{"record":{"id":"9780493e24b1fa8e","repo":"QuantConnect/Lean","slug":"time-unexpected-symbol-changed-event-new-symbo","errorCode":null,"errorMessage":"{Time} - Unexpected symbol changed event new symbol: {changedEvent}","messagePattern":"(.+?) - Unexpected symbol changed event new symbol: (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs","lineNumber":85,"sourceCode":"        {\n            foreach (var changedEvent in slice.SymbolChangedEvents.Values)\n            {\n                if (++_mappingsCount > 1)\n                {\n                    throw new RegressionTestException($\"{Time} - Unexpected number of symbol changed events (mappings): {_mappingsCount}. \" +\n                        $\"Expected only 1.\");\n                }\n\n                Debug($\"{Time} - SymbolChanged event: {changedEvent}\");\n\n                if (changedEvent.OldSymbol != _mappedSymbol.ID.ToString())\n                {\n                    throw new RegressionTestException($\"{Time} - Unexpected symbol changed event old symbol: {changedEvent}\");\n                }\n\n                if (changedEvent.NewSymbol != _continuousContract.Mapped.ID.ToString())\n                {\n                    throw new RegressionTestException($\"{Time} - Unexpected symbol changed event new symbol: {changedEvent}\");\n                }\n\n                // Let's trade the previous mapped contract, so we can hold it until expiration for testing\n                // (will be sooner than the new mapped contract)\n                _contractToTrade = _mappedSymbol;\n                _mappedSymbol = _continuousContract.Mapped;\n            }\n\n            // Let's trade after the mapping is done\n            if (_contractToTrade != null && _boughtQuantity == 0 && Securities[_contractToTrade].Exchange.ExchangeOpen)\n            {\n                Buy(_contractToTrade, 1);\n            }\n\n            if (_contractToTrade != null && slice.Delistings.TryGetValue(_contractToTrade, out var delisting))\n            {\n                if (delisting.Type == DelistingType.Delisted)\n                {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs#L67-L103","documentation":"The companion assertion to the old-symbol check: after a continuous-future rollover, the SymbolChangedEvent.NewSymbol must equal the contract that Lean now reports as _continuousContract.Mapped. A mismatch means the event's reported destination contract differs from the engine's current mapped contract, signalling a divergence between the event stream and the continuous-contract security state.","triggerScenarios":"A SymbolChangedEvent fires and changedEvent.NewSymbol != _continuousContract.Mapped.ID.ToString(). The destination contract in the event does not match the live continuous-contract Mapped symbol at the moment the event is processed.","commonSituations":"Engine version change alters how/when Mapped is updated relative to event emission; multiple mapping events queued in one slice; data change shifts the destination contract; contractDepthOffset adjusted so a different expiry becomes the new mapped contract.","solutions":["Validate the continuous-contract configuration (mapping mode, depth offset, normalization) against the expected data set.","Check that only one mapping event occurs in the backtest (the _mappingsCount > 1 guard at line 70 has not tripped).","Confirm EUREX futures data completeness; a missing destination contract makes NewSymbol fall back unexpectedly.","Re-read _continuousContract.Mapped at event time rather than caching, to compare against current engine state."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"foreach (var changedEvent in slice.SymbolChangedEvents.Values)\n{\n    var currentMapped = _continuousContract.Mapped.ID.ToString();\n    if (changedEvent.NewSymbol != currentMapped)\n    {\n        Log($\"{Time} - Mapping dest mismatch: event={changedEvent.NewSymbol} mapped={currentMapped}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-read _continuousContract.Mapped at event-processing time rather than caching.","Ensure only one mapping event occurs (guard _mappingsCount).","Pin Lean version and EUREX data for deterministic destination contracts."],"tags":["futures","continuous-contract","symbol-mapping","regression-test","eurex","rollover"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}