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_cancel_request_should_call__call_callback_when_order_is_traded_already( self): trader = BithumbTrader() trader._call_callback = MagicMock() dummy_request = { "order_id": "mango_id", "callback": MagicMock(), "result": { "state": "requested", "request": { "id": "mango_request_1234", "type": "buy", "price": "888000", "amount": "0.0001234", }, "type": "buy", "price": 888000.0, "amount": 0.0001234, "msg": "success", }, } trader.order_map["mango_request_1234"] = dummy_request _cancel_order = MagicMock(return_value=None) trader._query_order = MagicMock( return_value={ "data": { "order_status": "Completed", "order_id": "mango_id", "state": "done", "transaction_date": "1572497603668315", "order_price": 888000, "order_qty": 0.007, }, }) trader.cancel_request("mango_request_1234") trader._query_order.assert_called_once_with("mango_id") self.assertEqual(trader._call_callback.call_args_list[0][0][0], dummy_request["callback"]) mango_result = trader._call_callback.call_args_list[0][0][1] self.assertEqual(mango_result["date_time"], "2019-10-31T13:53:23") self.assertEqual(mango_result["price"], 888000) self.assertEqual(mango_result["type"], "buy") self.assertEqual(mango_result["state"], "done") self.assertEqual(mango_result["amount"], 0.007)
def test_cancel_all_requests_should_call_cancel_request_correctly(self): trader = BithumbTrader() dummy_request = "mango_request" trader.order_map["mango_request_1234"] = dummy_request trader.order_map["mango_request_5678"] = dummy_request trader.cancel_request = MagicMock() trader.cancel_all_requests() trader.cancel_request.assert_called() self.assertEqual(trader.cancel_request.call_args_list[0][0][0], "mango_request_1234") self.assertEqual(trader.cancel_request.call_args_list[1][0][0], "mango_request_5678")