QuantConnect/Lean · error · AssertionError
Received order event for unknown Symbol: {order_event.symbol
Error message
Received order event for unknown Symbol: {order_event.symbol} What it means
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.
Source
Thrown at Algorithm.Python/FutureOptionShortPutOTMExpiryRegressionAlgorithm.py:88
raise AssertionError(f"Delisting happened at unexpected date: {delisting.time}")
def on_order_event(self, order_event: OrderEvent):
if order_event.status != OrderStatus.FILLED:
# There's lots of noise with OnOrderEvent, but we're only interested in fills.
return
if not self.securities.contains_key(order_event.symbol):
raise AssertionError(f"Order event Symbol not found in Securities collection: {order_event.symbol}")
security = self.securities[order_event.symbol]
if security.symbol == self.es19m20:
raise AssertionError(f"Expected no order events for underlying Symbol {security.symbol}")
if security.symbol == self.expected_contract:
self.assert_future_option_contract_order(order_event, security)
else:
raise AssertionError(f"Received order event for unknown Symbol: {order_event.symbol}")
self.log(f"{order_event}")
def assert_future_option_contract_order(self, order_event: OrderEvent, option_contract: Security):
if order_event.direction == OrderDirection.SELL and option_contract.holdings.quantity != -1:
raise AssertionError(f"No holdings were created for option contract {option_contract.symbol}")
if order_event.direction == OrderDirection.BUY and option_contract.holdings.quantity != 0:
raise AssertionError("Expected no options holdings after closing position")
if order_event.is_assignment:
raise AssertionError(f"Assignment was not expected for {order_event.symbol}")
def on_end_of_algorithm(self):
if self.portfolio.invested:
raise AssertionError(f"Expected no holdings at end of algorithm, but are invested in: {', '.join([str(i.id) for i in self.portfolio.keys()])}")
View on GitHub (pinned to d2c3659f87)
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.
Defensive patterns
Strategy: validation
Validate before calling
# Whitelist the set of symbols allowed to fill
allowed = {self.es19m20, self.expected_contract}
if order_event.status == OrderStatus.FILLED and order_event.symbol not in allowed:
raise AssertionError(f'Unexpected fill symbol: {order_event.symbol}') Type guard
def is_known_contract(symbol, expected_contract, underlying) -> bool:
return symbol == expected_contract or symbol == underlying Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected no order events for underlying Symbol {security.sym
- [{UtcTime}] We hold a delisted securities: {string.Join(",",
- We expected some FOP trading to happen
- We shouldn't be invested anymore
- Expected option assignment but got: {orderEvent}
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/7e702d51b0e1ecaf.
Report an issue: GitHub.