QuantConnect/Lean · error · AssertionError

Expiry warning with time {delisting.time} but is expected to

Error message

Expiry warning with time {delisting.time} but is expected to be {self.expected_expiry_warning_time}

What it means

Delisting-timing assertion for a future/FOP expiry regression. When a DelistingType.WARNING event arrives, the test requires delisting.time to equal the hardcoded expected_expiry_warning_time (datetime(2020, 6, 19)). Any mismatch aborts, validating the engine emits the warning on the contract's last trading day.

Source

Thrown at Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py:57

        es_option = Symbol.create_option(
            es,
            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)

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Print delisting.time and self.expected_expiry_warning_time to see the exact delta.
  2. Verify the data file's expiry metadata for the ES / ES-option contract.
  3. Update expected_expiry_warning_time if the engine's warning-day semantics changed on purpose.
  4. Check whether delisting.time now includes a time-of-day component the comparison should normalize.
Defensive patterns

Strategy: validation

Validate before calling

# Validate warning time against expectation before raising
if delisting.type == DelistingType.WARNING:
    if delisting.time != self.expected_expiry_warning_time:
        self.debug(f"Warning time {delisting.time} != expected {self.expected_expiry_warning_time}")

Type guard

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

Prevention

When it happens

Trigger: Engine emitting the delisting warning on a different date (e.g. the day before or after expiry); delisting.time carrying an unexpected time component; data file expiry metadata disagreeing with the hardcoded expectation.

Common situations: Changes to delisting-warning emission logic in Lean; timezone shifts so delisting.time resolves to an adjacent day; data refreshes with corrected expiry dates that no longer match 2020-06-19.

Related errors


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