File: functions/api/stock-price.js
Current flow (in order of priority):
-
✅ Alpha Vantage (if API key exists)
- Rate limit: 25 calls/day on free tier
⚠️ - Status: PAID API (limited free tier)
- Rate limit: 25 calls/day on free tier
-
✅ Finnhub (backup if Alpha Vantage fails)
- Rate limit: 60/minute
- Status: PAID API (free tier available)
-
✅ Yahoo Finance (final fallback)
- Rate limit: No official limit (but can block)
- Status: FREE ✨
- Most reliable for your use case!
Currently: Calculated as Price × Shares Outstanding
- Price: From APIs above (Alpha Vantage → Finnhub → Yahoo)
- Shares Outstanding: Already from SEC EDGAR! ✅
Benefits:
- ✅ 100% FREE
- ✅ No API keys needed
- ✅ Works great for your use case
- ✅ Real-time prices
- ✅ Already your fallback (proven reliable)
Change needed: Remove Alpha Vantage and Finnhub, use Yahoo Finance directly.
// Simplified stock-price.js
export async function onRequest({ request, env }) {
const symbol = url.searchParams.get('symbol');
// Direct to Yahoo Finance (skip paid APIs)
const yahooData = await fetchFromYahoo(symbol);
if (yahooData) {
setCachedPrice(symbol, yahooData);
return new Response(JSON.stringify(yahooData));
}
return new Response(JSON.stringify({
error: 'Unable to fetch stock price'
}), { status: 500 });
}We already have:
- ✅ Shares Outstanding (from SEC EDGAR)
- ✅ Price (from Yahoo Finance)
Calculate locally:
market_cap = shares_outstanding × current_priceOR fetch pre-calculated from Yahoo:
// Yahoo Finance already provides market cap!
https://query1.finance.yahoo.com/v8/finance/chart/AAPL
// Returns: result.meta.marketCapFor company cards (static data):
- Use SEC EDGAR data (refreshed daily/weekly)
- Market Cap = Shares Outstanding × Last Price
For live price chart button:
- Use Yahoo Finance for real-time price updates
- No API key needed
- Works on-demand when user clicks
| Source | Cost | Rate Limit | Market Cap | Price | Use Case |
|---|---|---|---|---|---|
| SEC EDGAR | FREE | 10 req/sec | Via calc | ❌ | Annual financials |
| Yahoo Finance | FREE | Unlimited* | ✅ | ✅ | Real-time quotes |
| Alpha Vantage | $0-50/mo | 25/day (free) | ❌ | ✅ | Limited use |
| Finnhub | $0-99/mo | 60/min (free) | ❌ | ✅ | Backup only |
*Yahoo has no official limit but may throttle heavy automation
Do this:
- Update
functions/api/stock-price.js - Remove Alpha Vantage logic (save API quota!)
- Remove Finnhub logic (not needed)
- Use Yahoo Finance only (it's already working!)
Result:
- Same functionality
- No API keys needed
- No rate limits to worry about
- Saves $50-100/month if you were planning to upgrade
Current: Market cap manually updated (old data in JSON)
Better:
- Store shares_outstanding from SEC EDGAR (we already do!)
- Fetch current price from Yahoo when needed
- Calculate:
market_cap = shares × price
Or simpler:
- Just use Yahoo's market cap directly (they provide it!)
Best approach:
-
✅ Use SEC EDGAR for all fundamental data (done!)
- Revenue, Earnings, Assets, etc.
- Shares Outstanding
-
✅ Use Yahoo Finance for price/market cap (free & reliable)
- Real-time prices when user clicks "📈 Price" button
- Market cap updated daily
-
❌ Remove Alpha Vantage dependency
- 25 calls/day is too limiting
- You're likely hitting the fallback anyway
-
❌ Remove Finnhub dependency
- Not needed if Yahoo works
File: functions/api/stock-price.js
- Remove: Alpha Vantage function & logic
- Remove: Finnhub function & logic
- Keep: Yahoo Finance only
- ~50 lines of code removed
- No more API keys to manage
Want me to:
- ✅ Simplify stock-price.js to use only Yahoo Finance?
- ✅ Remove paid API dependencies from your codebase?
- ✅ Update market cap calculation to be more accurate?
All can be done in 5 minutes and will make your app:
- Simpler
- Free-er (no API costs)
- More reliable (no quota limits)
- Easier to maintain
Current: Trying 3 APIs (2 paid, 1 free) for the same data
Optimal: Use 1 free API (Yahoo) that works perfectly
Savings: $0-100/month (if you upgrade paid APIs)
Your entire app can run on 100% FREE data sources:
- SEC EDGAR: ✅ Fundamentals (Revenue, Earnings, etc.)
- Yahoo Finance: ✅ Price & Market Cap (Real-time)
- Total Cost: $0/month 💰