Skip to content

Fix S&P 500 alerts failing on Alpha Vantage premium endpoint#21

Merged
valuecodes merged 2 commits into
mainfrom
feat/sp500-free-ath
Jul 18, 2026
Merged

Fix S&P 500 alerts failing on Alpha Vantage premium endpoint#21
valuecodes merged 2 commits into
mainfrom
feat/sp500-free-ath

Conversation

@valuecodes

Copy link
Copy Markdown
Owner

What

  • Alpha Vantage moved TIME_SERIES_DAILY&outputsize=full to a paid plan, so the daily sp500-close and sp500-drawdown alerts threw every morning.
  • Establish the all-time high from the free TIME_SERIES_WEEKLY history instead, keeping free daily compact bars for the recent closes. Effective ATH = max(pre-window weekly high, recent daily closes).
  • The weekly baseline is restricted to weeks ending before the daily window, so today's close can't leak into the "as-of-yesterday" ATH and fabricate a false rebound alert.
  • Stays stateless — no KV/persistence added. ~4 API calls/day, well within the free tier.
  • Note: deep-history ATH is a weekly-closing-high approximation, not an exact daily-close ATH (accepted trade-off).

How to test

pnpm --filter @repo/alerts test
pnpm --filter @repo/alpha-vantage test
pnpm test

Security review

No security-impacting changes.

Copilot AI review requested due to automatic review settings July 18, 2026 06:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Alpha Vantage integration and S&P 500 alerts to avoid the now-premium TIME_SERIES_DAILY&outputsize=full endpoint by combining free daily compact bars with the free weekly time series to approximate an all-time-high baseline without adding state/persistence.

Changes:

  • Add weekly time-series support to @repo/alpha-vantage (schema + client method) and tests.
  • Introduce a shared fetchSp500 helper to fetch daily + weekly series and compute a pre-window ATH baseline.
  • Update sp500-close and sp500-drawdown alerts (and tests) to use the new fetch strategy.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/alpha-vantage/src/types.ts Refactors time-series parsing into a reusable schema and adds weekly response normalization.
packages/alpha-vantage/src/alpha-vantage.ts Adds getWeeklyTimeSeries() to fetch free long-history weekly data.
packages/alpha-vantage/src/alpha-vantage.test.ts Extends client tests to cover weekly endpoint behavior and query params.
apps/alerts/src/scheduled.test.ts Updates Alpha Vantage mock to support the new weekly call used by alerts.
apps/alerts/src/alerts/sp500.ts Adds shared SPY fetch helper to combine daily compact + weekly history with date cutoff.
apps/alerts/src/alerts/sp500-drawdown.ts Switches drawdown logic to compute ATH from weekly baseline + recent daily closes.
apps/alerts/src/alerts/sp500-drawdown.test.ts Updates tests to mock daily+weekly and adds cases for weekly-baseline and date-cutoff behavior.
apps/alerts/src/alerts/sp500-close.ts Switches close alert to use shared fetch helper and weekly baseline.
apps/alerts/src/alerts/sp500-close.test.ts Adds dedicated test coverage for close alert with weekly baseline and overlap exclusion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/alerts/src/alerts/sp500-drawdown.ts Outdated
Comment thread apps/alerts/src/alerts/sp500-close.ts Outdated
@valuecodes
valuecodes merged commit a248754 into main Jul 18, 2026
7 checks passed
@valuecodes
valuecodes deleted the feat/sp500-free-ath branch July 18, 2026 06:54
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