QuantConnect/Lean · error · RegressionTestException

Unexpected order fill event: {orderEvent}

Error message

Unexpected order fill event: {orderEvent}

What it means

After the three expected Filled events (option sell, option assignment, stock assignment), any additional Filled event is unexpected and triggers this error. It guards against duplicate or spurious fills beyond the defined sequence.

Source

Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:103

                    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)
            {
                // The delisted event is received before the order is canceled
                if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived || !_optionDelisted)
                {
                    throw new RegressionTestException($"Unexpected cancel event: {orderEvent}");
                }

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Log the extra orderEvent fully (Status, Symbol, OrderType, IsAssignment, FillQuantity, FillPrice) to identify its source.
  2. Confirm the LimitOrder was canceled before it could fill (it should be canceled on delisting).
  3. Check for a Lean regression producing duplicate exercise fills.
  4. If an additional fill is now legitimately expected, extend the state machine rather than silently ignoring it.
Defensive patterns

Strategy: validation

Validate before calling

else
{
    Debug($"Extra fill after expected sequence: {orderEvent}");
    // Determine if it is the limit order filling unexpectedly
    throw new RegressionTestException($"Unexpected order fill event: {orderEvent}");
}

Prevention

When it happens

Trigger: A fourth fill arrives — e.g., the LimitOrder from line 78 actually filled after assignment, a duplicate assignment event, or an extra exercise-delivery fill. The _stockAssigned flag is already true so the else-branch catches it.

Common situations: The never-fill LimitOrder eventually fills (price gap, or Lean fill logic change), a duplicate option-exercise event, or a Lean change generating an extra fill for the assignment.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/00fbe04712b4a051. Report an issue: GitHub.