$npx -y skills add realnaka/alphaloop --skill stock-data-fetchFetch 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.
| 1 | # Stock Data Fetch |
| 2 | |
| 3 | > **关于 `snapshot` 命令**:下文的 `snapshot` 是一个**可选的本地封装脚本**(自己用 Python/shell 包一层多源 failover 即可),不是随仓库分发的二进制。不想写脚本也没关系——本文档把每个市场的**免 key 直连端点**都列出来了,直接 `curl` 就能用。所有需要 key 的源(FMP/Finnhub/Longbridge)请把 key 放进**环境变量**,不要写死在代码里。 |
| 4 | |
| 5 | ## Quick Start |
| 6 | |
| 7 | ```bash |
| 8 | snapshot TICKER [--no-news] [--no-commit] |
| 9 | ``` |
| 10 | |
| 11 | One command. All markets. Automatic failover. |
| 12 | |
| 13 | ## Data Sources |
| 14 | |
| 15 | ### US Stocks |
| 16 | 1. **FMP** (primary) — quote, EV/EBITDA, FCF yield, growth rates, sector, beta, earnings |
| 17 | 2. **Finnhub** (fallback) — PE/PB/ROE, 52-week range (fills gaps FMP free tier lacks) |
| 18 | 3. **Longbridge** (backup) — 15min delayed, use only when FMP+Finnhub both fail |
| 19 | |
| 20 | ### A-Shares |
| 21 | 1. **Tencent qt.gtimg.cn** — real-time, free, no key |
| 22 | 2. **Sina hq.sinajs.cn** — fallback, needs Referer header |
| 23 | |
| 24 | ### HK Stocks |
| 25 | 1. **Tencent qt.gtimg.cn** — real-time, free, no key |
| 26 | 2. **Sina hq.sinajs.cn** — fallback |
| 27 | 3. **Longbridge** (backup) — 15min delayed |
| 28 | |
| 29 | ### Cryptocurrency |
| 30 | 1. **OKX** — real-time, 200+ pairs, no key |
| 31 | 2. **Hyperliquid** — 7×24 perp prices, 230+ coins, no key |
| 32 | 3. Binance blocked (HTTP 451) in this region — don't retry |
| 33 | |
| 34 | ### Commodities & Indices |
| 35 | 1. **Hyperliquid** — PAXG (gold), SPX (S&P 500 perp) |
| 36 | 2. **Finnhub futures** — CL=F (oil), SI=F (silver), NG=F (natgas), HG=F (copper) |
| 37 | |
| 38 | ### News |
| 39 | - **Marketaux** — entity-linked, sentiment-tagged |
| 40 | |
| 41 | ### Backup |
| 42 | - **Longbridge OpenAPI** — US/HK/China quotes, 15min delayed |
| 43 | - Keys: `LONGBRIDGE_APP_KEY`, `LONGBRIDGE_APP_SECRET` |
| 44 | - API base: `https://openapi.longbridge.cn` |
| 45 | |
| 46 | ## Verified Sources |
| 47 | |
| 48 | | Source | Markets | Latency | Key Required | |
| 49 | |--------|---------|---------|-------------| |
| 50 | | FMP | US | Real-time | ✅ Free | |
| 51 | | Finnhub | US | Real-time | ✅ Free | |
| 52 | | Tencent qt | China A/HK | Real-time | ❌ None | |
| 53 | | Sina | China A/HK | Real-time | ❌ None | |
| 54 | | OKX | Crypto | Real-time | ❌ None | |
| 55 | | Hyperliquid | Crypto+Commodities | Real-time | ❌ None | |
| 56 | | Marketaux | News | Real-time | ✅ Free | |
| 57 | | Longbridge | US/HK/China | 15min delay | ✅ Account | |
| 58 | |
| 59 | ## Lessons Learned (Battle Scars) |
| 60 | |
| 61 | ### Never Use These (in this network) |
| 62 | - **yfinance** — rate limited + SSL errors. Hermes docs explicitly warn against it |
| 63 | - **akshare / akshare-one** — both call eastmoney.com which is proxy-blocked |
| 64 | - **Google News RSS** — guaranteed timeout |
| 65 | - **Binance** — HTTP 451 (legal block) |
| 66 | |
| 67 | ### API Format Pitfalls |
| 68 | - **FMP v3 API is DEPRECATED** since Aug 2025. Use `/stable/` endpoints. The error message is misleading |
| 69 | - **FMP key from before Aug 2025 is invalid** — must re-register for new key |
| 70 | - **Tencent qt returns GBK encoding**, not UTF-8. Must `decode("gbk")` or pipe through `iconv -f GBK` |
| 71 | - **HK stock codes on Tencent need 5 digits**: `zfill(5)` not `lstrip("0")`. `00700` → `hk00700` not `hk700` |
| 72 | - **Sina requires `Referer: https://finance.sina.com.cn`** header, or returns empty |
| 73 | - **Hyperliquid allMids uses PAXG for gold**, not HOLD/XAUT0. SPX exists but is a meme coin ticker |
| 74 | - **lark-oapi SDK requires builder pattern**: `CreateMessageRequest.builder()...build()`, direct construction silently fails |
| 75 | |
| 76 | ### Network Constraints |
| 77 | - `eastmoney.com` — proxy blocked (blocks akshare, akshare-one) |
| 78 | - `api.binance.com` — HTTP 451 (legal) |
| 79 | - `news.google.com` — timeout |
| 80 | - `yfinance` — SSL + rate limit |
| 81 | - `open.longbridge.com` — blocked; use `openapi.longbridge.cn` instead |
| 82 | |
| 83 | ### Performance |
| 84 | - `max_turns: 60` → agent loops forever. Reduce to 10 (research needs 4-6) |
| 85 | - `max_tokens: unlimited` → output too long. Cap at 8192 |
| 86 | - Bot self-sent messages MUST be filtered by `sender_type in ("bot", "app")` or infinite echo loop |
| 87 | |
| 88 | ## CLI Commands |
| 89 | |
| 90 | ```bash |
| 91 | snapshot NVDA # Full: quote + fundamentals + earnings + news |
| 92 | snapshot NVDA --no-news # Skip news (faster) |
| 93 | snapshot 600519.SH # A-share |
| 94 | snapshot 00700.HK # HK stock |
| 95 | snapshot BTC # Crypto |
| 96 | snapshot GOLD # Commodity |
| 97 | ``` |
| 98 | |
| 99 | ## Output Format |
| 100 | |
| 101 | ```json |
| 102 | { |
| 103 | "ticker": "NVDA", "retrieved_at": "2026-04-29T10:00:00Z", |
| 104 | "source_apis": ["fmp", "finnhub"], |
| 105 | "data": { |
| 106 | "quote": {"price": 213.17, "change_pct": 2.3}, |
| 107 | "fundamentals": {"pe_ttm": 42.7, "market_cap": 5181096612529}, |
| 108 | "earnings_latest": {"revenue": 215938000000, "net_income": 120067000000} |
| 109 | } |
| 110 | } |
| 111 | ``` |