A real-time market capitalization tracking API that aggregates data from multiple free financial data sources, similar to companiesmarketcap.com.
- Real-time Market Data: Collects current stock prices and market caps from multiple free APIs
- Historical Tracking: Stores historical market cap data for trend analysis
- Automated Collection: Scheduled data collection every 15 minutes during market hours
- Multiple Data Sources: Fallback system using Yahoo Finance, Alpha Vantage, FMP, and SEC EDGAR
- RESTful API: Clean endpoints for accessing market cap rankings and company data
- Rate Limiting: Built-in protection against API abuse
- Railway Deployment Ready: Configured for easy cloud deployment
- Yahoo Finance: Main source for real-time prices (unofficial but reliable)
- SEC EDGAR API: Official government data for fundamental information
- Alpha Vantage: 25 calls/day free tier for backup data
- Financial Modeling Prep (FMP): 250 calls/day free tier
- Price Updates: Every 15 minutes during market hours (9 AM - 4 PM EST)
- Fundamental Data: Daily collection of shares outstanding from SEC filings
- Fallback System: If one API fails, automatically tries the next source
- Rate Limiting: Respects all API rate limits with intelligent delays
- Clone and Setup:
cd market-cap-api
npm install- Environment Configuration:
cp .env.example .envEdit .env with your API keys:
# Free API Keys (all optional, system works with fallbacks)
ALPHA_VANTAGE_API_KEY=your_key_here # Get free at alphavantage.co
FMP_API_KEY=your_key_here # Get free at financialmodelingprep.com
# Database
DATABASE_PATH=./data/market_caps.db
# Server
PORT=3001
NODE_ENV=development- Initialize Database:
npm run collect # This will create the database and collect initial datanpm run dev # Start with auto-reload
npm run collect # Manual data collectionnpm start # Production serverGET /api/top-companies?limit=50Response:
{
"success": true,
"data": [
{
"rank": 1,
"ticker": "AAPL",
"name": "Apple Inc.",
"market_cap": 3000.5,
"price": 185.42,
"change_percent": 1.23,
"sector": "Technology",
"exchange": "NASDAQ",
"last_updated": "2025-01-21T15:30:00Z"
}
],
"meta": {
"total": 50,
"lastUpdated": "2025-01-21T15:30:00Z"
}
}GET /api/company/AAPL?days=30GET /api/rankings/2025-01-21?limit=10GET /api/statsGET /health- Basic company information (ticker, name, sector, etc.)
- Shares outstanding from SEC filings
- IPO dates and metadata
- Daily price and market cap snapshots
- Source attribution for each data point
- Volume and change percentage tracking
- Optimized table for fast ranking queries
- Updated after each price collection
- Top 100 companies by market cap
- Tracks all data collection attempts
- Success/failure rates and error logging
- Performance metrics
- Market Hours: Every 15 minutes (9 AM - 4 PM EST, Mon-Fri)
- After Hours: Every hour
- Weekends: Every 6 hours (for international markets)
- Real-time prices: 15-minute delay (similar to companiesmarketcap.com)
- Market caps: Calculated as Price × Shares Outstanding
- Shares outstanding: Updated daily from SEC filings
- Multiple source validation: Cross-checks between APIs
- Automatic fallback between data sources
- Graceful handling of API failures
- Comprehensive logging and monitoring
- Data integrity checks
# Install Railway CLI
npm install -g @railway/cli
# Login and deploy
railway login
railway init
railway deploySet these in your Railway dashboard:
ALPHA_VANTAGE_API_KEY=your_key
FMP_API_KEY=your_key
NODE_ENV=production
DATABASE_PATH=/app/data/market_caps.dbThe app includes a railway.toml file with optimized settings:
- Build Command:
npm install - Start Command:
npm start - Health Check:
/health - Auto-scaling: Enabled
- Yahoo Finance: Unlimited (unofficial)
- SEC EDGAR: Unlimited (official government API)
- Alpha Vantage: 25 calls/day (covers 25 companies)
- FMP: 250 calls/day (covers major companies)
- Alpha Vantage Pro: $29.99/month (500 calls/day)
- FMP Premium: $19.99/month (unlimited calls)
- Railway Hosting: $5-20/month depending on usage
- Free tier: $0/month (covers top 50-100 companies)
- Premium tier: $50-100/month (covers all US stocks)
- Request/response logging with Winston
- Performance metrics tracking
- Data collection success rates
- Error tracking and alerting
/healthendpoint for uptime monitoring- Database connectivity checks
- API source availability tracking
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details.
For issues or questions:
- Check the logs in
logs/directory - Verify API keys are valid
- Test individual endpoints with curl/Postman
- Check Railway deployment logs if using cloud hosting