QuantConnect/Lean · error · RegressionTestException
Order was not canceled
Error message
Order was not canceled
What it means
Asserts _orderCanceled: during the algorithm, an order was canceled (set in the OnOrderEvent cancel branch seen in the SOURCE). The test expects a specific order to be canceled after the option is assigned/delisted. Failure means the cancellation path did not execute.
Source
Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:182
if (!_stockAssigned)
{
throw new RegressionTestException("Stock was not assigned");
}
if (!_optionDelistedWarningReceived)
{
throw new RegressionTestException("Option delisting warning was not received");
}
if (!_optionDelisted)
{
throw new RegressionTestException("Option was not delisted");
}
if (!_orderCanceled)
{
throw new RegressionTestException("Order was not canceled");
}
var openOrders = Transactions.GetOpenOrders();
if (openOrders.Count != 0)
{
throw new RegressionTestException("There should be no open orders");
}
if (!Portfolio.Invested)
{
throw new RegressionTestException("Portfolio should be invested");
}
// We should have the stock since the option was assigned
if (Portfolio.Positions.Groups.Single().Single().Symbol != _stock)
{
throw new RegressionTestException("Portfolio should have the stock");
}View on GitHub (pinned to d2c3659f87)
Solutions
- Inspect the open-order log to see if the target order existed and whether it was filled vs canceled.
- Trace the delisting-triggered order cancellation logic in the TransactionHandler/AlgorithmManager.
- Verify the OnOrderEvent cancel branch (OrderEvent.Status == Canceled) sets _orderCanceled.
Defensive patterns
Strategy: validation
Validate before calling
// Inspect whether the target order exists and its status
var open = Transactions.GetOpenOrders(_option);
var all = Transactions.GetOrders(_option);
var canceled = all.Where(o => o.Status == OrderStatus.Canceled).ToList();
if (canceled.Count == 0) Log($"No canceled order for {_option}. Open={open.Count}, Total={all.Count}"); Prevention
- Log order status transitions (submitted/filled/canceled) for the option throughout the run.
- Confirm the engine cancels open option orders on delisting.
- Verify OnOrderEvent maps OrderStatus.Canceled to the flag.
When it happens
Trigger: The order that should be canceled (e.g. a remaining open option order after delisting) was never submitted, or its cancel event did not arrive as OrderStatus.Canceled.
Common situations: Lean's automatic cancellation of open orders on delisting changed; the order fill model filled the order instead of canceling it; a change to order cancellation event dispatch.
Related errors
- There should be no open orders
- Option was not sold
- Option was not assigned
- Stock was not assigned
- Option delisting warning was not received
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/6f2b18de5d9fa4d1.
Report an issue: GitHub.