@SusChan444: Guys, no more backend needed for stock data! chengzuopeng/stock-sdk — pure JS/TS stock market SDK, zero Python, zero backend, get real-time data directly from browser/Node.js! Highlights: · Supports A-shares, Hong Kong stocks, US stocks, mutual funds, real-time quotes…

X AI KOLs Timeline Tools

Summary

Stock-SDK is a pure JavaScript/TypeScript stock market data SDK that supports browser and Node.js to get real-time data for A-shares/H-shares/US stocks/mutual funds, provides CLI and MCP to connect AI tools, designed for frontend and quantitative development.

Guys, no more backend needed for stock data! chengzuopeng/stock-sdk — pure JS/TS stock market SDK, zero Python, zero backend, get real-time data directly from browser/Node.js! The highlights: · Supports A-shares, Hong Kong stocks, US stocks, mutual funds, real-time quotes + K-line + technical indicators all included · Namespace API is super friendly with IDE autocomplete · Comes with CLI and MCP, one command to integrate with AI tools · Lightweight, zero dependencies, perfect TypeScript support Want to build a stock dashboard, quantitative demo, or AI stock picking? Just npm i stock-sdk and you're good to go! Direct link: https://github.com/chengzuopeng/stock-sdk… Official docs: https://stock-sdk.linkdiary.cn Quants and frontend devs, go for it – this open source benefit is really useful! #StockSDK #StockAPI #FrontendQuant #JSStockData
Original Article
View Cached Full Text

Cached at: 07/03/26, 02:38 PM

Guys, stock data no longer needs a backend! chengzuopeng/stock-sdk —— Pure JS/TS stock market SDK, zero Python, zero backend, get real-time data directly from browser/Node.js!
Key highlights:

  • Supports A-shares, H-shares, US stocks, public mutual funds – real-time quotes, K-line, technical indicators all included
  • Namespaced API is super friendly, with IDE autocomplete
  • Built-in CLI and MCP – one command to connect to AI tools
  • Lightweight, zero dependencies, perfect TypeScript support
    Want to build a market dashboard, quant demo, or AI stock picker? Just npm i stock-sdk and start!
    Direct link: https://github.com/chengzuopeng/stock-sdk
    Official docs: https://stock-sdk.linkdiary.cn
    Quant and frontend developers, go for it – this open source benefit is really practical~
    #StockSDK #StockAPI #FrontendQuant #JSStockData

chengzuopeng/stock-sdk

Source: https://github.com/chengzuopeng/stock-sdk

Stock SDK

npm version | npm downloads | license | MCP | AI Ready

English | 中文

A JavaScript SDK for stock market quotes designed for frontend and Node.js.

No Python, no backend service required – get real-time quotes and K-line data for A-shares / H-shares / US stocks / public mutual funds directly in browser or Node.js. Also comes with a command-line tool and MCP server – one command to fetch quotes or integrate with AI.

✨ Zero dependency, lightweight package | 🌐 Browser + Node.js | 📦 ESM + CJS + subpath | 🧠 Full TypeScript types | 🖥️ CLI | 🤖 MCP

v2.0.0: v2 is an architectural leap (namespaced API, unified symbol model, Quote discriminated union, unified error system, CLI/MCP/subpath exports).
Installation: npm i stock-sdk. To upgrade from v1, first read the v1 → v2 migration guide (breaking changes, no compatibility aliases).

📖 Official Documentation

👉 https://stock-sdk.linkdiary.cn

Complete API, namespace overview, CLI/MCP guides, online Playground, v1 → v2 migration docs are all here. Check the site first before diving in.

(v1 stable docs v1.stock-sdk.linkdiary.cn are archived)

📦 NPM | 📖 GitHub | 🎮 Online Playground

🧭 Stock Dashboard: A stock data dashboard demo site built on stock-sdk – welcome to try it.

Why stock-sdk?

If you’re a frontend engineer, you may have encountered these problems:

  • Most stock market tools are Python-based, making them hard to use directly in frontend
  • You want to build a market dashboard/demo but don’t want to maintain an extra backend service
  • Financial API response formats are messy and encoding is complex (GBK/concurrency/batch)

The goal of stock-sdk is simple:

Let frontend engineers elegantly fetch stock market data using the JavaScript/TypeScript they know best.


