Repository navigation
fix(market-hours): NYSE rules win when Alpaca's calendar disagrees, with a notice - #629
Merged
Merged
Conversation
…s, with a notice Alpaca's v2 calendar is trusted only where it agrees with the NYSE rules: - an empty answer on a rules trading day uses the rules (the routines run), isn't cached, and raises one WARNING notice calendar_disagrees:<day> - a row dated for another day is ignored (an out-of-range query once came back as 1970-01-02) - on a rules early-close day the earlier 13:00 close wins, so the evening routine still runs before the close - weekends and days after 2029-12-24 are answered by the rules with no request: checked 2026-10-28, v2's data ends there (2029-12-26/31 and 2030 come back empty although they trade) - a session the rules call closed is still trusted, and noted Tests: NYSE's published 2026-2028 holidays and early closes as an oracle independent of Alpaca's own output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ext per case, earlier close either way - a disagreement caches the rules' answer for the process (cron's next tick asks again), instead of a new request on every lookup - each disagreement says what was followed; the notice no longer claims the rules were used when the calendar was - a calendar close earlier than the rules' on a full day is also used and noted - the _disagree helper is gone Co-Authored-By: Claude Opus 5.5 <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.
Why
The scheduler asks Alpaca's v2 calendar whether today trades. An empty answer meant "closed", so a wrong answer would skip both routines for the day: no stop repair, raises, alerts or records.
A read-only probe of the paper calendar on 2026-10-28 (GETs only, no orders) found:
/v3/calendar/NYSEalready covers 2030.Research (docs, SDK source, incidents, exchange calendars) found the request can't shift the day (plain ET dates), v2 follows the NYSE schedule (SPY on Arca and QQQ on Nasdaq share it), and no reports of an empty answer on a real trading day.
What changes (
src/utils/market_hours.py)calendar_disagrees:<day>. Its text says to add the date toconfig_defaults/market_hours.yamlif NYSE announced a closure. The owner chose this: running on a closed market costs less than skipping a trading day.CALENDAR_LAST_DAY = 2029-12-24go straight to the rules, with no request (about 570 fewer calls a weekend).Tests
development.Follow-up
Before 2029-12-24, move to
/v3/calendar/NYSE. alpaca-py has no v3 route; its REST client can call it.🤖 Generated with Claude Code