| name | stock-data-fetch |
| description | Fetch multi-market financial data — US (FMP→Finnhub), A/HK (Tencent→Sina), crypto (OKX→Hyperliquid), commodities (Hyperliquid+Finnhub), news (Marketaux), backup (Longbridge). Battle-tested in restricted network environments. |
| category | data-science |
Stock Data Fetch
Quick Start
snapshot TICKER [--no-news] [--no-commit]
One command. All markets. Automatic failover.
Data Sources
US Stocks
- FMP (primary) — quote, EV/EBITDA, FCF yield, growth rates, sector, beta, earnings
- Finnhub (fallback) — PE/PB/ROE, 52-week range (fills gaps FMP free tier lacks)
- Longbridge (backup) — 15min delayed, use only when FMP+Finnhub both fail
A-Shares
- Tencent qt.gtimg.cn — real-time, free, no key
- Sina hq.sinajs.cn — fallback, needs Referer header
HK Stocks
- Tencent qt.gtimg.cn — real-time, free, no key
- Sina hq.sinajs.cn — fallback
- Longbridge (backup) — 15min delayed
Cryptocurrency
- OKX — real-time, 200+ pairs, no key
- Hyperliquid — 7×24 perp prices, 230+ coins, no key
- Binance blocked (HTTP 451) in this region — don't retry
Commodities & Indices
- Hyperliquid — PAXG (gold), SPX (S&P 500 perp)
- Finnhub futures — CL=F (oil), SI=F (silver), NG=F (natgas), HG=F (copper)
News
- Marketaux — entity-linked, sentiment-tagged
Backup
- Longbridge OpenAPI — US/HK/China quotes, 15min delayed
- Keys:
LONGBRIDGE_APP_KEY, LONGBRIDGE_APP_SECRET
- API base:
https://openapi.longbridge.cn
Verified Sources
| Source | Markets | Latency | Key Required |
|---|
| FMP | US | Real-time | ✅ Free |
| Finnhub | US | Real-time | ✅ Free |
| Tencent qt | China A/HK | Real-time | ❌ None |
| Sina | China A/HK | Real-time | ❌ None |
| OKX | Crypto | Real-time | ❌ None |
| Hyperliquid | Crypto+Commodities | Real-time | ❌ None |
| Marketaux | News | Real-time | ✅ Free |
| Longbridge | US/HK/China | 15min delay | ✅ Account |
Lessons Learned (Battle Scars)
Never Use These (in this network)
- yfinance — rate limited + SSL errors. Hermes docs explicitly warn against it
- akshare / akshare-one — both call eastmoney.com which is proxy-blocked
- Google News RSS — guaranteed timeout
- Binance — HTTP 451 (legal block)
API Format Pitfalls
- FMP v3 API is DEPRECATED since Aug 2025. Use
/stable/ endpoints. The error message is misleading
- FMP key from before Aug 2025 is invalid — must re-register for new key
- Tencent qt returns GBK encoding, not UTF-8. Must
decode("gbk") or pipe through iconv -f GBK
- HK stock codes on Tencent need 5 digits:
zfill(5) not lstrip("0"). 00700 → hk00700 not hk700
- Sina requires
Referer: https://finance.sina.com.cn header, or returns empty
- Hyperliquid allMids uses PAXG for gold, not HOLD/XAUT0. SPX exists but is a meme coin ticker
- lark-oapi SDK requires builder pattern:
CreateMessageRequest.builder()...build(), direct construction silently fails
Network Constraints
eastmoney.com — proxy blocked (blocks akshare, akshare-one)
api.binance.com — HTTP 451 (legal)
news.google.com — timeout
yfinance — SSL + rate limit
open.longbridge.com — blocked; use openapi.longbridge.cn instead
Performance
max_turns: 60 → agent loops forever. Reduce to 10 (research needs 4-6)
max_tokens: unlimited → output too long. Cap at 8192
- Bot self-sent messages MUST be filtered by
sender_type in ("bot", "app") or infinite echo loop
CLI Commands
snapshot NVDA
snapshot NVDA --no-news
snapshot 600519.SH
snapshot 00700.HK
snapshot BTC
snapshot GOLD
Output Format
{
"ticker": "NVDA", "retrieved_at": "2026-04-29T10:00:00Z",
"source_apis": ["fmp", "finnhub"],
"data": {
"quote": {"price": 213.17, "change_pct": 2.3},
"fundamentals": {"pe_ttm": 42.7, "market_cap": 5181096612529},
"earnings_latest": {"revenue": 215938000000, "net_income": 120067000000}
}
}