Skip to content

fix(market-hours): NYSE rules win when Alpaca's calendar disagrees, with a notice - #629

Merged
iAmGiG merged 2 commits into
developmentfrom
fix/calendar-guards
Oct 28, 2026
Merged

iAmGiG merged 2 commits into
developmentfrom
fix/calendar-guards

Conversation

@iAmGiG

@iAmGiG iAmGiG commented Oct 28, 2026

Copy link
Copy Markdown
Owner

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:

  • the expected answers for weekends, holidays, Veterans Day (it trades), the 11-27 and 12-24 1 p.m. closes, and 2025-01-09 (closed);
  • v2's data ends on 2029-12-24: 2029-12-26, 12-31 and 2030 come back empty although they are trading days. /v3/calendar/NYSE already 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)

  • An empty answer on a rules trading day: the rules win, nothing is cached, and the scheduler raises one WARNING notice calendar_disagrees:<day>. Its text says to add the date to config_defaults/market_hours.yaml if NYSE announced a closure. The owner chose this: running on a closed market costs less than skipping a trading day.
  • A row dated for another day is ignored.
  • On a rules early-close day, the earlier 13:00 close wins.
  • Weekends and days after CALENDAR_LAST_DAY = 2029-12-24 go straight to the rules, with no request (about 570 fewer calls a weekend).
  • A session the rules call closed is still trusted (Alpaca may know a new session), and noted.

Tests

  • 1315 passed, 2 skipped. New: the guard tests, a two-tick test that gives one notice, and NYSE's published 2026-2028 holidays and early closes as an oracle independent of Alpaca's output (our rules match).
  • Red check: all 9 behaviour tests fail on 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

…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>
@iAmGiG iAmGiG added bug Something isn't working infrastructure Infrastructure changes, deployment, and DevOps paper-trading Paper trading features and testing labels Oct 28, 2026
…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>
@iAmGiG
iAmGiG merged commit aee71c9 into development Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working infrastructure Infrastructure changes, deployment, and DevOps paper-trading Paper trading features and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant