A Go web server that fetches historical stock price data with P/E ratios.
- US Stocks: Daily prices with historical P/E ratio (via macrotrends.net)
- HK Stocks: Daily prices via Yahoo Finance
- Period aggregation: weekly, monthly, quarterly, yearly
- Drop day analysis (2%–5%+ buckets, close-based and low-based)
- SQLite cache with delta fetching — first fetch ~10s, subsequent fetches ~20ms
- Excel export
- Responsive web UI with interactive charts (price, P/E) and EPS in tooltips
- Mobile-friendly — chart renders on all screen sizes
- AWS Lambda support
go build
./stock-fetcher # starts on :8080
PORT=3000 ./stock-fetcher # starts on :3000# Using published image
docker compose up -d
# Build from source
docker compose up -d --buildCache is persisted in a named volume (cache-data → /data/cache.db).
| Method | Path | Description |
|---|---|---|
| GET | /api/health |
Health check + version info |
| GET | /api/stock/{symbol} |
Fetch stock data (JSON) |
| GET | /api/stock-excel/{symbol} |
Download Excel file |
| GET | /api/indices |
List available indices |
| GET | /api/indices/{name} |
List symbols in an index |
| GET | / |
Web UI |
| Param | Default | Values |
|---|---|---|
days |
1825 (5 years) | Number of days of historical data |
period |
monthly | daily, weekly, monthly, quarterly, yearly |
curl localhost:8080/api/stock/AAPL
curl localhost:8080/api/stock/AAPL?days=90\&period=daily
curl localhost:8080/api/stock/0700.HK?days=365
curl localhost:8080/api/indices/dowHistorical data is cached in SQLite. The DB path is auto-detected:
| Environment | Detection | DB path |
|---|---|---|
| Lambda | AWS_LAMBDA_FUNCTION_NAME env |
/tmp/cache.db |
| Docker | /data directory exists |
/data/cache.db |
| Local | fallback | ./cache.db |
Override with DB_PATH env var. Set DB_PATH=none to disable caching.
| Stock Type | Source | P/E Ratio |
|---|---|---|
| US Stocks | macrotrends.net | ✅ Yes (TTM, historical) |
| HK Stocks (.HK) | Yahoo Finance | ❌ No |
US stocks automatically fall back to Yahoo Finance if macrotrends fails (e.g., ETFs).
| Index | Stocks | Description |
|---|---|---|
sp500 |
502 | S&P 500 |
dow |
30 | Dow Jones Industrial Average |
nasdaq100 |
102 | NASDAQ 100 |
hangseng |
85 | Hang Seng Index |
MIT License