Installation
stock-sdk has zero runtime dependencies and works in both the browser and Node.js 18+, shipping both ESM and CJS builds.
Install the package
npm install stock-sdkyarn add stock-sdkpnpm add stock-sdkRequires Node.js >= 18.
stock-sdkhas no runtime dependencies, sonpm installpulls in no third-party packages.
Main entry import
Import the StockSDK class from the main entry to access every namespaced API:
import { StockSDK } from 'stock-sdk'
const sdk = new StockSDK()
const quotes = await sdk.quotes.cn(['sh600519'])CommonJS works too:
const { StockSDK } = require('stock-sdk')Import on demand (subpath)
Pure-computation capabilities are exported via subpaths. When you only need indicators, signals or symbol parsing, the request layer and all providers stay out of your bundle — friendly to tree-shaking:
// Technical-indicator functions
import { calcMA, calcMACD, calcBOLL, addIndicators } from 'stock-sdk/indicators'
// Signal detection (golden / death cross, overbought / oversold, etc.)
import { calcSignals } from 'stock-sdk/signals'
// Symbol parsing
import { normalizeSymbol } from 'stock-sdk/symbols'
import type { SymbolRef } from 'stock-sdk/symbols'Available subpath entries:
| Entry | Contents |
|---|---|
stock-sdk | Main library: StockSDK and every namespaced API |
stock-sdk/indicators | 14 technical-indicator functions + addIndicators |
stock-sdk/signals | Signal detection calcSignals |
stock-sdk/symbols | normalizeSymbol, SymbolRef and symbol types |
stock-sdk/screener | Screener and backtest engine |
stock-sdk/cache | Low-level API of the injectable cache layer |
stock-sdk/errors | Unified error type SdkError and error codes |
Each subpath is declared in
package.jsonexportswith the full import / require / types triple.
CLI
The main package ships a CLI — no extra install needed to fetch data from the terminal:
# Run once
npx stock-sdk quote sh600519
# Or install globally and use the stock-sdk command
npm install -g stock-sdk
stock-sdk kline 600519 --period dayThe CLI outputs JSON by default (pipe-friendly). See the CLI overview.
MCP
Start the built-in MCP server for AI tools like Cursor / Claude / Codex:
stock-sdk mcpThe MCP protocol is a hand-written minimal implementation (stdio + tools) that works out of the box. See MCP installation for per-client configuration.
CLI and MCP live behind separate entries. When you
import { StockSDK } from 'stock-sdk', not a single byte of their code enters your bundle, and the main package stays zero-dependency.
Next steps
- Quick Start: a 10-line namespaced demo.
- Symbols & Codes: how to write
stringandSymbolRef.