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.3.0

Published

Stock market data API for Node.js and TypeScript

Downloads

2,237

Readme

stock-api 是一个零运行时依赖的股票行情工具,提供 Node.js API 和 CLI。默认使用 stocks.auto 自动兜底数据源,也可以显式指定腾讯、新浪或东方财富。

特性

  • Node.js API + TypeScript 类型
  • CLI 查询股票行情和搜索股票
  • 默认自动兜底:tencent -> sina -> eastmoney
  • 指定数据源:stocks.tencent / stocks.sina / stocks.eastmoney
  • 支持 A 股、港股、美股代码格式
  • 零运行时依赖

安装

npm install stock-api

要求 Node.js >=18

快速使用

默认用 stocks.auto

import { stocks } from "stock-api";

const stock = await stocks.auto.getStock("SH510500");
const list = await stocks.auto.getStocks(["SH510500", "SZ000651"]);
const results = await stocks.auto.searchStocks("格力电器");

CommonJS:

const { stocks } = require("stock-api");

指定某个数据源时,把 auto 换成数据源名称:

const stock = await stocks.tencent.getStock("SH510500");
const list = await stocks.sina.getStocks(["SH510500", "SZ000651"]);
const results = await stocks.eastmoney.searchStocks("贵州茅台");

检查数据源状态:

const autoInspection = await stocks.auto.inspectStock("SH510500");
const sinaInspection = await stocks.sina.inspectStock("SH510500");

CLI

CLI 默认也是 auto 模式:

npx stock-api get-stock SH510500
npx stock-api get-stocks SH510500 SZ000651
npx stock-api search 格力电器

指定数据源:

npx stock-api get-stock SH510500 --source sina
npx stock-api search 贵州茅台 --source eastmoney

数据源

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

可用数据源:

const sources = stocks.getSources();
// ["tencent", "sina", "eastmoney"]

股票代码

统一使用 交易所 + 股票代码

| 市场 | 前缀 | 示例 | | --- | --- | --- | | 上海交易所 | SH | SH510500 | | 深圳交易所 | SZ | SZ000651 | | 香港市场 | HK | HK02020 | | 美国市场 | US | USDJI |

返回结构

type Stock = {
  code: string;
  name: string;
  percent: number;
  now: number;
  low: number;
  high: number;
  yesterday: number;
  source?: "base" | "tencent" | "sina" | "eastmoney";
};

source 用于标记实际返回数据的数据源。stocks.autoinspectStock 会带上 source;直接使用 stocks.tencent.getStockstocks.sina.getStockstocks.eastmoney.getStock 时不会自动兜底,返回结构保持该数据源的原始行为。

文档

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

浏览器使用

stock-api 面向 Node.js、后端服务、Serverless 函数和 CLI。不建议在浏览器前端直接请求第三方行情接口,因为数据源可能存在 CORS 限制和编码问题。

frontend -> your backend API -> stock-api -> market data source

License

MIT