Exemple #1
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()
Exemple #2
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")
Exemple #3
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()
Exemple #4
0
    def test__create_success_result_return_correct_result(self):
        dummy_request = {
            "id": "mango",
            "type": "banana",
            "price": 500,
            "amount": 0.12345
        }
        success_result = BithumbTrader._create_success_result(dummy_request)

        self.assertEqual(success_result["request"]["id"], dummy_request["id"])
        self.assertEqual(success_result["type"], dummy_request["type"])
        self.assertEqual(success_result["price"], dummy_request["price"])
        self.assertEqual(success_result["amount"], dummy_request["amount"])
        self.assertEqual(success_result["msg"], "success")