npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

stock-api

v2.7.2

Published

Stock market data API for Node.js, browsers, and TypeScript

Readme

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 前缀,例如 SH510500SZ000651

浏览器

引用

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

数据源

内置腾讯、新浪、东方财富数据源,默认由 stocks.auto 自动处理。

| 数据源 | 用法 | 能力 | | --- | --- | --- | | 自动兜底 | stocks.auto | 单只行情、批量行情、K 线、搜索、诊断 | | 腾讯 | stocks.tencent | 单只行情、批量行情、K 线、搜索、诊断 | | 新浪 | stocks.sina | 单只行情、批量行情、K 线、搜索、诊断 | | 东方财富 | stocks.eastmoney | A 股单只行情、批量行情、K 线、搜索、诊断 |

文档

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

免责声明

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

License

MIT