コード例 #1
0
    def test_set_more_than_max_count_orders(self):
        test_inst = ExchangePersonalData()
        test_inst.orders = {}
        test_inst._MAX_ORDERS_COUNT = 500
        nb_max_stored_orders = test_inst._MAX_ORDERS_COUNT

        max_timestamp = 0
        for i in range(nb_max_stored_orders):
            time_stamp = time.time()
            test_inst.upsert_order(
                i, {
                    "id": i,
                    "timestamp": time_stamp,
                    "status": OrderStatus.CLOSED.value
                })
            if i == nb_max_stored_orders / 2:
                max_timestamp = time_stamp
            time.sleep(0.000000001)

        assert len(test_inst.orders) == nb_max_stored_orders
        test_inst.upsert_order(
            nb_max_stored_orders + 1, {
                "id": nb_max_stored_orders + 1,
                "timestamp": time.time(),
                "status": OrderStatus.CLOSED.value
            })

        assert not [
            order for order in test_inst.orders.values()
            if order["timestamp"] < max_timestamp
        ]

        assert len(test_inst.orders) == nb_max_stored_orders / 2 + 1
コード例 #2
0
    def test_upsert_order(self):
        test_inst = ExchangePersonalData()

        # without orders
        test_inst.orders = {}
        assert not test_inst.has_order(10)
        test_inst.upsert_order(10, None)
        assert test_inst.has_order(10)
コード例 #3
0
    def test_select_orders(self):
        test_inst = ExchangePersonalData()

        symbol_1 = "BTC/USDT"
        symbol_2 = "ETH/BTC"
        symbol_3 = "ETH/USDT"

        # without orders
        test_inst.orders = {}
        assert test_inst.get_all_orders(symbol_1, None, None) == []
        assert test_inst.get_open_orders(symbol_2, None, None) == []
        assert test_inst.get_closed_orders(symbol_3, None, None) == []

        order_1 = self.create_fake_order(10, OrderStatus.CLOSED.value,
                                         symbol_1, 0)
        test_inst.upsert_order(10, order_1)
        assert test_inst.get_all_orders(symbol_1, None, None) == [order_1]
        assert test_inst.get_open_orders(symbol_1, None, None) == []
        assert test_inst.get_closed_orders(symbol_1, None, None) == [order_1]

        order_2 = self.create_fake_order(100, OrderStatus.OPEN.value, symbol_3,
                                         0)
        test_inst.upsert_order(100, order_2)
        assert test_inst.get_all_orders(symbol_3, None, None) == [order_2]
        assert test_inst.get_open_orders(symbol_3, None, None) == [order_2]
        assert test_inst.get_closed_orders(symbol_3, None, None) == []
        assert test_inst.get_all_orders(symbol_2, None, None) == []
        assert test_inst.get_open_orders(symbol_2, None, None) == []
        assert test_inst.get_closed_orders(symbol_2, None, None) == []
        assert test_inst.get_all_orders(None, None, None) == [order_1, order_2]
        assert test_inst.get_open_orders(None, None, None) == [order_2]
        assert test_inst.get_closed_orders(None, None, None) == [order_1]

        order_3 = self.create_fake_order(10, OrderStatus.OPEN.value, symbol_2,
                                         0)
        test_inst.upsert_order(10, order_3)
        assert test_inst.get_all_orders(symbol_2, None, None) == [order_3]
        assert test_inst.get_open_orders(symbol_2, None, None) == [order_3]
        assert test_inst.get_closed_orders(symbol_2, None, None) == []
        assert test_inst.get_all_orders(None, None, None) == [order_3, order_2]
        assert test_inst.get_open_orders(None, None,
                                         None) == [order_3, order_2]
        assert test_inst.get_closed_orders(None, None, None) == []
        assert test_inst.get_all_orders(symbol_1, None, None) == []
        assert test_inst.get_open_orders(symbol_1, None, None) == []
        assert test_inst.get_closed_orders(symbol_1, None, None) == []
        assert test_inst.get_all_orders(symbol_3, None, None) == [order_2]
        assert test_inst.get_open_orders(symbol_3, None, None) == [order_2]
        assert test_inst.get_closed_orders(symbol_3, None, None) == []

        order_4 = self.create_fake_order(11, OrderStatus.OPEN.value, symbol_1,
                                         100)
        order_5 = self.create_fake_order(12, OrderStatus.CLOSED.value,
                                         symbol_2, 1000)
        order_6 = self.create_fake_order(13, OrderStatus.CLOSED.value,
                                         symbol_3, 50)
        test_inst.upsert_orders([order_4, order_5, order_6])
        assert test_inst.get_all_orders(symbol_1, None, None) == [order_4]
        assert test_inst.get_open_orders(symbol_1, None, None) == [order_4]
        assert test_inst.get_closed_orders(symbol_1, None, None) == []
        assert test_inst.get_all_orders(symbol_2, None,
                                        None) == [order_3, order_5]
        assert test_inst.get_open_orders(symbol_2, None, None) == [order_3]
        assert test_inst.get_closed_orders(symbol_2, None, None) == [order_5]
        assert test_inst.get_all_orders(symbol_3, None,
                                        None) == [order_2, order_6]
        assert test_inst.get_open_orders(symbol_3, None, None) == [order_2]
        assert test_inst.get_closed_orders(symbol_3, None, None) == [order_6]
        assert test_inst.get_all_orders(
            None, None, None) == [order_3, order_2, order_4, order_5, order_6]
        assert test_inst.get_open_orders(None, None,
                                         None) == [order_3, order_2, order_4]
        assert test_inst.get_closed_orders(None, None,
                                           None) == [order_5, order_6]

        # test limit
        assert test_inst.get_all_orders(None, None,
                                        3) == [order_3, order_2, order_4]
        assert test_inst.get_open_orders(None, None,
                                         3) == [order_3, order_2, order_4]
        assert test_inst.get_closed_orders(None, None, 3) == [order_5, order_6]

        # test timestamps
        assert test_inst.get_all_orders(None, 30, 3) == [order_3, order_2]
        assert test_inst.get_open_orders(None, 1000,
                                         None) == [order_3, order_2, order_4]
        assert test_inst.get_closed_orders(None, 60, 1) == [order_6]