Skip to content

Default to all market hours when no symbol is provided to time rules#9470

Open
AlexCatarino wants to merge 1 commit intoQuantConnect:masterfrom
AlexCatarino:bug-9461-no-symbol-market-time-rules
Open

Default to all market hours when no symbol is provided to time rules#9470
AlexCatarino wants to merge 1 commit intoQuantConnect:masterfrom
AlexCatarino:bug-9461-no-symbol-market-time-rules

Conversation

@AlexCatarino
Copy link
Copy Markdown
Member

Description

Adds no-symbol overloads of AfterMarketOpen, BeforeMarketOpen, AfterMarketClose and BeforeMarketClose on TimeRules. 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 of SecurityExchangeHours to 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.cs covering:

  • Empty Securities → SPY fallback (open and close)
  • Always-open-only subscription → SPY fallback
  • US equity vs extended-hours future → future wins both open and close
  • US equity vs Forex (EURUSD) → forex wins both open and close
  • US equity vs CFD (XAUUSD) → CFD wins both open and close
  • US equity vs regular-hours future → tied open, future wins close
  • US equity vs equity option (SPY options) → tied open and close
  • US equity vs index option (SPX) → tied open, SPX option wins close

All 43 TimeRulesTests pass (28 pre-existing + 15 new).

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>

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>
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.

Default to ALL market opens in market data subscriptions

1 participant