Guide
BrokerMarket dataStocksOptionsFutures API key

Dhan (DhanHQ) API guide

Dhan built its platform with traders and developers in mind; DhanHQ v2 is a clean REST API with a separate data subscription.

Last verified · Also known as DhanHQ API, Dhan API, dhanhq

Quick answer

DhanHQ is Dhan’s API for Indian markets: order placement, super orders, forever orders, portfolio and funds are free, while Data APIs (live feed, market depth, historical candles) need a monthly plan. You authenticate with your client id and an access token generated on web.dhan.co, where you also choose how long it stays valid.

Dhan (DhanHQ) API at a glance

Pricing
Trading APIs free; Data APIs on a monthly plan
Availability
Indian residents with a Dhan account
Paper trading
DhanHQ sandbox for testing order flows
Integration type
REST + API key
In AlgoGP
Design and backtest in AlgoGP, connect the exported code
Auth
Client id + access token header
Trading APIs
Free
Data APIs
Monthly subscription
SDK
Python dhanhq

Build a Dhan (DhanHQ) strategy with AlgoGP

AlgoGP does not connect to Dhan (DhanHQ) natively yet. Dhan (DhanHQ) uses plain HTTPS with an API key, so it is a good candidate for a native adapter; it is not built in yet.

  1. 1

    Design and backtest in AlgoGP

    Describe the strategy to the copilot and backtest it on years of normalized history. The result does not depend on any vendor.

  2. 2

    Export the Python project

    Every project exports strategy.py, market_data.py, brokers.py and live.py. The strategy only sees bars, cash, positions and orders, never a vendor’s wire format.

  3. 3

    Plug in Dhan (DhanHQ)

    Implement the four adapter methods (account, positions, submit_market_order and a candle fetcher) with Dhan (DhanHQ)’s SDK, or keep a built-in platform for paper trading and add Dhan (DhanHQ) when you go live.

Built-in brokers for the same markets: Alpaca, Tradier, Interactive Brokers, OKX.

Dhan (DhanHQ) API: frequently asked questions

Is the Dhan API free?

Trading APIs are free; Data APIs require a paid plan.

How long does a Dhan access token last?

You choose the validity when generating it on web.dhan.co.

Design and backtest your Dhan (DhanHQ) strategy first

AlgoGP turns an idea into Python and tests it on years of history before you connect it to Dhan (DhanHQ). The exported code keeps the broker behind four small adapter methods.

  • AI copilot writes and revises the rules
  • Backtests with realistic costs
  • Exported Python ready to wire to Dhan (DhanHQ)

Free plan, no card required.

Dhan (DhanHQ) alternatives

Independent guide. AlgoGP is not affiliated with Dhan (DhanHQ). Limits, prices and availability change; confirm them in the official documentation. Nothing here is investment advice.

Build a strategy