DhanHQ API Guide: How to Use Dhanโ€™s Trading & Market Data APIs (Full Step-by-Step + FAQs)

  • Post category:Stock Market
  • Reading time:6 mins read
  • Post author:
  • Post last modified:July 9, 2026

How to Use DhanHQ API: Complete Guide to Trading, Market Data & Integration

If you want to automate trading, build your own strategy platform, connect Excel or Amibroker, or stream live market data โ€” DhanHQ APIs give you everything you need.

From order placement to live market WebSocket feeds, historical OHLC, and portfolio access, DhanHQ offers one of the most complete API stacks for Indian markets.

In this post, youโ€™ll learn:

  • What DhanHQ API includes

  • How to access API keys

  • How to place orders (with example)

  • How historical data works

  • Limits, charges & restrictions

  • How to check subscription status

  • Whether corporate action adjustments exist

  • Rate limits, order caps & Data API usage

  • How to connect Excel, MT, Amibroker

  • How to track instruments & LTP

  • Full FAQ section

๐Ÿ‘‰ Start Using DhanHQ API (Sign in to Generate Your Access Token)

What is DhanHQ API?

DhanHQ is Dhanโ€™s official trading & market data API suite designed for:

  • Algo traders

  • Professional traders

  • Fintech platforms

  • Data visualization tools

  • Quant developers

  • Excel/Google Sheets users

  • Amibroker, MetaTrader & TradingView bridge users

Dhan provides:

โœ” Trading APIs

Place, modify, cancel orders
Check positions, holdings, margins, orderbook, and trades.

โœ” Data APIs

  • Historical OHLC

  • Live market feed via WebSocket

  • Quotes, LTP, depth, and tick updates

โœ” Integration APIs

Connect external platforms to Dhan using REST & WebSocket endpoints.

Step-by-Step: How to Access DhanHQ API

Hereโ€™s the exact onboarding flow:

Step 1: Log in to your Dhan Account

Go to Dhan Web โ†’ Log in โ†’ Profile.

Step 2: Navigate to โ€œDhanHQ Trading APIsโ€

Inside profile settings, locate the API Access section.

Step 3: Generate Access Token

Click Generate Token โ†’ copy:

  • Access Token

  • Client ID

Step 4: Subscribe to Data API (Optional)

If you need live market feed or historical data at scale, enable DhanHQ Data API Subscription.

Step 5: Start integrating

Use REST endpoints or WebSocket to build:

  • Algos

  • Dashboards

  • Execution engines

  • Excel sheets

  • Amibroker/MT systems


๐Ÿ‘‰ Get Your DhanHQ Access Token Now

What You Can Do With DhanHQ API

1. Place Orders Programmatically

Supported order types:

  • Market / Limit

  • Stop-Loss / Stop-Loss-Market

  • Intraday, CNC, MTF

  • Futures & Options

  • Order Slicing (Large Orders)

Order Placement Example (API)

curl –request POST \
–url https://api.dhan.co/v2/orders \
–header ‘Content-Type: application/json’ \
–header ‘access-token: YOUR_ACCESS_TOKEN’ \
–data ‘{
“dhanClientId”:”1000000003″,
“transactionType”:”BUY”,
“exchangeSegment”:”NSE_EQ”,
“productType”:”INTRADAY”,
“orderType”:”MARKET”,
“validity”:”DAY”,
“securityId”:”1333″,
“quantity”:”5″,
“price”:”0″
}’

2. Modify or Cancel Orders

Dhan allows:

  • Modify order (up to 25 times per order)

  • Cancel order

  • Modify/cancel bulk via your script

This is ideal for scalping, HFT-style algos, and dynamic strategies.

3. Access Historical Data via API

Available Timeframes

  • 1 min

  • 5 min

  • 15 min

  • 30 min

  • 60 min

  • Daily OHLC

Data Range

  • Intraday minute data: last 5 trading days

  • Daily OHLC: extended date ranges

Corporate Action Adjustments?

Dhan has not explicitly confirmed whether OHLC is adjusted for splits/bonuses.
If adjusted data is needed โ†’ verify endpoint response.

4. Live Market Feed (WebSocket)

