A professional-grade stock analytics platform with real-time quotes, interactive charts, technical indicators, and watchlists. Features multi-source data integration with automatic failover for maximum reliability.
┌─────────────────────────────────────────────────────────────────┐
│ Frontend (Svelte + Vite) │
│ SearchBar │ StockView │ PriceChart │ Watchlist │ Indicators │
└──────────────────────────┬──────────────────────────────────────┘
│ REST API + SSE
┌──────────────────────────▼──────────────────────────────────────┐
│ Backend (Express + TypeScript) │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ Multi-Source Stock API Client │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────────┐ │ │
│ │ │ Twelve │→ │ Finnhub │→ │ Yahoo │→ │ Cache │ │ │
│ │ │ Data │ │(fallback)│ │ Finance │ │ (memory) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └────────────┘ │ │
│ └────────────────────────────────────────────────────────────┘ │
│ Stock Routes │ Watchlist Routes │ Alert Routes │ SSE Stream │
└──────────────────────────┬──────────────────────────────────────┘
│
┌──────────────────────────▼──────────────────────────────────────┐
│ Supabase (PostgreSQL) │
│ - watchlists - price_history (cache) │
│ - watchlist_stocks - price_alerts │
└─────────────────────────────────────────────────────────────────┘
| Data Type | Primary | Fallback 1 | Fallback 2 |
|---|---|---|---|
| Quotes | Twelve Data | Finnhub | Yahoo Finance |
| Historical | DB Cache → Twelve Data | Alpha Vantage | Yahoo Finance |
| Search | Twelve Data | Finnhub | - |
| Indicators | Twelve Data | - | - |
Clone the repository
git clone https://github.com/yourusername/stock-analytics.git
cd stock-analytics
Install dependencies
npm install
cd frontend && npm install && cd ..
Configure environment variables
cp .env.example .env
Edit .env:
PORT=3000
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-anon-key
# Primary data source (get at https://twelvedata.com)
TWELVE_DATA_API_KEY=your-key
# Fallback sources (recommended for reliability)
FINNHUB_API_KEY=your-key # https://finnhub.io
ALPHA_VANTAGE_API_KEY=your-key # https://alphavantage.co
Set up the database
Run in Supabase SQL Editor:
-- Watchlists
CREATE TABLE watchlists (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- Watchlist stocks
CREATE TABLE watchlist_stocks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
watchlist_id UUID REFERENCES watchlists(id) ON DELETE CASCADE,
symbol VARCHAR(10) NOT NULL,
added_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(watchlist_id, symbol)
);
-- Price alerts
CREATE TABLE price_alerts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
symbol VARCHAR(10) NOT NULL,
target_price DECIMAL(12, 2) NOT NULL,
condition VARCHAR(10) NOT NULL CHECK (condition IN ('above', 'below')),
triggered BOOLEAN DEFAULT FALSE,
triggered_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Historical price cache
CREATE TABLE price_history (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
symbol VARCHAR(10) NOT NULL,
date DATE NOT NULL,
open DECIMAL(12, 2),
high DECIMAL(12, 2),
low DECIMAL(12, 2),
close DECIMAL(12, 2),
volume BIGINT,
UNIQUE(symbol, date)
);
-- Indexes
CREATE INDEX idx_watchlist_stocks_symbol ON watchlist_stocks(symbol);
CREATE INDEX idx_price_alerts_symbol ON price_alerts(symbol);
CREATE INDEX idx_price_history_symbol_date ON price_history(symbol, date DESC);
Build and start
cd frontend && npm run build && cd ..
npm run dev
Open the app at http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/stocks/quote/:symbol |
Get current stock quote |
| GET | /api/stocks/search?q= |
Search stocks by name/symbol |
| GET | /api/stocks/history/:symbol?days=90 |
Get historical OHLCV data |
| GET | /api/stocks/indicators/:symbol |
Get RSI, MACD, SMA indicators |
| GET | /api/stocks/overview/:symbol |
Get all data in one call |
| GET | /api/stocks/status |
Check API sources status |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/watchlists |
Get all watchlists |
| POST | /api/watchlists |
Create watchlist |
| DELETE | /api/watchlists/:id |
Delete watchlist |
| POST | /api/watchlists/:id/stocks |
Add stock to watchlist |
| DELETE | /api/watchlists/:id/stocks/:symbol |
Remove stock |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/alerts |
Get all alerts |
| POST | /api/alerts |
Create price alert |
| DELETE | /api/alerts/:id |
Delete alert |
| GET | /api/stream/prices?symbols= |
SSE price updates |
| GET | /api/stream/alerts |
SSE alert notifications |
| Indicator | Description | Signal |
|---|---|---|
| RSI (14) | Relative Strength Index | >70 Overbought, <30 Oversold |
| MACD | 12/26/9 Moving Average Convergence | Histogram shows momentum |
| SMA 20 | 20-day Simple Moving Average | Short-term trend |
| SMA 50 | 50-day Simple Moving Average | Medium-term trend |
| Source | Rate Limit | Cache TTL |
|---|---|---|
| Twelve Data | 8/min, 800/day | 60s quotes, 5min history |
| Finnhub | 60/min | 60s quotes |
| Yahoo Finance | Unlimited | 60s quotes, 10min history |
| Database | N/A | Persistent historical data |
The app includes built-in request throttling to prevent hitting rate limits.
# Start dev server (auto-kills existing process on port 3000)
npm run dev
# Build frontend only
cd frontend && npm run build
# Type checking
npm run lint
The frontend builds to public/build/ and is served by Express. For separate deployment, use the frontend/dist folder.
| Variable | Description | Required |
|---|---|---|
PORT |
Server port (default: 3000) | No |
SUPABASE_URL |
Supabase project URL | Yes |
SUPABASE_ANON_KEY |
Supabase anon key | Yes |
TWELVE_DATA_API_KEY |
Twelve Data API key | Yes |
FINNHUB_API_KEY |
Finnhub API key | Recommended |
ALPHA_VANTAGE_API_KEY |
Alpha Vantage API key | Optional |
MIT License - see LICENSE for details.
Built with Claude Code