{"record":{"id":"4cc9a7736af13da0","repo":"QuantConnect/Lean","slug":"liquidatestrategy-method-is-not-implemented","errorCode":null,"errorMessage":"LiquidateStrategy method is not implemented","messagePattern":"LiquidateStrategy method is not implemented","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/OptionStrategyFactoryMethodsBaseAlgorithm.py","lineNumber":75,"sourceCode":"        if self.portfolio.invested:\n            raise AssertionError(\"Expected no holdings at end of algorithm\")\n\n        orders_count = len(list(self.transactions.get_orders(lambda order: order.status == OrderStatus.FILLED)))\n        if orders_count != self.expected_orders_count():\n            raise AssertionError(f\"Expected {self.expected_orders_count()} orders to have been submitted and filled, \"\n                            f\"half for buying the strategy and the other half for the liquidation. Actual {orders_count}\")\n\n    def expected_orders_count(self) -> int:\n        raise NotImplementedError(\"ExpectedOrdersCount method is not implemented\")\n\n    def trade_strategy(self, chain: OptionChain, option_symbol: Symbol) -> None:\n        raise NotImplementedError(\"TradeStrategy method is not implemented\")\n\n    def assert_strategy_position_group(self, position_group: IPositionGroup, option_symbol: Symbol) -> None:\n        raise NotImplementedError(\"AssertStrategyPositionGroup method is not implemented\")\n\n    def liquidate_strategy(self) -> None:\n        raise NotImplementedError(\"LiquidateStrategy method is not implemented\")\n","sourceCodeStart":57,"sourceCodeEnd":76,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/OptionStrategyFactoryMethodsBaseAlgorithm.py#L57-L76","documentation":"liquidate_strategy is the abstract close method on OptionStrategyFactoryMethodsBaseAlgorithm. on_data calls it after verification so the subclass can close the combo it opened (e.g. via self.liquidate() or an opposing strategy order). The base raises NotImplementedError because the liquidation mechanism depends on the concrete strategy. Hitting it means the algorithm cannot close its position.","triggerScenarios":"on_data, after verifying the invested group, calls self.liquidate_strategy() on an instance whose class did not override the method.","commonSituations":"Running the base class; a new subclass missing the override; renaming the method in the base without updating subclasses.","solutions":["Implement liquidate_strategy in the subclass to close every leg (e.g. self.liquidate() or self.sell(strategy, quantity)).","Run a concrete subclass.","Use @abstractmethod to catch the omission at instantiation."],"exampleFix":"# before: base raises NotImplementedError\n# after\ndef liquidate_strategy(self):\n    self.liquidate()","handlingStrategy":"validation","validationCode":"if self.liquidate_strategy.__func__ is OptionStrategyFactoryMethodsBaseAlgorithm.liquidate_strategy:\n    raise NotImplementedError('Subclass must override liquidate_strategy()')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use @abstractmethod for liquidate_strategy so omissions fail early.","Implement the close in every subclass.","Run concrete subclasses, not the base."],"tags":["options","template-method","not-implemented","quantconnect","option-strategy","inheritance","liquidation"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}