stock-api logo

stock-api

CommunityPopular
zhangxiangliang

查询 A 股、美股、港股与场内基金行情,并通过 Node.js、浏览器、CLI 或 MCP 快速接入。

Publisherzhangxiangliang
Repositorystock-api
LanguageTypeScript
Forks
211
Stars
1.9K
Available tools
5
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    stock-api exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 5 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    1.9K stars and 211 forks from the linked repository.

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。

shell
npm install stock-api

使用

typescript
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。

浏览器

引用

html
<script src="https://cdn.jsdelivr.net/npm/stock-api/dist/browser/stock-api.iife.min.js"></script>

使用

html
<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

shell
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 客户端:

json
{
  "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:

text
请阅读 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.eastmoneyA 股单只行情、批量行情、K 线、搜索、诊断

stocks.eastmoney.searchStocks 依赖的搜索接口对部分境外网络环境(例如海外服务器、CI 出口 IP)会返回反爬响应而失败,行情/K 线不受影响。直接依赖东方财富搜索的场景建议改用 stocks.auto,它会在东方财富搜索失败时自动回退到腾讯、新浪。

文档

文档内容
API 使用TypeScript API、自动兜底、诊断返回结构
CLI 使用命令、参数、输出、退出码
项目架构目录结构、provider 工厂、解析和错误模型
开发指南本地开发、测试、发布前检查、新增数据源
API 监控定时检查第三方数据源并更新状态徽章

免责声明

stock-api 使用第三方公开行情接口作为数据来源,不保证数据的准确性、完整性、实时性或持续可用性。本项目不提供投资建议,任何交易或投资决策都应由你自行判断。商业、高频或生产使用前,请自行确认第三方数据源的服务条款、授权范围和合规要求。

License

MIT

Installation

TypingMind
{
  "mcpServers": {
    "stock-api": {
      "command": "npx",
      "args": [
        "-y",
        "stock-api",
        "mcp"
      ]
    }
  }
}

Available Tools

  • get_stock

    Get one normalized stock quote by code.

  • get_stocks

    Get normalized stock quotes for multiple codes.

  • get_klines

    Get normalized K-line rows for charting.

  • search_stocks

    Search stock symbols by keyword.

  • inspect_stock

    Inspect quote availability and provider fallback details.

Use stock-api MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once stock-api is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add stock-api as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the stock-api MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "stock-api": {
      "command": "npx",
      "args": [
        "-y",
        "stock-api"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the stock-api MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the stock-api MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use stock-api to help me with this task?
stock-api
Sure. I read it.
Here is what I found using stock-api.

Frequently asked questions

What is the stock-api MCP server used for?

stock-api is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use stock-api MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use stock-api with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use stock-api MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With stock-api connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect stock-api MCP to TypingMind?

stock-api runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does stock-api MCP provide in TypingMind?

stock-api exposes 5 MCP tools that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use stock-api MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If stock-api requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