{"record":{"id":"e99f8af36e05dda4","repo":"QuantConnect/Lean","slug":"option-was-not-sold","errorCode":null,"errorMessage":"Option was not sold","messagePattern":"Option was not sold","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs","lineNumber":157,"sourceCode":"\n                _optionDelistedWarningReceived = true;\n            }\n            else\n            {\n                if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived || _optionDelisted)\n                {\n                    throw new RegressionTestException($\"Unexpected delisting event: {delisting}\");\n                }\n\n                _optionDelisted = true;\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (!_optionSold)\n            {\n                throw new RegressionTestException(\"Option was not sold\");\n            }\n\n            if (!_optionAssigned)\n            {\n                throw new RegressionTestException(\"Option was not assigned\");\n            }\n\n            if (!_stockAssigned)\n            {\n                throw new RegressionTestException(\"Stock was not assigned\");\n            }\n\n            if (!_optionDelistedWarningReceived)\n            {\n                throw new RegressionTestException(\"Option delisting warning was not received\");\n            }\n\n            if (!_optionDelisted)","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs#L139-L175","documentation":"In OnEndOfAlgorithm this asserts _optionSold is true: the regression algorithm sold (shorted) the option during its run. If false, the sell order never executed or OnOrderEvent never set the flag. The algorithm depends on this sale to then be assigned and receive stock.","triggerScenarios":"The initial option sell order was not filled (insufficient buying power, market closed, no option data), or OnOrderEvent failed to match the fill event that sets _optionSold.","commonSituations":"Data gaps for the option contract (no quotes/trades), brokerage model rejecting the short sale, fill slippage/time changes, or transaction-handler changes that drop the fill event.","solutions":["Check the algorithm logs for the option order submission and fill events.","Verify the option data file exists and has bars for the start date; confirm the FillModel produced a fill.","Trace OnOrderEvent to ensure the OrderEvent.Status == Filled path sets _optionSold."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before relying on the sale, validate the order was placed and is filling\nvar ticket = Transactions.GetOrderTickets(_option).LastOrDefault();\nif (ticket == null || ticket.Status != OrderStatus.Filled)\n{\n    // surface why the sell did not complete\n    Log($\"Option sell not filled: {ticket}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log the order ticket status of the initial sell so OnEndOfAlgorithm failures are diagnosable.","Verify option data availability for the start date before relying on a fill.","Confirm the brokerage model allows the short option sale."],"tags":["quantconnect","lean","regression-test","options","order-fill","postcondition"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}