def simulate_cancel_order(order_tracker: OrderTracker, order: Union[LimitOrder, MarketOrder]): """ Simulates order being cancelled. """ order_id = order.client_order_id if isinstance(order, LimitOrder) else order.order_id if order_id: order_tracker.check_and_track_cancel(order_id)
def simulate_stop_tracking_order(order_tracker: OrderTracker, order: Union[LimitOrder, MarketOrder], market_info: MarketTradingPairTuple): """ Simulates an order being cancelled or filled completely. """ if isinstance(order, LimitOrder): order_tracker.stop_tracking_limit_order(market_pair=market_info, order_id=order.client_order_id, ) else: order_tracker.stop_tracking_market_order(market_pair=market_info, order_id=order.order_id )
def simulate_place_order(order_tracker: OrderTracker, order: Union[LimitOrder, MarketOrder], market_info: MarketTradingPairTuple): """ Simulates an order being succesfully placed. """ if isinstance(order, LimitOrder): order_tracker.add_create_order_pending(order.client_order_id) order_tracker.start_tracking_limit_order(market_pair=market_info, order_id=order.client_order_id, is_buy=order.is_buy, price=order.price, quantity=order.quantity ) else: order_tracker.add_create_order_pending(order.order_id) order_tracker.start_tracking_market_order(market_pair=market_info, order_id=order.order_id, is_buy=order.is_buy, quantity=order.amount )
def simulate_order_created(order_tracker: OrderTracker, order: Union[LimitOrder, MarketOrder]): order_id = order.client_order_id if isinstance(order, LimitOrder) else order.order_id order_tracker.remove_create_order_pending(order_id)
def setUp(self): self.order_tracker: OrderTracker = OrderTracker() self.clock: Clock = Clock(ClockMode.BACKTEST, self.clock_tick_size, self.start_timestamp, self.end_timestamp) self.clock.add_iterator(self.order_tracker) self.clock.backtest_til(self.start_timestamp)