DhanHQ TS TypeScript SDK for DhanHQ API v2
A production-grade TypeScript SDK and Node.js client for the DhanHQ trading API. Build algorithmic trading systems for Indian markets (NSE, BSE, MCX) with typed REST APIs, real-time WebSocket market data, options analytics, technical indicators, risk management, and MCP tools for AI trading agents.
bash
npm install @nemesis-oss/dhanhq-sdkFeatures
- Typed REST API — Every endpoint, parameter, and response fully typed from OpenAPI
- Real-Time WebSocket Market Data — LTP, OHLCV, 5-level depth, binary packet parsing
- Order Update Stream — Real-time order execution events over WebSocket
- Option Chain & Greeks — Black-Scholes pricing, Greeks, implied volatility, max pain, PCR
- Technical Analysis — SMA, EMA, RSI, MACD, Bollinger, ATR, ADX, Stochastic, Supertrend, VWAP, OBV, multi-timeframe bias
- Pre-Trade Risk Pipeline — Market hours, position limits, daily loss, concentration checks
- Composable Trading Skills — 11 built-in strategies (iron condor, straddle, covered call, etc.)
- MCP Server & Agent Tools — Expose the SDK as tools for LLMs and AI agents
Quick Example
ts
import { DhanClient } from "@nemesis-oss/dhanhq-sdk";
const client = new DhanClient({
token: process.env.DHAN_TOKEN!,
clientId: process.env.DHAN_CLIENT_ID!,
});
// Place an order
const order = await client.orders.place({
dhanClientId: "YOUR_CLIENT_ID",
transactionType: "BUY",
exchangeSegment: "NSE_FNO",
productType: "INTRADAY",
orderType: "MARKET",
validity: "DAY",
securityId: "12345",
quantity: 15,
correlationId: "entry-001",
});Next Steps
| Guide | Description |
|---|---|
| Installation & Setup | Configure the SDK and authenticate |
| Orders API | Place, modify, cancel orders |
| WebSocket Market Feed | Stream live market data |
| Option Chain & Greeks | Resolve option chains and compute Greeks |
| Technical Analysis | Indicators and multi-timeframe bias |
| MCP Server | AI trading agent integration |
| GitHub | Source code and issues |
| npm | Package registry |