
stock-api
CLIFetches US, Hong Kong and China A-share stock data with zero runtime dependencies: real-time quotes, daily, weekly and monthly candles and search as JSON, falling back across Tencent, Sina and Eastmoney sources. Also runs as an MCP server. Unofficial public APIs, no stability guarantee.
stock-api
支持 A 股、港股、美股行情查询的 TypeScript 股票数据工具。
stock-api 是一个零运行时依赖的股票行情工具,支持 Node.js、浏览器、CLI 和 MCP。默认使用 stocks.auto,自动从可用数据源获取行情。
支持使用方式
特性
- Node.js / Browser bundler API + TypeScript 类型
- CLI 查询股票行情、K 线和搜索股票
- MCP tools 给 AI 客户端直接调用股票接口
- 默认自动兜底:
tencent -> sina -> eastmoney - 指定数据源:
stocks.tencent/stocks.sina/stocks.eastmoney - 支持 A 股、港股、美股代码格式
- 零运行时依赖
Node.js
安装
Node.js 环境要求 >=18。
npm install stock-api
使用
import { stocks } from "stock-api";
const stock = await stocks.auto.getStock("SH510500");
const list = await stocks.auto.getStocks(["SH510500", "SZ000651"]);
const klines = await stocks.auto.getKlines("SH600519", { period: "day" });
const results = await stocks.auto.searchStocks("格力电器");
股票代码使用 SH / SZ / HK / US 前缀,例如 SH510500、SZ000651。
浏览器
引用
<script src="https://cdn.jsdelivr.net/npm/stock-api/dist/browser/stock-api.iife.min.js"></script>
使用
<script>
StockApi.stocks.auto.getStock("SH510500").then(console.log);
StockApi.stocks.auto.getStocks(["SH510500", "SZ000651"]).then(console.log);
StockApi.stocks.auto.getKlines("SH600519", { period: "day" }).then(console.log);
StockApi.stocks.auto.searchStocks("格力电器").then(console.log);
</script>
浏览器示例:GitHub Pages
CLI
npx stock-api get-stock SH510500
npx stock-api get-stocks SH510500 SZ000651
npx stock-api get-klines SH600519 --period day --count 120
npx stock-api search-stocks 格力电器
MCP
把 stock-api 接到支持 MCP 的 AI 客户端:
{
"mcpServers": {
"stock-api": {
"command": "npx",
"args": ["-y", "stock-api", "mcp"]
}
}
}
内置工具:get_stock、get_stocks、get_klines、search_stocks、inspect_stock。
支持的 MCP 协议版本:2025-11-25、2025-06-18。握手时会返回客户端请求的版本,不支持则回退到最新的一个。
AI Agent(任意工具)
不想配置 MCP?把下面这句话发给任意 AI 工具(Claude Code、Codex、GLM 等),它读完就知道怎么用 stock-api:
请阅读 https://raw.githubusercontent.com/zhangxiangliang/stock-api/main/SKILL.md
然后用 stock-api 回答我的股票问题。
SKILL.md 里写了具体的 npx stock-api 命令,所以和 MCP 共用同一套数据逻辑,只是接入方式更简单、跨工具通用。
数据源
内置腾讯、新浪、东方财富数据源,默认由 stocks.auto 自动处理。
| 数据源 | 用法 | 能力 |
|---|---|---|
| 自动兜底 | stocks.auto | 单只行情、批量行情、K 线、搜索、诊断 |
| 腾讯 | stocks.tencent | 单只行情、批量行情、K 线、搜索、诊断 |
| 新浪 | stocks.sina | 单只行情、批量行情、K 线、搜索、诊断 |
| 东方财富 | stocks.eastmoney | A 股单只行情、批量行情、K 线、搜索、诊断 |
stocks.eastmoney.searchStocks依赖的搜索接口对部分境外网络环境(例如海外服务器、CI 出口 IP)会返回反爬响应而失败,行情/K 线不受影响。直接依赖东方财富搜索的场景建议改用stocks.auto,它会在东方财富搜索失败时自动回退到腾讯、新浪。
文档
| 文档 | 内容 |
|---|---|
| API 使用 | TypeScript API、自动兜底、诊断返回结构 |
| CLI 使用 | 命令、参数、输出、退出码 |
| 项目架构 | 目录结构、provider 工厂、解析和错误模型 |
| 开发指南 | 本地开发、测试、发布前检查、新增数据源 |
| API 监控 | 定时检查第三方数据源并更新状态徽章 |
免责声明
stock-api 使用第三方公开行情接口作为数据来源,不保证数据的准确性、完整性、实时性或持续可用性。本项目不提供投资建议,任何交易或投资决策都应由你自行判断。商业、高频或生产使用前,请自行确认第三方数据源的服务条款、授权范围和合规要求。
License
MIT
関連リソース

OpenBB Platform CLI
CLICommand-line edition of the open-source OpenBB investment research platform: query stock prices, financial statements, macroeconomic and other financial data from the terminal, and automate data pulls with Routine scripts. Officially maintained; some sources need API keys.
OpenBB-finance/OpenBB74.3k
yahoo-finance2
CLIUnofficial Yahoo Finance data tool with a yahoo-finance CLI, an MCP server and an agent skill: stock quotes, price history, financials, option chains and analyst ratings. Needs Node.js 22+, no API key. The API is unofficial and may change; for research only.
gadicc/yahoo-finance2804
Finance Toolkit MCP
MCPFrom the FinanceToolkit author: computes ratios, valuation, risk and macro indicators with 500+ transparent formulas, for company comparisons and first-pass due diligence. Hosted, no install; enter a Financial Modeling Prep key on first connect (free tier: US stocks, 5 years). Verify results.
JerBouma/FinanceToolkit5.4k
Finance Skills
PluginPlugin marketplace for investment research: six plugin groups covering yfinance market data, earnings previews and recaps, DCF valuation, option payoff charts, ETF premiums, read-only news from X, Discord and other social sources, and TradingView data. Research only, not investment advice.
himself65/finance-skills3.4k
Financial Modeling Prep MCP Server
MCPGives agents 250+ Financial Modeling Prep endpoints: financials, valuation and technical indicators, insider and congressional trades, SEC filings and earnings calendars. Needs an FMP API key (free tier); connect to the author's hosted URL or run locally on Node.js 25.3+. Results need expert review.
imbenrabi/Financial-Modeling-Prep-MCP-Server150
EODHD Claude Skills
PluginEODHD's official plugin (remote MCP, 7 workflow skills, an analyst subagent): quotes, fundamentals and macro data from 70+ exchanges worldwide, company briefs, stock screening and portfolio risk analysis. Needs an EODHD account; free tier: 20 calls/day, basic US data only. Not investment advice.
EodHistoricalData/eodhd-claude-skills46