Beispiel #1
0
    def test_get_account_info_should_return_correct_info(self):
        dummy_respone = [
            {
                "currency": "KRW",
                "balance": 123456789
            },
            {
                "currency": "APPLE",
                "balance": 500,
                "avg_buy_price": 23456
            },
        ]
        trader = BithumbTrader()
        trader.balance = 123456789
        trader.asset = (23456, 500)
        trader.market = "APPLE"
        trader.worker = MagicMock()
        trader.get_trade_tick = MagicMock(return_value={
            "status": "0000",
            "data": [{
                "price": 777
            }]
        })
        result = trader.get_account_info()

        self.assertEqual(result["balance"], 123456789)
        self.assertEqual(result["asset"], {"APPLE": (23456, 500)})
        self.assertEqual(result["quote"], {"APPLE": 777})
        self.assertEqual("date_time" in result, True)
        trader.get_trade_tick.assert_called_once_with()
Beispiel #2
0
    def test__call_callback_NOT_update_when_type_is_not_done(self):
        trader = BithumbTrader()
        trader.balance = 550000
        trader.asset = (67000000, 1.000001)
        dummy_result = {
            "request": {
                "id": "mango_request_5678",
                "type": "buy",
                "price": "888000",
                "amount": "0.0001234",
            },
            "type": "sell",
            "price": "62000000",
            "amount": "0.0012345",
            "msg": "success",
            "state": "requested",
        }
        dummy_callback = MagicMock()
        trader._call_callback(dummy_callback, dummy_result)

        self.assertEqual(trader.balance, 550000)
        self.assertEqual(trader.asset, (67000000, 1.000001))
        dummy_callback.assert_called_once_with(dummy_result)
Beispiel #3
0
    def test__call_callback_update_balance_correctly_when_sell(self):
        trader = BithumbTrader()
        trader.balance = 550000
        trader.asset = (67000000, 1.000001)
        dummy_result = {
            "request": {
                "id": "mango_request_5678",
                "type": "buy",
                "price": "888000",
                "amount": "0.0001234",
            },
            "type": "sell",
            "price": "62000000",
            "amount": "0.0012345",
            "msg": "success",
            "state": "done",
        }
        dummy_callback = MagicMock()
        trader._call_callback(dummy_callback, dummy_result)

        self.assertEqual(trader.balance, 626501)
        self.assertEqual(trader.asset, (67000000, 0.998766))
        dummy_callback.assert_called_once_with(dummy_result)