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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tushare-stock

v0.1.5

Published

CLI to fetch China A-share stock basic info via Tushare and compute support/resistance.

Readme

CN A股命令行工具(Tushare)

一个简单的 Node.js 命令行工具,使用 Tushare Pro 完成:

  • 依据输入的代码解析为 ts_code(不进行名称解析)
  • 仅获取最新一根日线数据
  • 基于最新交易日的 高/低/收 计算经典枢轴点(Classic Pivot Points)的支撑/阻力位

安装

通过 npm 全局安装(推荐)

npm install -g tushare-stock

安装后即可直接使用 tushare-stocktushare-stock-mcp 命令。

本地开发

git clone https://github.com/xianyusPadding/tushare-stock.git
cd tushare-stock
npm link

先决条件

  • Node.js 18+
  • 有效的 Tushare Pro Token

如何获取 Tushare Token

  1. 访问 Tushare Pro 接口 Token
  2. 注册并登录账号
  3. 获取 Token 需要个人积分满 120 分
  4. 积分获取方式:
    • 分享接口文档到社交媒体(可获得积分)
    • 捐赠支持项目(可获得积分)
    • 其他方式详见 Tushare 积分获取指南

提示: 如果您是新用户,建议先完成分享任务来快速获得所需积分。

配置 Token

方式 1: 使用 init 命令(推荐)

安装后首次使用时,运行初始化命令:

tushare-stock init

该命令会交互式地引导您:

  1. 输入您的 Tushare Token
  2. 选择保存位置:
    • 全局配置(~/.tushare-stock.env,推荐)- 所有项目共用
    • 本地项目配置(当前目录 .env)- 仅当前项目使用

方式 2: 手动配置

设置环境变量

export TUSHARE_TOKEN=your_tushare_token_here

创建配置文件

在项目根目录创建 .env 文件:

TUSHARE_TOKEN=your_tushare_token_here

或创建全局配置文件 ~/.tushare-stock.env

TUSHARE_TOKEN=your_tushare_token_here

用法

命令行工具

  • 初始化配置:

    tushare-stock init
  • 查询单只股票:

    tushare-stock <代码或ts_code> [--json] [--no-color]
  • 查询多只股票(表格展示):

    tushare-stock table <代码或ts_code...> [--json] [--no-color]

示例

# 初始化配置(首次使用)
tushare-stock init

# 查询单只股票
tushare-stock 600519
tushare-stock 600519.SH

# 查询多只股票
tushare-stock table 600519 000001.SZ 688981

# JSON 格式输出
tushare-stock 600519 --json

# 禁用彩色输出
tushare-stock 600519 --no-color

输入格式

  • 代码:6 位数字(如 600519)。交易所后缀(SH/SZ/BJ)将依据常见前缀推断;若不确定,程序会通过日线接口探测。
  • ts_code:完整的 Tushare 代码,如 600519.SH000001.SZ

注意:根据要求仅使用 daily 接口,禁用名称解析(不调用 stock_basic)。

输出

  • 默认:人类可读文本,包含基本信息、最新日线 OHLC 与基于枢轴点的支撑/阻力位。
  • --json:输出完整 JSON 数据。
  • 默认启用彩色输出;使用 --no-color 或设置环境变量 NO_COLOR=1 以禁用。

说明

  • 支撑/阻力采用经典枢轴点(R1/S1、R2/S2、R3/S3),由最近交易日的 高/低/收 推导,通常用于参考下一交易日。
  • 全程仅使用 daily 接口,不拉取基础信息。

MCP 服务器

本工具同时提供一个 Model Context Protocol (MCP) 服务器,便于在 Claude Desktop、Cline 等客户端作为"工具"调用。

前置条件

  • Node.js 18+
  • 依赖安装:npm install(全局安装后无需手动安装依赖)
  • Tushare Token:
    • 推荐:运行 tushare-stock init 设置全局配置
    • 或设置 TUSHARE_TOKEN 环境变量
    • 或在项目根目录创建 .env~/.tushare-stock.env 文件

启动方式

  • 脚本方式npm run mcp
  • 可执行方式(通过 npm install -g tushare-stocknpm link 后):tushare-stock-mcp

提供的工具(tools)

stock

  • 入参:{ code: string, json?: boolean }
  • 出参:
    • 文本:单只股票最新日线与 P/R1/S1
    • JSON:完整对象 { ts_code, trade_date, open, high, low, close, vol, P, R1, S1 }

table

  • 入参:{ codes: string[], json?: boolean }
  • 出参:
    • 文本:多只股票的表格(TS_CODE, DATE, OPEN, HIGH, LOW, CLOSE, P, R1, S1)
    • JSON:数组形式的同结构对象

Claude Desktop 配置示例(macOS)

文件路径:~/Library/Application Support/Claude/claude_desktop_config.json

方式 1:使用全局安装的命令(推荐)

{
  "mcpServers": {
    "cn-stock": {
      "command": "tushare-stock-mcp",
      "args": [],
      "env": {
        "TUSHARE_TOKEN": "your_tushare_token_here"
      }
    }
  }
}

方式 2:使用 Node 启动本地仓库

{
  "mcpServers": {
    "cn-stock": {
      "command": "node",
      "args": ["/absolute/path/to/your/repo/src/mcp-server.mjs"],
      "env": {
        "TUSHARE_TOKEN": "your_tushare_token_here"
      }
    }
  }
}

Cline(VS Code 扩展)配置示例

使用全局命令

{
  "mcpServers": {
    "cn-stock": {
      "command": "tushare-stock-mcp",
      "args": [],
      "env": { "TUSHARE_TOKEN": "your_tushare_token_here" }
    }
  }
}

使用本地仓库

{
  "mcpServers": {
    "cn-stock": {
      "command": "node",
      "args": ["/absolute/path/to/your/repo/src/mcp-server.mjs"],
      "env": { "TUSHARE_TOKEN": "your_tushare_token_here" }
    }
  }
}

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request!

链接