Use Cases

  • 📊 Stock market dashboard (Web/Admin)
  • 📈 Data visualization (ECharts/TradingView)
  • 🎓 Stock/finance course demos
  • 🧪 Quant strategy prototyping (JS/Node)
  • 🕒 Scheduled stock data fetching with Node.js
  • 🖥️ Quick quote lookup via CLI / 🤖 Feed data source to AI tools

Features

  • Zero dependencies, runs on both browser and Node.js 18+; provides ESM and CommonJS
  • Namespaced API: sdk.quotes.cn() / sdk.kline.cn() / sdk.options.etf.dailyKline(), grouped by domain, IDE autocomplete friendly
  • Unified symbol model: string as first-class citizen – tolerant parsing of sh600519, 600519, 600519.SH, 00700, hk00700, AAPL, 105.AAPL etc.; supports special indices like CSI (930955, H30533, HSHCI, GDAXI – see Symbol Guide)
  • A-shares / H-shares / US stocks / public mutual funds real-time quotes, historical K-line (daily/weekly/monthly), minute K-line (1/5/15/30/60), intraday time-sharing
  • Technical indicators: MA, MACD, BOLL, KDJ, RSI, WR, BIAS, CCI, ATR, OBV, ROC, DMI, SAR, KC
  • Signals / Screener / Backtest: calcSignals (golden cross/death cross/overbought/oversold event recognition), chainable screener, local backtest
  • Futures / Options / Capital flow / Dragon & Tiger list / Northbound / Block trades / Margin trading / Limit-up board – full extended data
  • Mutual fund deep data: historical NAV, real-time estimate, peer ranking trend, fund/ETF dividends, theme funds
  • Subpath exports: stock-sdk/{indicators,signals,symbols,screener,cache,errors} – pure computation without network layer, tree-shake friendly
  • Unified error system: only throws SdkError with a standard code, importable from stock-sdk/errors
  • Request governance: provider-level retry/rate-limit/circuit-breaker + injectable fetchImpl/signal/lifecycle hooks
  • CLI: stock-sdk quote 600519 – fetch quotes directly from terminal
  • Built-in MCP server: stock-sdk mcp – one line to integrate with Cursor/Claude/Codex and other AI tools (zero-dependency hand-written, no @modelcontextprotocol/sdk)

Installation

# Latest version (v2: namespaced API / CLI / MCP)  
npm install stock-sdk  

# v1 legacy (archived, critical fixes only)  
npm install stock-sdk@legacy  

Quick Start

import { StockSDK } from 'stock-sdk';  

const sdk = new StockSDK();  

// Namespaced API (v2) – symbol format tolerant, '600519' / 'sh600519' / '600519.SH' all work  
const quotes = await sdk.quotes.cnSimple(['sh000001', 'sz000858', 'sh600519']);  
quotes.forEach((q) => {  
  console.log(`${q.name}: ${q.price} (${q.changePercent}%)`);  
});  

// Historical K-line + technical indicators  
const kline = await sdk.kline.withIndicators('600519', {  
  period: 'daily',  
  indicators: {  
    ma: { periods: [5, 10, 20] },  
    macd: {},  
  },  
});  

// All A-share quotes (5000+ stocks, built-in concurrency control)  
const all = await sdk.batch.cn({ concurrency: 5 });  
console.log(`Total ${all.length} stocks`);  

H-shares '00700' / 'hk00700', US stocks 'AAPL' / '105.AAPL' – all handled by normalizeSymbol with unified tolerant parsing.


CLI

After installation, the stock-sdk command is available (or use npx):

# Quote (auto-detect market by code)  
npx stock-sdk quote 600519 00700 AAPL  

# K-line + truncated output  
npx stock-sdk kline 600519 --period weekly --limit 30  

# With technical indicators  
npx stock-sdk indicators 600519 --ma 5,10,20 --macd  

# Search  
npx stock-sdk search 茅台  

# Directly call any namespace method  
npx stock-sdk quotes cn sh600519 sz000001  

Default JSON output, add --format table|csv, --pretty, --limit N.


🤖 AI / MCP Integration

v2 includes a built-in zero-dependency MCP server – start with one command:

npx stock-sdk mcp  

Connect to Cursor / Claude Desktop / Codex / Gemini etc. (configure mcpServers):

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

