Fix S&P 500 alerts failing on Alpha Vantage premium endpoint#21
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
fetchSp500helper to fetch daily + weekly series and compute a pre-window ATH baseline. - Update
sp500-closeandsp500-drawdownalerts (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.
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.
What
TIME_SERIES_DAILY&outputsize=fullto a paid plan, so the dailysp500-closeandsp500-drawdownalerts threw every morning.TIME_SERIES_WEEKLYhistory instead, keeping free dailycompactbars for the recent closes. Effective ATH =max(pre-window weekly high, recent daily closes).How to test
pnpm --filter @repo/alerts testpnpm --filter @repo/alpha-vantage testpnpm testSecurity review
No security-impacting changes.