QuantConnect/Lean · error · RegressionTestException
Expected option assignment but got: {orderEvent}
Error message
Expected option assignment but got: {orderEvent} What it means
In OnOrderEvent, after the initial option sell fill, the next expected Filled event must be the option assignment: OrderType.OptionExercise with IsAssignment == true. If the event is not an assignment (e.g., the limit order from line 78 filled, or an unexpected fill arrived), the regression fails.
Source
Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:87
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Status == OrderStatus.Filled)
{
// This is the fill for the option sell order
if (!_optionSold)
{
// Let's close the position but with a limit order that won't ever fill (limit price too low)
// just so we keep it open until the brokerage tries to assign it
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}");
}
}View on GitHub (pinned to d2c3659f87)
Solutions
- Confirm the LimitOrder price (10% of current) is far enough from market that it cannot fill; lower the factor if needed.
- Log every OrderEvent with its Status, OrderType, IsAssignment, and Symbol to trace the sequence.
- Verify the option (GOOG Put $800 expiring 2015-12-24) is in-the-money at expiry so assignment occurs.
- Check for a Lean regression in option-exercise event generation.
Defensive patterns
Strategy: validation
Validate before calling
else if (!_optionAssigned)
{
if (orderEvent.Ticket.OrderType != OrderType.OptionExercise || !orderEvent.IsAssignment)
{
Debug($"Unexpected event: {orderEvent.Status} {orderEvent.Ticket.OrderType} IsAssign={orderEvent.IsAssignment}");
throw new RegressionTestException($"Expected option assignment but got: {orderEvent}");
}
_optionAssigned = true;
} Prevention
- Place limit orders far enough from market price that they cannot fill.
- Log every OrderEvent to trace the fill sequence.
- Verify the option is ITM at expiry so assignment occurs.
When it happens
Trigger: The LimitOrder placed at 10% of price unexpectedly filled (it is designed never to fill), or an order event arrives out of the expected sequence (sell -> option assignment -> stock assignment), or assignment did not fire by expiry.
Common situations: A Lean change where low-priced limit orders fill against the bid, a change in option-exercise/assignment event ordering, or the option not being assigned at expiry due to a data/exercise-logic regression.
Related errors
- Expected stock 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/907d2fcb41907a19.
Report an issue: GitHub.