stock-api
Get normalized stock market data by running the stock-api CLI. It covers
China A-shares, Hong Kong, and US markets, with automatic provider fallback
across Tencent, Sina, and Eastmoney.
When to use
- The user wants a current price or quote for one or more stocks.
- The user wants K-line / candlestick history for charting or analysis.
- The user knows a company name but not its code (search first, then quote).
How to run
Use npx stock-api <command>. Every command prints JSON to stdout.
Stock codes use a market prefix: SH / SZ (China), HK (Hong Kong),
US (US). Examples: SH510500, SZ000651, HK02020, USDJI.
Get one quote
npx stock-api get-stock SH510500
Get several quotes at once
npx stock-api get-stocks SH510500 SZ000651
Get K-line (candlestick) history
npx stock-api get-klines SH600519 --period week --count 20
--period—day(default),week, ormonth.--count— number of rows (defaults to the provider default).--adjust—none(default),qfq(forward), orhfq(backward).
Search a code by keyword
npx stock-api search-stocks 格力电器
Options (all commands)
--source—auto(default),tencent,sina, oreastmoney. Leave it onautounless the user asks for a specific provider;autofalls back across providers if one fails.
Notes
- Output is JSON — parse it, don't reformat by hand, before showing the user.
- If a code returns no data, try
search-stocksto confirm the correct code. - For programmatic/persistent use, this same engine is also available as an
MCP server:
npx stock-api mcp. Prefer the CLI commands above for one-off lookups.