QuantConnect/Lean · error · AssertionError

Delisting warning received at an unexpected date: {self.time

Error message

Delisting warning received at an unexpected date: {self.time} - expected {delisting.time}

What it means

Companion warning-date check: when a DelistingType.WARNING fires, delisting.time must equal a datetime built from the algorithm's current self.time (year/month/day). It cross-validates the warning was emitted on the same calendar day the algorithm is processing.

Source

Thrown at Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py:60

            Market.CME,
            OptionStyle.AMERICAN,
            OptionRight.PUT,
            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:

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Compare the tz of delisting.time and self.time and normalize before comparing.
  2. Confirm the warning is emitted during the bar whose date matches the contract expiry.
  3. If the engine now emits warnings one bar earlier/later, update the assertion's date construction.
  4. Print both values raw to identify the exact day mismatch.
Defensive patterns

Strategy: validation

Validate before calling

# Cross-check warning day against algorithm day
if delisting.type == DelistingType.WARNING:
    same_day = delisting.time.date() == self.time.date()
    if not same_day:
        self.debug(f"Warning day {delisting.time.date()} != algo day {self.time.date()}")

Type guard

def warning_on_current_day(delisting, algo_time: datetime) -> bool:
    return delisting.type == DelistingType.WARNING and delisting.time.date() == algo_time.date()

Prevention

When it happens

Trigger: delisting.time and self.time disagree on the calendar day (one is UTC, one is exchange-local); a backtest fill-forward causing the warning to surface a day late; engine time-zone handling changes.

Common situations: Timezone skew between delisting.time (often UTC) and self.time (exchange tz); data-driven warning arriving outside the expected bar; date-boundary logic regressions.

Related errors


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