{"record":{"id":"587daeceaa9d9f68","repo":"QuantConnect/Lean","slug":"time-unexpected-order-event-symbol-ordereven","errorCode":null,"errorMessage":"{Time} - Unexpected order event symbol: {orderEvent.Symbol}. Expected {_contractToTrade}","messagePattern":"(.+?) - Unexpected order event symbol: (.+?)\\. Expected (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs","lineNumber":118,"sourceCode":"            if (_contractToTrade != null && slice.Delistings.TryGetValue(_contractToTrade, out var delisting))\n            {\n                if (delisting.Type == DelistingType.Delisted)\n                {\n                    _delisted = true;\n\n                    if (Portfolio.Invested)\n                    {\n                        throw new RegressionTestException($\"{Time} - Portfolio should not be invested after the traded contract is delisted.\");\n                    }\n                }\n            }\n        }\n\n        public override void OnOrderEvent(OrderEvent orderEvent)\n        {\n            if (orderEvent.Symbol != _contractToTrade)\n            {\n                throw new RegressionTestException($\"{Time} - Unexpected order event symbol: {orderEvent.Symbol}. Expected {_contractToTrade}\");\n            }\n\n            if (orderEvent.Direction == OrderDirection.Buy)\n            {\n                if (orderEvent.Status == OrderStatus.Filled)\n                {\n                    if (_boughtQuantity != 0 && _liquidatedQuantity != 0)\n                    {\n                        throw new RegressionTestException($\"{Time} - Unexpected buy order event status: {orderEvent.Status}\");\n                    }\n                    _boughtQuantity = orderEvent.Quantity;\n                }\n            }\n            else if (orderEvent.Direction == OrderDirection.Sell)\n            {\n                if (orderEvent.Status == OrderStatus.Filled)\n                {\n                    if (_boughtQuantity <= 0 && _liquidatedQuantity != 0)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs#L100-L136","documentation":"OnOrderEvent asserts every order event belongs to the single contract the algorithm intends to trade (_contractToTrade). If orderEvent.Symbol differs, an order was placed/filled for a symbol the algorithm did not explicitly trade — a stray order, a mapping-related ghost fill, or a fill for the new mapped contract instead of the held one.","triggerScenarios":"An OrderEvent arrives whose .Symbol != _contractToTrade. This happens when the continuous-contract remap routes a fill to the new mapped contract, or when an internal/liquidation order fires on a different symbol than _contractToTrade.","commonSituations":"Continuous contract rollover causes fills to appear under the new symbol; delisting liquidation emits events for a symbol object that is a different instance than _contractToTrade; engine ordering places the buy before _contractToTrade is set.","solutions":["Ensure _contractToTrade is assigned (line 90, from _mappedSymbol) before any order events can fire.","Compare symbols by value/ID, and if multiple contract instances are expected, broaden the filter rather than strict equality.","Confirm no extra AddFuture/MarketOrder calls are placing orders on unintended contracts.","If rollover fills legitimately arrive for the new mapped symbol, handle them in a separate branch instead of rejecting."],"exampleFix":"// before\nif (orderEvent.Symbol != _contractToTrade) { throw ...; }\n\n// after: allow the new mapped contract's liquidation events too\nif (orderEvent.Symbol != _contractToTrade && orderEvent.Symbol != _mappedSymbol)\n{\n    throw new RegressionTestException($\"{Time} - Unexpected order event symbol: {orderEvent.Symbol}.\");\n}","handlingStrategy":"validation","validationCode":"public override void OnOrderEvent(OrderEvent orderEvent)\n{\n    var allowed = new[] { _contractToTrade, _mappedSymbol };\n    if (!allowed.Contains(orderEvent.Symbol))\n    {\n        Log($\"{Time} - Ignoring order event for {orderEvent.Symbol}\");\n        return;\n    }\n}","typeGuard":"bool IsExpectedOrderSymbol(Symbol s) => s == _contractToTrade || s == _mappedSymbol;","tryCatchPattern":null,"preventionTips":["Ensure _contractToTrade is assigned before orders can fill.","Allow liquidation events for the new mapped symbol after rollover.","Avoid placing orders on unintended contracts."],"tags":["futures","order-event","regression-test","eurex","order-management"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}