QuantConnect/Lean · error · AssertionError

Expected to liquidate future {order_event.symbol} at {self.e

Error message

Expected to liquidate future {order_event.symbol} at {self.expected_liquidation_time} (+1 minute), instead liquidated at {self.time}

What it means

Liquidation-timing assertion for the FUTURE (underlying ES) sell/fill event. The test accepts self.time equal to either expected_liquidation_time or expected_liquidation_time - 1 minute; any other time aborts. This tolerates the future liquidating one bar before the option exercise.

Source

Thrown at Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py:92

            self.market_order(self.es_future, 1)
            self.market_order(self.es_future_option, 1)

    def on_order_event(self, order_event: OrderEvent):
        if order_event.direction != OrderDirection.SELL or order_event.status != OrderStatus.FILLED:
            return

        # * Future Liquidation
        # * Future Option Exercise
        # * We expect NO Underlying Future Liquidation because we already hold a Long future position so the FOP Put selling leaves us breakeven
        self.liquidated += 1
        if order_event.symbol.security_type == SecurityType.FUTURE_OPTION and self.expected_liquidation_time != self.time:
            raise AssertionError(f"Expected to liquidate option {order_event.symbol} at {self.expected_liquidation_time}, instead liquidated at {self.time}")

        if order_event.symbol.security_type == SecurityType.FUTURE and \
            (self.expected_liquidation_time - timedelta(minutes=1)) != self.time and \
            self.expected_liquidation_time != self.time:

            raise AssertionError(f"Expected to liquidate future {order_event.symbol} at {self.expected_liquidation_time} (+1 minute), instead liquidated at {self.time}")

    def on_end_of_algorithm(self):
        if not self.invested:
            raise AssertionError("Never invested in ES futures and FOPs")

        if self.delistings_received != 4:
            raise AssertionError(f"Expected 4 delisting events received, found: {self.delistings_received}")

        if self.liquidated != 2:
            raise AssertionError(f"Expected 3 liquidation events, found {self.liquidated}")

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Print self.time vs expected_liquidation_time to see the actual delta.
  2. If running at coarser resolution, widen the tolerance or restore Resolution.MINUTE.
  3. Verify the future data's expiry/liquidation timestamp.
  4. Update expected_liquidation_time if the engine's liquidation bar intentionally shifted.
Defensive patterns

Strategy: validation

Validate before calling

# Validate future liquidation within tolerance
if order_event.symbol.security_type == SecurityType.FUTURE:
    ok = self.time in (self.expected_liquidation_time, self.expected_liquidation_time - timedelta(minutes=1))
    if not ok:
        self.debug(f"Future liquidation at {self.time} not within tolerance of {self.expected_liquidation_time}")

Type guard

def future_liquidated_within_tolerance(algo_time, expected: datetime) -> bool:
    return algo_time in (expected, expected - timedelta(minutes=1))

Prevention

When it happens

Trigger: Future auto-liquidation happening more than 1 minute from the expected time; timezone skew; data changes altering the liquidation bar; resolution changes widening the bar beyond the 1-minute tolerance.

Common situations: Switching the contract resolution so the bar width exceeds 1 minute; engine changes to future liquidation ordering; data refreshes shifting the liquidation timestamp.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/079c500f9f7a62d1. Report an issue: GitHub.