Esempio n. 1
0
    def test_remaining_quantity_updated_after_expired_order_event(self):
        self.limit_buy_strategy.logger().setLevel(1)
        self.limit_buy_strategy.logger().addHandler(self)

        self.clock.add_iterator(self.limit_buy_strategy)
        # check no orders are placed before time delay
        self.clock.backtest_til(self.start_timestamp)
        self.assertEqual(0, len(self.limit_buy_strategy.active_bids))

        # one order created after first tick
        self.clock.backtest_til(self.start_timestamp +
                                math.ceil(self.clock_tick_size /
                                          self.order_delay_time))
        self.assertEqual(1, len(self.limit_buy_strategy.active_bids))
        bid_order: LimitOrder = self.limit_buy_strategy.active_bids[0][1]
        self.assertEqual(1, bid_order.quantity)
        self.assertEqual(self.limit_buy_strategy._quantity_remaining, 1)

        # Simulate order cancel
        self.market.trigger_event(
            MarketEvent.OrderExpired,
            OrderExpiredEvent(self.market.current_timestamp,
                              bid_order.client_order_id))

        self.assertEqual(0, len(self.limit_buy_strategy.active_bids))
        self.assertEqual(self.limit_buy_strategy._quantity_remaining, 2)

        self.assertTrue(
            self._is_logged(
                'INFO',
                f"Updating status after order expire (id: {bid_order.client_order_id})"
            ))
Esempio n. 2
0
 def simulate_order_expired(market_info: MarketTradingPairTuple, order: Union[LimitOrder, MarketOrder]):
     market_info.market.trigger_event(
         MarketEvent.OrderExpired,
         OrderExpiredEvent(
             int(time.time() * 1e3),
             order.client_order_id if isinstance(order, LimitOrder) else order.order_id,
         )
     )