Beispiel #1
0
    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()
Beispiel #2
0
    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()
Beispiel #3
0
    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")