def test_set_orders(self): test_inst = ExchangePersonalData() # without orders test_inst.orders = {} assert not test_inst.has_order(10) assert not test_inst.has_order(20) test_inst.upsert_orders([{ "id": 15 }, { "id": 10 }, { "id": 20 }, { "id": 15 }]) assert test_inst.get_order(15) assert test_inst.has_order(15) assert test_inst.has_order(20) assert test_inst.has_order(10) assert not test_inst.has_order(12) assert not test_inst.has_order(30)
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]