QuantConnect/Lean · error · RegressionTestException
Expected stock assignment but got: {orderEvent}
Error message
Expected stock assignment but got: {orderEvent} What it means
After the option assignment, the next expected Filled event is the stock (underlying) leg of the assignment: OrderType.OptionExercise, IsAssignment == false, Symbol == _stock. If the event is an assignment (duplicate), has the wrong symbol, or is a non-exercise fill, the regression fails.
Source
Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:96
LimitOrder(_option, 1, Securities[_option].Price * 0.1m);
_optionSold = true;
}
// This is the assignment
else if (!_optionAssigned)
{
if (orderEvent.Ticket.OrderType != OrderType.OptionExercise || !orderEvent.IsAssignment)
{
throw new RegressionTestException($"Expected option assignment but got: {orderEvent}");
}
_optionAssigned = true;
}
else if (!_stockAssigned)
{
if (orderEvent.Ticket.OrderType != OrderType.OptionExercise || orderEvent.IsAssignment || orderEvent.Symbol != _stock)
{
throw new RegressionTestException($"Expected stock assignment but got: {orderEvent}");
}
_stockAssigned = true;
}
else
{
throw new RegressionTestException($"Unexpected order fill event: {orderEvent}");
}
}
else if (orderEvent.Status == OrderStatus.CancelPending)
{
// We receive the delisting warning before the order cancel is requested
if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived)
{
throw new RegressionTestException($"Unexpected cancel pending event: {orderEvent}");
}
}
else if (orderEvent.Status == OrderStatus.Canceled)View on GitHub (pinned to d2c3659f87)
Solutions
- Verify _stock (AddEquity("GOOG").Symbol) matches the symbol on the exercise-delivery OrderEvent — account for mapped symbols.
- Log orderEvent.Symbol, IsAssignment, and OrderType for the failing event.
- Check for a Lean regression in option-exercise underlying-delivery event representation.
- Compare the symbol using SID/canonical rather than raw Value if mapping is involved.
Example fix
// before if (orderEvent.Ticket.OrderType != OrderType.OptionExercise || orderEvent.IsAssignment || orderEvent.Symbol != _stock) // after — compare canonical symbol to handle mapping if (orderEvent.Ticket.OrderType != OrderType.OptionExercise || orderEvent.IsAssignment || !orderEvent.Symbol.SID().Equals(_stock.SID()))
Defensive patterns
Strategy: type-guard
Validate before calling
else if (!_stockAssigned)
{
var isExerciseDelivery = orderEvent.Ticket.OrderType == OrderType.OptionExercise
&& !orderEvent.IsAssignment
&& orderEvent.Symbol == _stock;
if (!isExerciseDelivery)
{
Debug($"Symbol mismatch? event={orderEvent.Symbol} stock={_stock}");
throw new RegressionTestException($"Expected stock assignment but got: {orderEvent}");
}
_stockAssigned = true;
} Type guard
static bool IsStockDeliveryLeg(OrderEvent e, Symbol stock) =>
e.Ticket.OrderType == OrderType.OptionExercise && !e.IsAssignment && e.Symbol == stock; Prevention
- Compare symbols by SID/canonical form when mapping (GOOG vs GOOCV) is involved.
- Log the event symbol, IsAssignment, and OrderType for every fill.
- Extend the state machine explicitly if Lean adds new exercise-delivery event types.
When it happens
Trigger: A second option-assignment event arrives instead of the underlying leg, the underlying delivery uses a different symbol than _stock (e.g., a mapped symbol), or an unexpected order fill interrupts the sequence.
Common situations: Symbol mapping (GOOG vs GOOCV) causing orderEvent.Symbol != _stock, a Lean change in how the underlying delivery event is represented, or a duplicate assignment event.
Related errors
- Expected option assignment but got: {orderEvent}
- Unexpected order fill event: {orderEvent}
- Option was not assigned
- Stock was not assigned
- Index is not tradable.
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/9dfa95a0a168c41c.
Report an issue: GitHub.