def test__send_limit_order_should_call_bithumb_api_call_with_correct_query( self): trader = BithumbTrader("BTC") expected_query = { "order_currency": trader.market, "payment_currency": trader.market_currency, "type": "bid", "units": "0.0051", "price": "500", } trader.bithumb_api_call = MagicMock() trader._send_limit_order(True, 500, 0.00512) trader.bithumb_api_call.assert_called_once_with( "/trade/place", expected_query)
def test__execute_order_call_callback_with_error_when_try_to_buy_over_balance( self): dummy_task = { "request": { "id": "apple", "price": 50000000, "amount": 0.01, "type": "buy" }, "callback": MagicMock(), } trader = BithumbTrader() trader._send_limit_order = MagicMock(return_value={ "status": "0000", "order_id": "apple_order_id" }) trader._create_success_result = MagicMock(return_value="banana") trader._start_timer = MagicMock() trader.cancel_request = MagicMock() trader._execute_order(dummy_task) dummy_task["callback"].assert_called_once_with("error!") trader._send_limit_order.assert_not_called() trader._create_success_result.assert_not_called() trader._start_timer.assert_not_called()
def test__execute_order_ignore_when_price_is_zero(self): dummy_task = { "request": { "id": "apple", "price": 0, "amount": 0.0001, "type": "sell" }, "callback": MagicMock(), } trader = BithumbTrader() trader._send_limit_order = MagicMock(return_value={ "status": "0000", "order_id": "apple_order_id" }) trader._create_success_result = MagicMock(return_value="banana") trader._start_timer = MagicMock() trader.cancel_request = MagicMock() trader._execute_order(dummy_task) dummy_task["callback"].assert_not_called() trader._send_limit_order.assert_not_called() trader._create_success_result.assert_not_called() trader._start_timer.assert_not_called()
def test__execute_order_call__send_limit_order_correctly(self): dummy_task = { "request": { "id": "apple", "price": 500, "amount": 0.0001, "type": "buy" }, "callback": MagicMock(), } trader = BithumbTrader() trader._send_limit_order = MagicMock(return_value={ "status": "0000", "order_id": "apple_order_id" }) trader._create_success_result = MagicMock(return_value="banana") trader._start_timer = MagicMock() trader._execute_order(dummy_task) trader._send_limit_order.assert_called_once_with(True, 500, 0.0001) trader._create_success_result.assert_called_once_with( dummy_task["request"]) trader._start_timer.assert_called_once() self.assertEqual(trader.order_map["apple"]["order_id"], "apple_order_id") self.assertEqual(trader.order_map["apple"]["callback"], dummy_task["callback"]) self.assertEqual(trader.order_map["apple"]["result"], "banana") dummy_task["callback"].assert_called_once_with("banana")