QuantConnect/Lean · error · RegressionTestException

Expected a single subscription to exist ({spx})

Error message

Expected a single subscription to exist ({spx})

What it means

After AddIndex('SPX', Resolution.Minute, fillForward:false), this asserts SubscriptionManager.Subscriptions has exactly one entry and its Symbol equals spx. .Single() will throw if count != 1. It guards that adding the index creates exactly one subscription, no more. Failure means either zero or multiple subscriptions, or the single subscription's symbol differs from spx.

Source

Thrown at Algorithm.CSharp/DuplicatedIndexOptionSubscriptionRegressionAlgorithm.cs:42

namespace QuantConnect.Algorithm.CSharp
{
    /// <summary>
    /// Reproduces https://github.com/QuantConnect/Lean/issues/7451, making sure no additional subscriptions are added for an index
    /// after manually adding both the underlying and an option contract, with slightly different configurations like the fill forward value.
    /// </summary>
    public class DuplicatedIndexOptionSubscriptionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
    {
        public override void Initialize()
        {
            SetStartDate(2021, 1, 4);
            SetEndDate(2021, 1, 4);
            SetCash(1000000);

            var spx = AddIndex("SPX", Resolution.Minute, fillForward: false).Symbol;

            if (SubscriptionManager.Subscriptions.Single().Symbol != spx)
            {
                throw new RegressionTestException($"Expected a single subscription to exist ({spx})");
            }

            var spxOption = QuantConnect.Symbol.CreateOption(
                spx,
                Market.USA,
                OptionStyle.European,
                OptionRight.Call,
                3200m,
                new DateTime(2021, 1, 15));

            AddIndexOptionContract(spxOption, Resolution.Minute);

            if (SubscriptionManager.Subscriptions.Count() < 2)
            {
                throw new RegressionTestException("Expected subscriptions for the added index option contract");
            }

            if (SubscriptionManager.Subscriptions.Count(x => x.Symbol == spx) != 1)

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Dump SubscriptionManager.Subscriptions after AddIndex to count entries and their symbols.
  2. Check AddIndex for any automatic auxiliary-subscription logic that was introduced.
  3. Ensure the SPX canonical symbol matches the returned subscription Symbol (SID equality).
Defensive patterns

Strategy: validation

Validate before calling

var subs = SubscriptionManager.Subscriptions.Select(s => s.Symbol).ToList();
if (subs.Count != 1 || subs[0] != spx)
{
    foreach (var s in subs) Log($"Subscription: {s}");
}

Prevention

When it happens

Trigger: AddIndex created more than one subscription (duplicate), or the symbol returned does not match. A SubscriptionManager refactor that adds auxiliary subscriptions or changes canonical symbol resolution.

Common situations: Default subscriptions being added automatically (e.g. a benchmark or a helper subscription); symbol canonicalization producing a different SID; fillForward/extendedMarket options triggering extra config entries.

Related errors


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