Default to all market hours when no symbol is provided to time rules#9470
Open
AlexCatarino wants to merge 1 commit intoQuantConnect:masterfrom
Open
Default to all market hours when no symbol is provided to time rules#9470AlexCatarino wants to merge 1 commit intoQuantConnect:masterfrom
AlexCatarino wants to merge 1 commit intoQuantConnect:masterfrom
Conversation
Add no-symbol overloads of `AfterMarketOpen`, `BeforeMarketOpen`, `AfterMarketClose` and `BeforeMarketClose` so scheduled events can be defined without referencing a specific security. Per-date, the helpers pick the earliest open / latest close across the algorithm's non-always-open exchanges, falling back to US equities (SPY) when no eligible security is subscribed. US equities are skipped during the walk since SPY's exchange hours already represent them. Closes QuantConnect#9461. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds no-symbol overloads of
AfterMarketOpen,BeforeMarketOpen,AfterMarketCloseandBeforeMarketCloseonTimeRules. Per-date, the helpers pick the earliest market open / latest market close across the algorithm's subscribed exchanges, ignoring always-open ones (e.g. Crypto). When no eligible security is subscribed they default to US equities (SPY).A small helper
BaseScheduleRules.GetMarketOpenCloseExchangeHours()builds the (deduped) set ofSecurityExchangeHoursto consider. The set is pre-seeded with SPY's exchange hours so the fallback is always present and US equities are skipped during the walk (they share the SPY entry).Related Issue
Closes #9461
Motivation and Context
Agents (and users) frequently write
time_rules.after_market_open(minutes=30)without a symbol, which currently throws because every overload requires one. The fix lets those calls succeed by inferring sensible market hours from the algorithm's subscriptions.Requires Documentation Change
The Scheduled Events documentation should mention that the no-symbol form is now available and document its open/close selection rule (earliest open / latest close, ignoring always-open exchanges, SPY fallback).
How Has This Been Tested?
Added 15 new unit tests in
Tests/Common/Scheduling/TimeRulesTests.cscovering:Securities→ SPY fallback (open and close)All 43
TimeRulesTestspass (28 pre-existing + 15 new).Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>