{"record":{"id":"079c500f9f7a62d1","repo":"QuantConnect/Lean","slug":"expected-to-liquidate-future-order-event-symbol","errorCode":null,"errorMessage":"Expected to liquidate future {order_event.symbol} at {self.expected_liquidation_time} (+1 minute), instead liquidated at {self.time}","messagePattern":"Expected to liquidate future (.+?) at (.+?) \\(\\+1 minute\\), instead liquidated at (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py","lineNumber":92,"sourceCode":"            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\n        # * Future Option Exercise\n        # * We expect NO Underlying Future Liquidation because we already hold a Long future position so the FOP Put selling leaves us breakeven\n        self.liquidated += 1\n        if order_event.symbol.security_type == SecurityType.FUTURE_OPTION and self.expected_liquidation_time != self.time:\n            raise AssertionError(f\"Expected to liquidate option {order_event.symbol} at {self.expected_liquidation_time}, instead liquidated at {self.time}\")\n\n        if order_event.symbol.security_type == SecurityType.FUTURE and \\\n            (self.expected_liquidation_time - timedelta(minutes=1)) != self.time and \\\n            self.expected_liquidation_time != self.time:\n\n            raise AssertionError(f\"Expected to liquidate future {order_event.symbol} at {self.expected_liquidation_time} (+1 minute), instead liquidated at {self.time}\")\n\n    def on_end_of_algorithm(self):\n        if not self.invested:\n            raise AssertionError(\"Never invested in ES futures and FOPs\")\n\n        if self.delistings_received != 4:\n            raise AssertionError(f\"Expected 4 delisting events received, found: {self.delistings_received}\")\n\n        if self.liquidated != 2:\n            raise AssertionError(f\"Expected 3 liquidation events, found {self.liquidated}\")\n","sourceCodeStart":74,"sourceCodeEnd":103,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py#L74-L103","documentation":"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.","triggerScenarios":"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.","commonSituations":"Switching the contract resolution so the bar width exceeds 1 minute; engine changes to future liquidation ordering; data refreshes shifting the liquidation timestamp.","solutions":["Print self.time vs expected_liquidation_time to see the actual delta.","If running at coarser resolution, widen the tolerance or restore Resolution.MINUTE.","Verify the future data's expiry/liquidation timestamp.","Update expected_liquidation_time if the engine's liquidation bar intentionally shifted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Validate future liquidation within tolerance\nif order_event.symbol.security_type == SecurityType.FUTURE:\n    ok = self.time in (self.expected_liquidation_time, self.expected_liquidation_time - timedelta(minutes=1))\n    if not ok:\n        self.debug(f\"Future liquidation at {self.time} not within tolerance of {self.expected_liquidation_time}\")","typeGuard":"def future_liquidated_within_tolerance(algo_time, expected: datetime) -> bool:\n    return algo_time in (expected, expected - timedelta(minutes=1))","tryCatchPattern":null,"preventionTips":["Run at Resolution.MINUTE so the 1-minute tolerance applies cleanly.","Widen tolerance if using coarser resolution intentionally.","Log the actual delta when debugging.","Re-baseline after engine liquidation-ordering changes."],"tags":["quantconnect","futures","liquidation","expiry","resolution","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}