Track:

  • LTP

  • Depth

  • Tick updates

  • Quotes

  • OHLC

  • Multiple instruments at once

Example (Python SDK):

from dhanhq import DhanContext, MarketFeed

dhan = DhanContext(“CLIENT_ID”,“TOKEN”)
inst = [(MarketFeed.NSE, “1333”, MarketFeed.Ticker)]
feed = MarketFeed(dhan, inst, version=“v2”)
feed.run_forever()

You can track hundreds to thousands of instruments depending on your subscription.

5. Connect to Excel, MetaTrader, Amibroker

DhanHQ supports integration with:

  • Excel
    Pull real-time quotes & place orders via macro/API calls.

  • Amibroker
    Use a custom AFL bridge via REST/WebSocket.

  • MetaTrader (MT4/MT5)
    Use an EA/bridge plugin to route MT orders to DhanHQ.

Any app that supports HTTP or WebSocket can connect.

6. Check API Subscription & Usage

You can verify:

  • Data API subscription

  • Expiry

  • Access token validity

  • Usage limits

  • Rate limits

From DhanHQ dashboard > Developer/API section.

7. Supported Languages

DhanHQ can be used with:

  • Python (official SDK)

  • JavaScript / Node.js

  • Java

  • Go

  • C#

  • C++

  • Rust

  • Ruby

  • Any language that supports REST + WebSocket

 

8. Rate Limits (Important)

API Type
Per Sec
Per Min
Per Day
Order API
25
250
7,000
Data API
5
โ€”
100,000
Quotes API
1
โ€”
Unlimited
Non-Trading API
20
Unlimited
Unlimited

If your algo exceeds these, your requests may be throttled.

9. Order Placement Limit

Technically DhanHQ supports high throughput:

  • 25 order requests per second

  • 250 per minute

Your account balance, margins, and risk checks still apply.

10. Basket Orders?

There is no dedicated โ€œbasket orderโ€ API, but you can:

  • Script multi-order execution

  • Run parallel REST calls

  • Use order slicing for large trades

 

11. Statement Retrieval via API

At present, there is no direct endpoint for:

  • P&L statement PDF

  • Tax statement

  • Ledger PDF

But you can fetch portfolio, positions, fund limits via API.

DhanHQ Data API Subscription โ€” How It Works

  • Enable Data API via subscription panel

  • Access LTP, quotes, depth, OHLC, live feed

  • Use REST or WebSocket

  • Check usage in dashboard

  • Cancel anytime from subscription panel

 

Deactivation, Cancellation & Support

Deactivate F&O Segment

This is not done via API.
Go to Dhan App โ†’ Profile โ†’ Segments or contact support.

Cancel Data API Subscription

Go to Profile โ†’ Data Subscription โ†’ Cancel.

Token Validity

Dhan has not publicly disclosed maximum validity; token remains valid until expired or manually regenerated.

FAQs

1. Are APIs available for all exchanges?

Yes โ€” NSE & BSE equity, equity derivatives, and more depending on your segment activation.

2. How many instruments can I track?

Hundreds to thousands depending on subscription & WebSocket bandwidth.

3. Is live market data free?

Live feed requires Data API subscription.

4. Are corporate actions adjusted?

Not officially confirmed โ€” verify data points.

Conclusion โ€” Should You Use DhanHQ API?

If youโ€™re a trader, quant, developer, or fintech builder who needs:

  • High-speed execution

  • Reliable market data

  • Scalable WebSocket feeds

  • Strong Python SDK

  • Easy integration with Excel/Amibroker/MT

  • Modern rate limits & slicing orders

Then DhanHQ API is one of the best in India.

Itโ€™s fast, stable, well-documented, and ideal for both professional traders and developers.


๐Ÿ‘‰ Generate Your DhanHQ API Token & Start Building Today

If, you have liked the content please do share it with your friends or on social media, as sharing do bring the good karma. If you have any questions or feedback you can leave them in comment box below.

 

๐Ÿ”— Related Learning

 

 

Note: Please do your own research and make investment. Moneycontain will not be responsible for any of your losses at all. The point made is for educational purpose only and intended to give information. All investments are subject to risks, which should be considered prior to making any investments.

Leave a Reply