Environment variable STOCK_SDK_MCP_TOOLS=core|full|<comma-separated tool names> controls the tool set (default core).

👉 Full MCP Documentation


Signals / Screener / Backtest

import { calcSignals } from 'stock-sdk/signals';  
import { screen, backtest } from 'stock-sdk/screener';  

// Event recognition (golden cross/death cross/overbought/oversold) based on K-line with indicators  
const signals = calcSignals(klineWithIndicators, {  
  ma: { fast: 5, slow: 20 },  
  rsi: {},  
});  

// Chainable screener (input any quote array, local only, no network)  
const picks = screen(allQuotes)  
  .where((q) => q.pe != null && q.pe < 20)  
  .where((q) => q.changePercent > 3)  
  .sortBy((q) => q.amount)  
  .top(20);  

// Local backtest  
const report = backtest({  
  klines,  
  strategy: (bar, i, all) => 'hold', // returns 'buy' | 'sell' | 'hold'  
});  
console.log(report.totalReturn, report.winRate, report.maxDrawdown);  

Request Governance & Errors

import { StockSDK } from 'stock-sdk';  
import { HttpError, getSdkErrorCode } from 'stock-sdk/errors';  

const sdk = new StockSDK({  
  retry: { maxRetries: 2, baseDelay: 500 },  
  providerPolicies: {  
    eastmoney: { timeout: 12000, rateLimit: { requestsPerSecond: 3, maxBurst: 3 } },  
  },  
});  

try {  
  await sdk.quotes.cnSimple(['sh600519']);  
} catch (error) {  
  // v2 only throws SdkError with unified code  
  if (error instanceof HttpError) console.log(error.status, error.statusText);  
  console.log(getSdkErrorCode(error)); // HTTP_ERROR / NETWORK_ERROR / TIMEOUT / ABORTED / PARSE_ERROR ...  
}  

Subpath Exports

When using only pure calculations (indicators/symbols/signals/screener), import from subpaths to avoid pulling in RequestClient and all providers:

// 14 indicators, 17 pure functions (MA family includes calcSMA, calcEMA, calcWMA):  
// calcSMA / calcEMA / calcWMA / calcMA / calcMACD / calcBOLL / calcKDJ /  
// calcRSI / calcWR / calcBIAS / calcCCI / calcATR / calcOBV / calcROC /  
// calcDMI / calcSAR / calcKC  
import { calcMACD, calcKDJ } from 'stock-sdk/indicators';  
import { normalizeSymbol, toTencentSymbol } from 'stock-sdk/symbols';  
import { calcSignals } from 'stock-sdk/signals';  
import { screen, backtest } from 'stock-sdk/screener';  
import { MemoryCacheStore, cacheThrough } from 'stock-sdk/cache';  
import { SdkError, isSdkError, getSdkErrorCode } from 'stock-sdk/errors';  

Market Support Matrix

Different markets have varying levels of coverage. The table below helps you quickly determine if the SDK covers your scenario.

  • ✅ Supported | ⚠️ Partial (see notes) | ❌ Not implemented | — Not applicable
FeatureA-sharesH-sharesUS StocksPublic Mutual FundsFuturesOptions
Real-time Quotes✅ Global Futures✅ ETF / CFFEX / Commodity
Historical K-line (D/W/M)⚠️ Listed ETFs/LOFs✅ Domestic + Global
Minute K-line (5/15/30/60)kline.hkMinutekline.usMinute⚠️ Listed ETFs/LOFs
Intraday Timeline (1 min)quotes.timelinekline.hkMinute(period=‘1’)kline.usMinute(period=‘1’)⚠️ Listed ETFs/LOFs✅ ETF Options
Dividends✅ Fund + ETF
Capital Flow✅ Individual/Market/Rank/Sector
Sector (Industry/Concept)
Dragon & Tiger List✅ Options Dragon & Tiger
Shanghai-Shenzhen-HK Connect / Northbound✅ Northbound✅ Southbound
Block Trade / Margin
Limit-up Board / Tape Anomalies
Full Market Code List / Batch Quotes✅ 5000+✅ Codes
Inventory Data✅ Domestic + COMEX
Trading Calendarcalendar.*⚠️ Market status only⚠️ Market status only

Data delay: Real-time quotes come from public sources like Tencent Finance / East Money – not real-time matching, usually tens of seconds to minutes delay. Not suitable for high-frequency trading decisions.


