Skip to content

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-sdk

Features

  • 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

GuideDescription
Installation & SetupConfigure the SDK and authenticate
Orders APIPlace, modify, cancel orders
WebSocket Market FeedStream live market data
Option Chain & GreeksResolve option chains and compute Greeks
Technical AnalysisIndicators and multi-timeframe bias
MCP ServerAI trading agent integration
GitHubSource code and issues
npmPackage registry

Community project. This is an independent SDK and is not affiliated with, endorsed by, or supported by Dhan. Dhan publishes its own official clients as dhanhq and dhanhq-ts.

Community project — not affiliated with Dhan. MIT License.