QuantConnect/Lean · error · RegressionTestException
Option was not sold
Error message
Option was not sold
What it means
In OnEndOfAlgorithm this asserts _optionSold is true: the regression algorithm sold (shorted) the option during its run. If false, the sell order never executed or OnOrderEvent never set the flag. The algorithm depends on this sale to then be assigned and receive stock.
Source
Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:157
_optionDelistedWarningReceived = true;
}
else
{
if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived || _optionDelisted)
{
throw new RegressionTestException($"Unexpected delisting event: {delisting}");
}
_optionDelisted = true;
}
}
public override void OnEndOfAlgorithm()
{
if (!_optionSold)
{
throw new RegressionTestException("Option was not sold");
}
if (!_optionAssigned)
{
throw new RegressionTestException("Option was not assigned");
}
if (!_stockAssigned)
{
throw new RegressionTestException("Stock was not assigned");
}
if (!_optionDelistedWarningReceived)
{
throw new RegressionTestException("Option delisting warning was not received");
}
if (!_optionDelisted)View on GitHub (pinned to d2c3659f87)
Solutions
- Check the algorithm logs for the option order submission and fill events.
- Verify the option data file exists and has bars for the start date; confirm the FillModel produced a fill.
- Trace OnOrderEvent to ensure the OrderEvent.Status == Filled path sets _optionSold.
Defensive patterns
Strategy: validation
Validate before calling
// Before relying on the sale, validate the order was placed and is filling
var ticket = Transactions.GetOrderTickets(_option).LastOrDefault();
if (ticket == null || ticket.Status != OrderStatus.Filled)
{
// surface why the sell did not complete
Log($"Option sell not filled: {ticket}");
} Prevention
- Log the order ticket status of the initial sell so OnEndOfAlgorithm failures are diagnosable.
- Verify option data availability for the start date before relying on a fill.
- Confirm the brokerage model allows the short option sale.
When it happens
Trigger: The initial option sell order was not filled (insufficient buying power, market closed, no option data), or OnOrderEvent failed to match the fill event that sets _optionSold.
Common situations: Data gaps for the option contract (no quotes/trades), brokerage model rejecting the short sale, fill slippage/time changes, or transaction-handler changes that drop the fill event.
Related errors
- Option was not assigned
- Stock was not assigned
- Option delisting warning was not received
- Option was not delisted
- Unexpected delisting events
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/e99f8af36e05dda4.
Report an issue: GitHub.