{"record":{"id":"efaad27c7c92a1a4","repo":"QuantConnect/Lean","slug":"delisting-occurred-at-unexpected-time-delisting","errorCode":null,"errorMessage":"Delisting occurred at unexpected time: {delisting.time} - expected: {self.expected_expiry_delisting_time}","messagePattern":"Delisting occurred at unexpected time: (.+?) - expected: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py","lineNumber":63,"sourceCode":"            3400.0,\n            datetime(2020, 6, 19)\n        )\n\n        self.es_future = self.add_future_contract(es, Resolution.MINUTE).symbol\n        self.es_future_option = self.add_future_option_contract(es_option, Resolution.MINUTE).symbol\n\n    def on_data(self, data: Slice):\n        for delisting in data.delistings.values():\n            self.delistings_received += 1\n\n            if delisting.type == DelistingType.WARNING and delisting.time != self.expected_expiry_warning_time:\n                raise AssertionError(f\"Expiry warning with time {delisting.time} but is expected to be {self.expected_expiry_warning_time}\")\n\n            if delisting.type == DelistingType.WARNING and delisting.time != datetime(self.time.year, self.time.month, self.time.day):\n                raise AssertionError(f\"Delisting warning received at an unexpected date: {self.time} - expected {delisting.time}\")\n\n            if delisting.type == DelistingType.DELISTED and delisting.time != self.expected_expiry_delisting_time:\n                raise AssertionError(f\"Delisting occurred at unexpected time: {delisting.time} - expected: {self.expected_expiry_delisting_time}\")\n\n            if delisting.type == DelistingType.DELISTED and delisting.time != datetime(self.time.year, self.time.month, self.time.day):\n                raise AssertionError(f\"Delisting notice received at an unexpected date: {self.time} - expected {delisting.time}\")\n\n        if not self.invested and \\\n            (self.es_future in data.bars or self.es_future in data.quote_bars) and \\\n            (self.es_future_option in data.bars or self.es_future_option in data.quote_bars):\n\n            self.invested = True\n\n            self.market_order(self.es_future, 1)\n            self.market_order(self.es_future_option, 1)\n\n    def on_order_event(self, order_event: OrderEvent):\n        if order_event.direction != OrderDirection.SELL or order_event.status != OrderStatus.FILLED:\n            return\n\n        # * Future Liquidation","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py#L45-L81","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Print delisting.time vs self.expected_expiry_delisting_time to see the delta.","Confirm the data's expiry metadata still maps to the 2020-06-19 / 2020-06-20 pair.","Update expected_expiry_delisting_time if the engine's delisting-day rule changed intentionally.","Strip time-of-day from the comparison if only the date is meaningful."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Validate delisted time against expectation\nif delisting.type == DelistingType.DELISTED:\n    if delisting.time != self.expected_expiry_delisting_time:\n        self.debug(f\"Delisted time {delisting.time} != expected {self.expected_expiry_delisting_time}\")","typeGuard":"def delisted_time_matches(delisting, expected: datetime) -> bool:\n    return delisting.type == DelistingType.DELISTED and delisting.time == expected","tryCatchPattern":null,"preventionTips":["Keep expected_expiry_delisting_time synced with the data's expiry + 1 day rule.","Strip time-of-day if only the date is meaningful.","Log raw values on mismatch.","Re-baseline after engine delisting-day rule changes."],"tags":["quantconnect","futures","future-options","delisting","expiry","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}