QuantConnect/Lean · error · AssertionError

Delisting occurred at unexpected time: {delisting.time} - ex

Error message

Delisting occurred at unexpected time: {delisting.time} - expected: {self.expected_expiry_delisting_time}

What it means

Asserts that a DelistingType.DELISTED event's time equals expected_expiry_delisting_time (datetime(2020, 6, 20)). It validates the engine performs the actual delisting on the day after expiry, as designed for futures.

Source

Thrown at Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py:63

            3400.0,
            datetime(2020, 6, 19)
        )

        self.es_future = self.add_future_contract(es, Resolution.MINUTE).symbol
        self.es_future_option = self.add_future_option_contract(es_option, Resolution.MINUTE).symbol

    def on_data(self, data: Slice):
        for delisting in data.delistings.values():
            self.delistings_received += 1

            if delisting.type == DelistingType.WARNING and delisting.time != self.expected_expiry_warning_time:
                raise AssertionError(f"Expiry warning with time {delisting.time} but is expected to be {self.expected_expiry_warning_time}")

            if delisting.type == DelistingType.WARNING and delisting.time != datetime(self.time.year, self.time.month, self.time.day):
                raise AssertionError(f"Delisting warning received at an unexpected date: {self.time} - expected {delisting.time}")

            if delisting.type == DelistingType.DELISTED and delisting.time != self.expected_expiry_delisting_time:
                raise AssertionError(f"Delisting occurred at unexpected time: {delisting.time} - expected: {self.expected_expiry_delisting_time}")

            if delisting.type == DelistingType.DELISTED and delisting.time != datetime(self.time.year, self.time.month, self.time.day):
                raise AssertionError(f"Delisting notice received at an unexpected date: {self.time} - expected {delisting.time}")

        if not self.invested and \
            (self.es_future in data.bars or self.es_future in data.quote_bars) and \
            (self.es_future_option in data.bars or self.es_future_option in data.quote_bars):

            self.invested = True

            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

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Print delisting.time vs self.expected_expiry_delisting_time to see the delta.
  2. Confirm the data's expiry metadata still maps to the 2020-06-19 / 2020-06-20 pair.
  3. Update expected_expiry_delisting_time if the engine's delisting-day rule changed intentionally.
  4. Strip time-of-day from the comparison if only the date is meaningful.
Defensive patterns

Strategy: validation

Validate before calling

# Validate delisted time against expectation
if delisting.type == DelistingType.DELISTED:
    if delisting.time != self.expected_expiry_delisting_time:
        self.debug(f"Delisted time {delisting.time} != expected {self.expected_expiry_delisting_time}")

Type guard

def delisted_time_matches(delisting, expected: datetime) -> bool:
    return delisting.type == DelistingType.DELISTED and delisting.time == expected

Prevention

When it happens

Trigger: Engine delisting the contract on the expiry day itself instead of the following day; delisting.time carrying a time-of-day component that breaks equality; data file metadata causing the delisting to fire on a different date.

Common situations: Changes to the delisting-vs-expiry-day offset in Lean; data refreshes with shifted expiry; timezone handling making delisting.time land on the previous/next day.

Related errors


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