Skip to content

Auto-subscribe symbols when registering indicators and consolidators#9582

Merged
Martin-Molinero merged 1 commit into
QuantConnect:masterfrom
jhonabreul:feature-auto-subscribe-on-indicator-consolidator-registration
Jul 2, 2026
Merged

Auto-subscribe symbols when registering indicators and consolidators#9582
Martin-Molinero merged 1 commit into
QuantConnect:masterfrom
jhonabreul:feature-auto-subscribe-on-indicator-consolidator-registration

Conversation

@jhonabreul

Copy link
Copy Markdown
Collaborator

Description

Registering an indicator or a consolidator for a symbol that has not been subscribed to used to throw:

Please register to receive data for symbol '...' using the AddSecurity() function.

Order submission already auto-subscribes a symbol on the user's behalf (see GetSecurityForOrder). This PR applies the same behavior to indicator and consolidator registration: GetSubscription now adds the security automatically when it has no subscription, before falling back to the error message.

Details:

  • The tradability/expiry guard used by order submission was extracted into a shared CanAutoAddSecurity helper, now used by both GetSecurityForOrder and GetSubscription. Order submission keeps its extra SecurityType != Index check (indexes are not tradable), while the subscription path allows indexes since it only needs their data.
  • The subscription lookup in GetSubscription was refactored into a bool TryGetSubscription(..., out SubscriptionDataConfig subscription) helper, replacing the previous try/catch control flow.

Related Issue

N/A

Motivation and Context

Users can already trade a symbol without subscribing to it (order submission subscribes it automatically). It is surprising and inconsistent that registering an indicator or consolidator for that same symbol throws instead. This makes the behavior consistent across the API.

Requires Documentation Change

No.

How Has This Been Tested?

  • Added RegisterIndicatorAndConsolidatorWithoutSubscriptionRegressionAlgorithm, which never calls AddEquity/AddSecurity and:
    • registers an SMA indicator and a 30-minute consolidator for SPY (exercising the indicator/consolidator auto-add), asserting the indicator receives data and the consolidator produces bars;
    • submits a MarketOrder for a separate, unsubscribed symbol (AIG) (exercising the order-submission auto-add), asserting the order is placed and filled and that the position is established.
  • Verified the algorithm fails on master (throws during initialization) and passes with this change.
  • Ran the related unit fixtures with no regressions: AlgorithmIndicatorsTests, AlgorithmResolveConsolidatorTests, AlgorithmRegisterIndicatorTests, AlgorithmSubscriptionManagerRemoveConsolidatorTests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Registering an indicator or consolidator for a symbol that had not been
subscribed to threw 'Please register to receive data for symbol ...'.
Order submission already auto-subscribes the symbol on the user's behalf;
this applies the same behavior to indicator/consolidator registration.

GetSubscription now adds the security automatically when it has no
subscription (guarded by the shared CanAutoAddSecurity check, which is
also used by order submission) before falling back to the error. The
subscription lookup is exposed via a TryGetSubscription out-parameter
helper.
@jhonabreul jhonabreul marked this pull request as ready for review July 2, 2026 16:45
@jhonabreul jhonabreul requested review from Martin-Molinero and Copilot and removed request for Copilot July 2, 2026 17:35

@Martin-Molinero Martin-Molinero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@Martin-Molinero Martin-Molinero merged commit a4bea04 into QuantConnect:master Jul 2, 2026
7 of 8 checks passed
@jhonabreul jhonabreul deleted the feature-auto-subscribe-on-indicator-consolidator-registration branch July 2, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants