TypeScript Client for Dhan API v2
dhan-ts
A comprehensive, fully-typed TypeScript/JavaScript library for Dhan's trading API. Build powerful trading applications with type-safe access to 15+ API modules and real-time WebSocket feeds.
Why dhan-ts?
Fully Typed
Complete TypeScript support with IntelliSense and compile-time type checking for all API endpoints
Real-time Feeds
WebSocket feeds for live market data, order updates, and market depth with automatic reconnection
Comprehensive
15+ API modules covering orders, portfolio, funds, market data, options, and more
Production Ready
Battle-tested with error handling, automatic reconnection, and comprehensive documentation
Quick Start
Installation
npm install dhan-tsREST API Usage
import { DhanHqClient, DhanEnv } from 'dhan-ts';
const client = new DhanHqClient({
accessToken: 'your-token',
clientId: 'your-client-id',
env: DhanEnv.PROD,
});
// Get fund limits
const funds = await client.funds.getFundLimit();
// Place an order
const order = await client.orders.placeOrder({
// order details...
});WebSocket Feed
import { DhanFeed, FeedRequestCode } from 'dhan-ts';
const feed = new DhanFeed(config);
const liveFeed = feed.liveFeed;
// Connect
await liveFeed.connect();
// Subscribe to instruments
liveFeed.subscribe(
[[1, "1333"]], // Reliance
FeedRequestCode.SUBSCRIBE_TICKER
);
// Listen for updates
liveFeed.on('data', (data) => {
console.log('Price:', data.lastTradedPrice);
});Market Data
// Get historical data
const data = await client.marketData
.getProcessedCandleData({
securityId: '1333',
exchangeSegment: 'NSE_EQ',
interval: TimeInterval.DAY_1,
daysAgo: 100,
});Complete API Coverage
Access every feature of Dhan's trading platform through a unified, type-safe interface
REST APIs (15 Modules)
Orders
Place, modify, cancel orders
Portfolio
Holdings & positions
Funds
Balance & margin
Market Data
Real-time & historical
Super Orders
Advanced order types
Forever Orders
GTT orders
Option Chain
Options & Greeks
Expired Options
Historical data
Authentication
Auth flows
E-DIS
Delivery instruction
Statements
Ledger & history
Traders Control
Kill switch
Scanner
Stock screening
15+
API Modules
6
WebSocket Feeds
100%
TypeScript Coverage
Ready to Start Trading?
Install dhan-ts today and build your next trading application with confidence