Пример #1
0
    def test__execute_order_handle_task_correctly(self):
        dummy_task = {
            "request": {
                "id": "apple",
                "price": 500,
                "amount": 0.0001,
                "type": "buy"
            },
            "callback": MagicMock(),
        }
        trader = UpbitTrader()
        trader._send_order = MagicMock(return_value={"uuid": "mango"})
        trader._create_success_result = MagicMock(return_value="banana")
        trader._start_timer = MagicMock()

        trader._execute_order(dummy_task)

        trader._send_order.assert_called_once_with(trader.market, 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"]["uuid"], "mango")
        self.assertEqual(trader.order_map["apple"]["callback"],
                         dummy_task["callback"])
        self.assertEqual(trader.order_map["apple"]["result"], "banana")
        dummy_task["callback"].assert_called_once()
Пример #2
0
    def test__execute_order_call_cancel_request_when_request_type_is_cancel(
            self):
        dummy_task = {
            "request": {
                "id": "apple",
                "price": 500,
                "amount": 0.0001,
                "type": "cancel"
            },
            "callback": "kiwi",
        }
        trader = UpbitTrader()
        trader.cancel_request = MagicMock()
        trader._send_order = MagicMock()
        trader._create_success_result = MagicMock()
        trader._start_timer = MagicMock()

        trader._execute_order(dummy_task)

        trader._send_order.assert_not_called()
        trader._create_success_result.assert_not_called()
        trader._start_timer.assert_not_called()
        trader.cancel_request.assert_called_once_with("apple")
Пример #3
0
    def test__execute_order_should_call_callback_with_error_at_balance_lack(
            self):
        dummy_task = {
            "request": {
                "id": "apple",
                "price": 50000,
                "amount": 0.01,
                "type": "buy"
            },
            "callback": MagicMock(),
        }
        trader = UpbitTrader()
        trader._send_order = MagicMock()
        trader._create_success_result = MagicMock()
        trader._start_timer = MagicMock()
        trader.balance = 450

        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)
Пример #4
0
    def test__execute_order_should_call_callback_with_error_when__send_order_return_None(
            self):
        dummy_task = {
            "request": {
                "id": "apple",
                "price": 500,
                "amount": 0.0001,
                "type": "buy"
            },
            "callback": MagicMock(),
        }
        trader = UpbitTrader()
        trader._send_order = MagicMock(return_value=None)
        trader._create_success_result = MagicMock(return_value="banana")
        trader._start_timer = MagicMock()

        trader._execute_order(dummy_task)

        dummy_task["callback"].assert_called_once_with("error!")
        trader._send_order.assert_called_once_with(trader.market, True, 500,
                                                   0.0001)
        trader._create_success_result.assert_not_called()
        trader._start_timer.assert_not_called()
        self.assertEqual(len(trader.order_map), 0)