API Overview (Namespaces)

💡 Full API in Official Documentation. In v2, all methods are under namespaces:

NamespaceRepresentative Methods
sdk.quotes.cn, .cnSimple, .hk, .us, .fund, .fundFlow, .largeOrder, .timeline
sdk.codes.cn, .us, .hk, .fund
sdk.batch.cn, .hk, .us, .byCodes, .raw
sdk.kline.cn, .cnMinute, .hk, .hkMinute, .us, .usMinute, .withIndicators
sdk.board.industry.*, .concept.* (list, spot, constituents, kline, minuteKline)
sdk.options.index.*, .etf.*, .commodity.*, .cffex.*, .lhb
sdk.futures.kline, .globalSpot, .globalKline, .inventory, .comexInventory, …
sdk.fundFlow.individual, .market, .rank, .sectorRank, .sectorHistory
sdk.northbound.minute, .summary, .holdingRank, .history, .individual
sdk.marketEvent.ztPool, .stockChanges, .boardChanges
sdk.dragonTiger.detail, .stockStats, .institution, .branchRank, .seatDetail
sdk.blockTrade / sdk.marginBlock trade / Margin trading
sdk.fund.dividendList, .navHistory, .estimate, .rankHistory, .theme
sdk.calendar.isTradingDay, .nextTradingDay, .prevTradingDay, .marketStatus
sdk.reference.dividendDetail, .tradingCalendar
Top-levelsdk.search(keyword)

Indicator calculations moved to subpath: import { calcMACD } from 'stock-sdk/indicators'.
Migrating from v1 flat API? See v1 → v2 Migration Guide (includes full sdk.getXxx()sdk.<namespace>.<method>() mapping table).


Development Checks

pnpm typecheck  
pnpm build  
pnpm test  
pnpm test:integration:smoke   # Smoke integration (real network)  
pnpm test:integration:full    # Full integration regression  

License

ISC


🌐 Official Site | 📦 NPM | 📖 GitHub | 🎮 Online Demo | 🧭 Stock Dashboard | 🐛 Issues


If this project helps you, feel free to Star ⭐ or raise an Issue for feedback.

Similar Articles

@_zheergen: Guys! Found another all-in-one Python stock tool — InStock. The myhhub/stock repository covers A-share quantitative analysis quite comprehensively: data scraping, indicator calculation, stock selection, backtesting, and automated trading all in one. Let me highlight the core features: Real-time A-share data scraping + 30…

X AI KOLs Timeline

Introduces the open-source Python tool InStock (myhhub/stock) for A-share quantitative analysis, supporting data scraping, technical indicators, stock selection, backtesting, automated trading, etc., and can be deployed via Docker.

@geekbb: Open-source A-share quantitative workstation, using TickFlow data for three tasks: stock selection, real-time monitoring, and backtesting. Built-in 20 stock selection strategies (Polars vectorization runs all A-shares in seconds), supports no-code custom signals, AI strategy writing, multi-condition monitoring rules + Feishu push. https:…

X AI KOLs Timeline

Open-source A-share quantitative workstation, based on TickFlow data, implements three functions: stock selection, real-time monitoring, and backtesting. Built-in 20 Polars vectorized strategies, supports AI strategy writing and Feishu push.

@oragnes: The Codex App / CLI can now directly access stock prices, earnings reports, SEC filings, and financial news data. It utilizes the official Financial Datasets MCP Server. It's not just a plugin for "looking up stock prices," but rather connects financial data sources into AI Agents, allowing …

X AI KOLs Timeline

OpenAI's Codex App and CLI can now access financial data such as stock quotes, financial reports, and SEC filings directly through the Financial Datasets official MCP Server, supporting real-time market queries, financial report analysis, and company comparisons.

@Jolyne_AI: The most troublesome part of A-share data analysis is not writing strategies, but getting all the data first: market data, research reports, dragon and tiger list, northbound flows, capital flows, announcements, financial reports—each type has a different API and parameters often change. a-stock-data is an A-share full-stack data Skill for AI coding assistants, packaging 13 data sources…

X AI KOLs Timeline

a-stock-data is an A-share full-stack data Skill for AI coding assistants, packaging 13 data sources into directly callable tools, supporting multiple data layers such as market data, research reports, signals, and capital flows.