{"record":{"id":"ea67d398647cf129","repo":"QuantConnect/Lean","slug":"unexpected-order-event-symbol","errorCode":null,"errorMessage":"Unexpected order event symbol!","messagePattern":"Unexpected order event symbol!","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateSPXWeeklyIndexOptionsStrategyAlgorithm.cs","lineNumber":95,"sourceCode":"\n                if (contracts.Count > 1)\n                {\n                    var smallerStrike = contracts[0];\n                    var higherStrike = contracts[1];\n\n                    // if found, buy until it expires\n                    var optionStrategy = OptionStrategies.BearCallSpread(_spxOption, smallerStrike.Strike, higherStrike.Strike, smallerStrike.Expiry);\n                    Buy(optionStrategy, 1);\n                }\n            }\n        }\n\n        public override void OnOrderEvent(OrderEvent orderEvent)\n        {\n            Debug(orderEvent.ToString());\n            if (orderEvent.Symbol.ID.Symbol != \"SPXW\")\n            {\n                throw new RegressionTestException(\"Unexpected order event symbol!\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public virtual bool CanRunLocally { get; } = true;\n\n        /// <summary>\n        /// This is used by the regression test system to indicate which languages this algorithm is written in.\n        /// </summary>\n        public virtual List<Language> Languages { get; } = new() { Language.CSharp };\n\n        /// <summary>\n        /// Data Points count of all timeslices of algorithm\n        /// </summary>\n        public virtual long DataPoints => 26399;\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateSPXWeeklyIndexOptionsStrategyAlgorithm.cs#L77-L113","documentation":"Thrown in OnOrderEvent when orderEvent.Symbol.ID.Symbol is not 'SPXW'. The algorithm trades SPXW (SPX weekly) index options exclusively via a Bear Call Spread strategy. Any order event from a different symbol (e.g., SPX, the underlying, or a non-weekly SPX option) indicates the option strategy generated legs on unexpected contracts.","triggerScenarios":"The option filter returns non-SPXW contracts (standard SPX options), the BearCallSpread strategy resolves legs to the underlying, the option chain contains mixed SPX and SPXW contracts, or a symbol-creation change alters the ticker string.","commonSituations":"AddIndexOption filter not restrictive enough (missing IncludeWeeklys or strikes filter), option strategy leg resolution picks up non-weekly contracts, or data file changes introduce SPX contracts into the SPXW chain.","solutions":["Verify the AddIndexOption canonical symbol is 'SPXW' and the filter only returns weekly contracts.","Log orderEvent.Symbol in OnOrderEvent to identify which unexpected symbol triggered the assertion.","Check OptionStrategies.BearCallSpread leg resolution to confirm it only uses SPXW contracts from the chain.","Inspect the option chain data for contamination with non-SPXW symbols."],"exampleFix":"// before\npublic override void OnOrderEvent(OrderEvent orderEvent)\n{\n    if (orderEvent.Symbol.ID.Symbol != \"SPXW\")\n    {\n        throw new RegressionTestException(\"Unexpected order event symbol!\");\n    }\n}\n\n// after — diagnose the offending symbol\npublic override void OnOrderEvent(OrderEvent orderEvent)\n{\n    if (orderEvent.Symbol.ID.Symbol != \"SPXW\")\n    {\n        throw new RegressionTestException(\n            $\"Unexpected order event symbol: {orderEvent.Symbol.ID.Symbol} (full: {orderEvent.Symbol})\");\n    }\n}","handlingStrategy":"validation","validationCode":"// Validate symbol before asserting\nif (orderEvent.Symbol.ID.Symbol != \"SPXW\")\n{\n    Log($\"Unexpected symbol in order event: {orderEvent.Symbol} (canonical: {orderEvent.Symbol.ID.Symbol})\");\n}","typeGuard":"bool IsExpectedSymbol(OrderEvent ev) => ev.Symbol.ID.Symbol == \"SPXW\";","tryCatchPattern":null,"preventionTips":["Verify AddIndexOption canonical symbol is 'SPXW' and filter returns only weekly contracts.","Check OptionStrategies.BearCallSpread leg resolution uses only SPXW symbols.","Log every order event symbol to detect contamination early.","Ensure the option chain data does not mix SPX and SPXW contracts."],"tags":["quantconnect","options","spx-weekly","option-strategy","symbol-validation","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}