QuantConnect/Lean · error · RegressionTestException
Algorithm should have just 1 order, but was {transactions}
Error message
Algorithm should have just 1 order, but was {transactions} What it means
Asserts exactly one order was placed. The Sell fires only when ShortableQuantity > 1000, which (per the custom provider) is true only after 2013-10-04 16:00 returning 1001. With Daily resolution over 2013-10-04..06 the condition is met exactly once. != 1 means it never fired (0) or fired multiple times (lack of Portfolio.Invested guard).
Source
Thrown at Algorithm.CSharp/CustomShortableProviderRegressionAlgorithm.cs:58
_spy = AddEquity("SPY", Resolution.Daily);
_spy.SetShortableProvider(new CustomSPYShortableProvider());
}
public override void OnData(Slice slice)
{
var spyShortableQuantity = _spy.ShortableProvider.ShortableQuantity(_spy.Symbol, Time);
if (spyShortableQuantity > 1000)
{
_orderId = Sell("SPY", (int)spyShortableQuantity);
}
}
public override void OnEndOfAlgorithm()
{
var transactions = Transactions.OrdersCount;
if (transactions != 1)
{
throw new RegressionTestException($"Algorithm should have just 1 order, but was {transactions}");
}
var orderQuantity = Transactions.GetOrderById(_orderId).Quantity;
if (orderQuantity != -1001)
{
throw new RegressionTestException($"Quantity of order {_orderId} should be -1001, but was {orderQuantity}");
}
var feeRate = _spy.ShortableProvider.FeeRate(_spy.Symbol, Time);
if (feeRate != 0.0025m)
{
throw new RegressionTestException($"Fee rate should be 0.0025, but was {feeRate}");
}
var rebateRate = _spy.ShortableProvider.RebateRate(_spy.Symbol, Time);
if (rebateRate != 0.0507m)
{
throw new RegressionTestException($"Fee rate should be 0.0507, but was {rebateRate}");
}
}
View on GitHub (pinned to d2c3659f87)
Solutions
- Add a Portfolio.Invested / Transactions.OrdersCount guard so the sell fires once, not every qualifying bar.
- Confirm ShortableQuantity's date threshold (2013-10-04 16:00) falls inside the backtest window in the security's exchange time zone.
- Match the expected resolution (Daily) and date range so exactly one bar returns > 1000.
- Re-check the custom provider returns 1001 (not null) for the qualifying dates.
Example fix
// before: sells on every bar where shortable > 1000
if (spyShortableQuantity > 1000) _orderId = Sell("SPY", (int)spyShortableQuantity);
// after: sell exactly once
if (!Portfolio.Invested && spyShortableQuantity > 1000)
_orderId = Sell("SPY", (int)spyShortableQuantity); Defensive patterns
Strategy: validation
Validate before calling
// Guard so the sell fires exactly once
if (!Portfolio.Invested && Transactions.OrdersCount == 0 && spyShortableQuantity > 1000)
_orderId = Sell("SPY", (int)spyShortableQuantity); Prevention
- Add a Portfolio.Invested / OrdersCount guard so condition-true bars do not stack orders.
- Ensure ShortableQuantity's date threshold falls in-window in exchange time.
- Match the expected resolution and date range.
When it happens
Trigger: OnData sells when shortable > 1000; if that branch never runs you get 0 orders, if it runs every bar you get several. The test expects precisely one sell of 1001 shares.
Common situations: ShortableQuantity returns <= 1000 for the whole window (date logic wrong, wrong Time zone); no Portfolio.Invested guard so Sell fires on every bar after the threshold; or resolution/date-range change shifts how many bars exceed 1000.
Related errors
- Quantity of order {_orderId} should be -1001, but was {order
- Fee rate should be 0.0025, but was {feeRate}
- Fee rate should be 0.0507, but was {rebateRate}
- Order was not canceled
- There should be no open orders
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/4177dd84f05a7ee0.
Report an issue: GitHub.