QuantConnect/Lean · error · RegressionTestException
{Time} - Unexpected order event symbol: {orderEvent.Symbol}.
Error message
{Time} - Unexpected order event symbol: {orderEvent.Symbol}. Expected {_contractToTrade} What it means
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.
Source
Thrown at Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs:118
if (_contractToTrade != null && slice.Delistings.TryGetValue(_contractToTrade, out var delisting))
{
if (delisting.Type == DelistingType.Delisted)
{
_delisted = true;
if (Portfolio.Invested)
{
throw new RegressionTestException($"{Time} - Portfolio should not be invested after the traded contract is delisted.");
}
}
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Symbol != _contractToTrade)
{
throw new RegressionTestException($"{Time} - Unexpected order event symbol: {orderEvent.Symbol}. Expected {_contractToTrade}");
}
if (orderEvent.Direction == OrderDirection.Buy)
{
if (orderEvent.Status == OrderStatus.Filled)
{
if (_boughtQuantity != 0 && _liquidatedQuantity != 0)
{
throw new RegressionTestException($"{Time} - Unexpected buy order event status: {orderEvent.Status}");
}
_boughtQuantity = orderEvent.Quantity;
}
}
else if (orderEvent.Direction == OrderDirection.Sell)
{
if (orderEvent.Status == OrderStatus.Filled)
{
if (_boughtQuantity <= 0 && _liquidatedQuantity != 0)View on GitHub (pinned to d2c3659f87)
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.
Example fix
// before
if (orderEvent.Symbol != _contractToTrade) { throw ...; }
// after: allow the new mapped contract's liquidation events too
if (orderEvent.Symbol != _contractToTrade && orderEvent.Symbol != _mappedSymbol)
{
throw new RegressionTestException($"{Time} - Unexpected order event symbol: {orderEvent.Symbol}.");
} Defensive patterns
Strategy: validation
Validate before calling
public override void OnOrderEvent(OrderEvent orderEvent)
{
var allowed = new[] { _contractToTrade, _mappedSymbol };
if (!allowed.Contains(orderEvent.Symbol))
{
Log($"{Time} - Ignoring order event for {orderEvent.Symbol}");
return;
}
} Type guard
bool IsExpectedOrderSymbol(Symbol s) => s == _contractToTrade || s == _mappedSymbol;
Prevention
- Ensure _contractToTrade is assigned before orders can fill.
- Allow liquidation events for the new mapped symbol after rollover.
- Avoid placing orders on unintended contracts.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {Time} - Unexpected buy order event status: {orderEvent.Stat
- {Time} - Unexpected sell order event status: {orderEvent.Sta
- {Time} - Unexpected liquidated quantity: {_liquidatedQuantit
- Unexpected sold quantity: {_boughtQuantity} and liquidated q
- {Time} - Unexpected symbol changed event old symbol: {change
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/587daeceaa9d9f68.
Report an issue: GitHub.