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 = UpbitTrader() trader.balance = 123456789 trader.asset = (23456, 500) trader.market_currency = "APPLE" trader.market = "APPLE" trader.worker = MagicMock() trader.get_trade_tick = MagicMock(return_value=[{"trade_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()
def test__call_callback_NOT_update_when_type_is_not_done(self): trader = UpbitTrader() 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)
def test__call_callback_update_balance_correctly_when_sell(self): trader = UpbitTrader() 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)
def test__execute_order_should_call_callback_with_error_at_asset_lack( self): dummy_task = { "request": { "id": "apple", "price": 50000, "amount": 0.01, "type": "sell" }, "callback": MagicMock(), } trader = UpbitTrader() trader._send_order = MagicMock() trader._create_success_result = MagicMock() trader._start_timer = MagicMock() trader.asset = (45000, 0.009) trader._execute_order(dummy_task) dummy_task["callback"].assert_called_once_with("error!") trader._send_order.assert_not_called() trader._create_success_result.assert_not_called() trader._start_timer.assert_not_called() self.assertEqual(len(trader.order_map), 0)