$npx -y skills add MagicCube/agentara --skill stockQuery stock quotes for US stocks, Hong Kong stocks, and A-shares. Use when the user asks about a stock price, market quote, or stock performance — including phrases like "查一下 BABA", "BABA 现在多少", "阿里巴巴股价", "茅台今天", "港股 9988", "美股行情", or any mention of a specific stock ticker or com
| 1 | # Stock Quote Skill |
| 2 | |
| 3 | Fetch latest stock price, change, and anomaly detection for US stocks, HK stocks, and A-shares. |
| 4 | Uses **stooq.com** as data source — reliable, no auth, bypasses system proxy automatically. |
| 5 | Data is T+1 for all markets (previous trading day close). This is expected and normal. |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## Step 1 — Identify Stock & Market |
| 10 | |
| 11 | Parse the user's query: |
| 12 | |
| 13 | - **A-share**: 6-digit code (000001, 600519, 300750) or Chinese company name → market = `cn` |
| 14 | - **HK stock**: 4–5 digit code (9988, 00700, 9999) or `XXXX.HK` format → market = `hk` |
| 15 | - **US stock**: Latin ticker (BABA, AAPL, TSLA, NVDA) or `BABA.US` format → market = `us` |
| 16 | |
| 17 | For well-known companies, infer the market: |
| 18 | - 阿里巴巴 → BABA (US) + 09988 (HK) — user usually means one, ask if unclear |
| 19 | - 腾讯 → 00700 (HK) |
| 20 | - 茅台/贵州茅台 → 600519 (A-share) |
| 21 | - 宁德时代 → 300750 (A-share) |
| 22 | |
| 23 | For HK symbols, pass as-is (no zero-padding): `9988`, `700`. stooq handles it. |
| 24 | |
| 25 | --- |
| 26 | |
| 27 | ## Step 2 — Fetch Data |
| 28 | |
| 29 | Use the unified `fetch_stock.py` script. Market codes: `hk`, `cn`, `us`. |
| 30 | |
| 31 | ```bash |
| 32 | # HK stock |
| 33 | python3 /Users/henry/.agentara/.claude/skills/stock/fetch_stock.py hk 9988 |
| 34 | |
| 35 | # A-share |
| 36 | python3 /Users/henry/.agentara/.claude/skills/stock/fetch_stock.py cn 600519 |
| 37 | |
| 38 | # US stock |
| 39 | python3 /Users/henry/.agentara/.claude/skills/stock/fetch_stock.py us BABA |
| 40 | ``` |
| 41 | |
| 42 | Output is a JSON array of rows: `{date, open, close, high, low, vol, pct, chg}`. |
| 43 | If the output starts with `{"error":`, report the error to the user and stop. |
| 44 | |
| 45 | **Network notes:** stooq.com is called with `trust_env=False` (bypasses Clash/system proxy). |
| 46 | No external Python deps beyond `requests` (stdlib-equivalent, always available). |
| 47 | |
| 48 | **Stooq symbol format:** |
| 49 | - HK: `9988.hk` (no leading zeros) |
| 50 | - CN: `600519.cn` |
| 51 | - US: `baba.us` (lowercase) |
| 52 | |
| 53 | --- |
| 54 | |
| 55 | ## Step 3 — Analyze & Detect Anomalies |
| 56 | |
| 57 | From the JSON output (up to 21 rows): |
| 58 | |
| 59 | 1. **Latest row** = most recent trading day data |
| 60 | 2. **Latest price** = `close` of last row |
| 61 | 3. **Latest change%** = `pct` of last row |
| 62 | 4. **Avg volatility** = mean of `|pct|` of rows 2–21 (excluding last row) |
| 63 | 5. **Avg volume** = mean of `vol` of rows 2–6 (5-day avg, excluding last) |
| 64 | 6. **Latest volume** = `vol` of last row |
| 65 | |
| 66 | **Anomaly flags** (report any that apply): |
| 67 | - `|pct| > 5%` → 🚨 大幅波动 |
| 68 | - `|pct| > 2%` AND `|pct| > 2 × avg_volatility` → ⚠️ 异常波动(超出近期均值2倍) |
| 69 | - `latest_vol > 2 × avg_volume` → 📊 成交量异常放大(X倍) |
| 70 | - `latest_vol < 0.4 × avg_volume` → 🔇 成交量异常萎缩 |
| 71 | |
| 72 | If US stock `pct` is always near 0 except the last row, it's because the diff is computed on fetched data — use the last row's `pct` directly. |
| 73 | |
| 74 | --- |
| 75 | |
| 76 | ## Step 4 — Format Output |
| 77 | |
| 78 | Keep it brief and mobile-friendly. Use list format, no tables. |
| 79 | |
| 80 | **Color + emoji rules (Chinese convention: 红涨绿跌):** |
| 81 | - `pct > 0` → emoji 📈, wrap numbers in `<font color='red'>...</font>` |
| 82 | - `pct < 0` → emoji 📉, wrap numbers in `<font color='green'>...</font>` |
| 83 | - `pct == 0` → emoji ➡️, no color wrapper |
| 84 | |
| 85 | **Template (adapt to context):** |
| 86 | |
| 87 | ``` |
| 88 | **{公司名} · {市场} {代码}** |
| 89 | |
| 90 | - 最新价:<font color='red/green'>**{price} {货币}**</font> |
| 91 | - 涨跌:{emoji} <font color='red/green'>**{chg:+.2f} / {pct:+.2f}%**</font> |
| 92 | - 最新交易日:{date} |
| 93 | |
| 94 | {anomaly_section_if_any} |
| 95 | ``` |
| 96 | |
| 97 | **Anomaly section** (only if flags exist): |
| 98 | ``` |
| 99 | ⚠️ 异常提示 |
| 100 | - [flag 1] |
| 101 | - [flag 2] |
| 102 | 近5日均幅 **{avg_vol:.2f}%**,今日 <font color='red/green'>**{pct:.2f}%**</font> |
| 103 | ``` |
| 104 | |
| 105 | **If no anomaly:** omit the anomaly section entirely. Keep the whole response under 10 lines. |
| 106 | |
| 107 | --- |
| 108 | |
| 109 | ## Step 5 — Currency |
| 110 | |
| 111 | - A-share: ¥ (人民币) |
| 112 | - HK: HK$ (港元) |
| 113 | - US: $ (美元) |
| 114 | |
| 115 | --- |
| 116 | |
| 117 | ## Notes |
| 118 | |
| 119 | - US data lags by 1 trading day (Sina source) — this is expected, tell the user if they ask |
| 120 | - If AKShare is not installed: `pip3 install akshare -q` |
| 121 | - If the symbol is wrong or not found, tell the user and suggest the correct format |
| 122 | - For A-share names, you can infer the 6-digit code from common knowledge; if uncertain, say so |
| 123 | - Do NOT show raw JSON or DataFrame output to the user — always parse and format it |