🐦 magpie is a local daemon at
http://127.0.0.1:17891exposing a tiny HTTP API. This skill teaches you how to call it. The daemon must already be running — if/healthfails, tell the user tomagpie start.
Always check /health before issuing requests. If down:
bash
curl -s http://127.0.0.1:17891/api/v1/health
If non-200 / connection refused, tell user:
"magpie daemon 没启动,请运行
cd /Volumes/DevDisk/symbol/magpie && node dist/cli.js start(或如果已安装 npm 包,magpie start)。"
Base URL: http://127.0.0.1:17891
bash
# Single
curl -s "http://127.0.0.1:17891/api/v1/quote/600519"
# Batch
curl -s "http://127.0.0.1:17891/api/v1/quotes?codes=600519,000858,002594"
Response shape:
json
{
"ok": true,
"quote": {
"code": "600519", "name": "贵州茅台",
"price": 1344.09, "change": -10.46, "changePct": -0.77,
"open": 1354.5, "prevClose": 1354.55,
"high": 1358.6, "low": 1338,
"volume": 5696787, "turnover": 7653257144,
"source": "sina", "delaySec": 5
}
}
Stock code rules:
600519 not sh600519If user gave a stock name, you need to know the code. Try this order:
GET /watchlist to see if user already added it (matches by name substring)Common Chinese A-share stocks (verified):
Ambiguous abbreviations — always ask the user to clarify:
If in doubt, ask: "你指的是哪个股票?请给 6 位代码。"
Note: stock names from sina data source occasionally arrive with full/half-width spaces (e.g.
五 粮 液). magpie v0.0.3+ trims these in the server. If you ever see one, just trim before rendering.
bash
curl -s "http://127.0.0.1:17891/api/v1/flow/600519"
Units are CNY (元). Divide by 1e8 for 亿. Negative = 净流出,positive = 净流入.
Fields: mainNetIn (主力), superNetIn (超大单), bigNetIn (大单), midNetIn (中单), smallNetIn (小单).
Rendering rule (do not parrot negative numbers):
< 0 → 净流出 ¥{abs(v/1e8).toFixed(2)} 亿> 0 → 净流入 ¥{(v/1e8).toFixed(2)} 亿0 → 持平delaySec is usually 60s for flow (vs 5s for quote). If user is asking real-time, add a hint: " 资金流数据延迟~1min、以交所清算为准".
bash
curl -s "http://127.0.0.1:17891/api/v1/kline/600519?period=daily&days=30"
period ∈ daily|weekly|monthly. Default 30 rows. Rows have date, open, close, high, low, volume, turnover, changePct, change, turnoverRate.
bash
curl -s "http://127.0.0.1:17891/api/v1/lhb" # today
curl -s "http://127.0.0.1:17891/api/v1/lhb?date=2026-05-13" # specific date
Returns up to 50 rows. After 18:00 SH local is most reliable.
bash
# List
curl -s "http://127.0.0.1:17891/api/v1/watchlist"
# Add
curl -s -X POST -H "content-type: application/json" \
-d '{"code":"600519","name":"贵州茅台","group":"持仓","note":"长持"}' \
http://127.0.0.1:17891/api/v1/watchlist
# Remove
curl -s -X DELETE "http://127.0.0.1:17891/api/v1/watchlist/600519"
bash
# List
curl -s "http://127.0.0.1:17891/api/v1/alerts"
curl -s "http://127.0.0.1:17891/api/v1/alerts?code=600519"
# Add
curl -s -X POST -H "content-type: application/json" \
-d '{"code":"600519","type":"lte","threshold":1300,"note":"抄底位"}' \
http://127.0.0.1:17891/api/v1/alerts
# Disable
curl -s -X DELETE "http://127.0.0.1:17891/api/v1/alerts/1"
# History
curl -s "http://127.0.0.1:17891/api/v1/alerts/history?days=7"
Rule types:
typetriggertypical usegteprice ≥ thresholdtake-profit / breakout-watchlteprice ≤ thresholdstop-loss / buy-the-dipbreakoutprice ≥ threshold AND prevClose < threshold突破阻力breakdownprice ≤ threshold AND prevClose > threshold跌破支撑
Default cooldown: 30 min (same rule won't re-fire within 30min).
bash
curl -s "http://127.0.0.1:17891/api/v1/digest?type=morning"
curl -s "http://127.0.0.1:17891/api/v1/digest?type=evening" # includes fund flow
curl -s "http://127.0.0.1:17891/api/v1/digest?type=weekly" # 5-day change
Response has digest.markdown you can directly forward to the user.
GET /quote/<code>贵州茅台 600519: ¥1344.09 📉 -0.77% (今高 ¥1358.6 / 今低 ¥1338)delaySec > 30 add: " 数据延迟 Xs"GET /flow/<code>
Convert to 亿元 ( /1e8), highlight mainNetIn. Negative → say "净流出",不要写负号。
Default report: main + super 两项足够。
茅台 600519 主力净流出 ¥11.78 亿(超大单净流出 ¥11.55 亿)“详细” / “全部” 才担 mid/small: · 大单 -0.23 亿 · 中单 +11.78 亿 · 小单 -0.003 亿
Determine type:
lte (价格简单 ≤) or breakdown (需 prevClose > threshold)gte (价格简单 ≥) or breakout (需 prevClose < threshold)POST /alerts with {code, type, threshold, note}
Confirm template by type (don't free-style):
gte → ✓ 规则 #N 已添加:{name} ({code}) 涨到 ¥{th} ping 你lte → ✓ 规则 #N 已添加:{name} ({code}) 跌到 ¥{th} ping 你breakout → ✓ 规则 #N 已添加:{name} ({code}) 突破 ¥{th} ping 你breakdown → ✓ 规则 #N 已添加:{name} ({code}) 跌破 ¥{th} ping 你Distance hint (optional but nice): if current price differs from threshold by >5%, append (当前 ¥{p},距阈值 {+±X%})
GET /digest?type=evening (after 15:00) or morning (before 09:30)digest.markdown verbatim — already formatted nicelyGET /lhb (after 18:00 SH for stable data)/health)#phasemeaningwhat to tell userpre盘前 00:00-09:30“今日未开盘,显示是上一交易日收盘”morning上午 09:30-11:30“盘中,数据实时”lunch午休12 11:30-13:00“午间休市”afternoon下午 13:00-15:00“盘中,数据实时”post盘后 15:00-24:00“今日已收盘”closed节假日或周末“非交易日,上一交易日收盘数据”
Unknown phase value → fall back to " closed" handling.
¥ prefix and 2 decimals; percentages with sign and 2 decimalsErrorWhat to saynot_found in quote"代码 XXXXXX 找不到,是不是写错了?"/flow returns error"Eastmoney 接口抽风,等 1 分钟重试,或者用 /quote 看价格"connect refused"magpie 没启动,请 magpie start"empty lhb"今天龙虎榜数据还没出,通常 18:00 后才稳"Non-trading day健康响应里 phase: closed,告诉用户:"今天非交易日,行情是上一交易日收盘数据"
盯盘 / 自选股 / 查股 / 股价 / 资金流 / 主力 / 龙虎榜 / 涨跌 / 早盘 / 收盘 / 茅台 / 五粮液 / 比亚迪 / 招行 / 平安 / K线 / 突破 / 跌破 / 止损 / 止盈 / 设告警 / 提醒我 / 我的盘