{"record":{"id":"7e702d51b0e1ecaf","repo":"QuantConnect/Lean","slug":"received-order-event-for-unknown-symbol-order-ev","errorCode":null,"errorMessage":"Received order event for unknown Symbol: {order_event.symbol}","messagePattern":"Received order event for unknown Symbol: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FutureOptionShortPutOTMExpiryRegressionAlgorithm.py","lineNumber":88,"sourceCode":"                    raise AssertionError(f\"Delisting happened at unexpected date: {delisting.time}\")\n\n    def on_order_event(self, order_event: OrderEvent):\n        if order_event.status != OrderStatus.FILLED:\n            # There's lots of noise with OnOrderEvent, but we're only interested in fills.\n            return\n\n        if not self.securities.contains_key(order_event.symbol):\n            raise AssertionError(f\"Order event Symbol not found in Securities collection: {order_event.symbol}\")\n\n        security = self.securities[order_event.symbol]\n        if security.symbol == self.es19m20:\n            raise AssertionError(f\"Expected no order events for underlying Symbol {security.symbol}\")\n\n        if security.symbol == self.expected_contract:\n            self.assert_future_option_contract_order(order_event, security)\n\n        else:\n            raise AssertionError(f\"Received order event for unknown Symbol: {order_event.symbol}\")\n\n        self.log(f\"{order_event}\")\n\n    def assert_future_option_contract_order(self, order_event: OrderEvent, option_contract: Security):\n        if order_event.direction == OrderDirection.SELL and option_contract.holdings.quantity != -1:\n            raise AssertionError(f\"No holdings were created for option contract {option_contract.symbol}\")\n\n        if order_event.direction == OrderDirection.BUY and option_contract.holdings.quantity != 0:\n            raise AssertionError(\"Expected no options holdings after closing position\")\n\n        if order_event.is_assignment:\n            raise AssertionError(f\"Assignment was not expected for {order_event.symbol}\")\n\n    def on_end_of_algorithm(self):\n        if self.portfolio.invested:\n            raise AssertionError(f\"Expected no holdings at end of algorithm, but are invested in: {', '.join([str(i.id) for i in self.portfolio.keys()])}\")\n","sourceCodeStart":70,"sourceCodeEnd":105,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FutureOptionShortPutOTMExpiryRegressionAlgorithm.py#L70-L105","documentation":"FutureOptionShortPutOTMExpiryRegressionAlgorithm.on_order_event dispatches fill events: the symbol must be either the underlying (rejected) or self.expected_contract (validated). Any other filled symbol reaches the else branch and raises AssertionError, flagging an order event for an unrecognised contract.","triggerScenarios":"A FILLED OrderEvent arrives for a symbol that is neither self.es19m20 nor self.expected_contract — e.g., a different option contract series, a rolled future, or a spurious contract.","commonSituations":"The option filter changed and let an extra contract trade; data updates added a new fillable contract; or expected_contract selection logic picked a different contract than the one that actually filled.","solutions":["Check the printed order_event.symbol to identify the unexpected contract and why it was traded.","Tighten the option/future filter in set_filter so only the intended contract is tradeable.","Reconcile self.expected_contract selection with the contract the execution model actually filled."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Whitelist the set of symbols allowed to fill\nallowed = {self.es19m20, self.expected_contract}\nif order_event.status == OrderStatus.FILLED and order_event.symbol not in allowed:\n    raise AssertionError(f'Unexpected fill symbol: {order_event.symbol}')","typeGuard":"def is_known_contract(symbol, expected_contract, underlying) -> bool:\n    return symbol == expected_contract or symbol == underlying","tryCatchPattern":null,"preventionTips":["Restrict the option/future filter in set_filter so only intended contracts can trade.","Log every fill symbol during test development to spot unexpected contracts early."],"tags":["regression-test","future-options","order-events","symbol"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}