Dhan API + TradingView: Webhook Automation Setup (2026)

jayadev rana Avatar

As of July 2026, the quickest way to connect a TradingView strategy to your Dhan account is Dhan’s own native webhook order type — there is no third-party bridge and no separate bridge subscription. You generate a webhook URL inside the Dhan web platform, paste the matching JSON into your TradingView alert, and each alert fires a live order on Dhan. If you need deeper control — custom position sizing, multi-leg option logic, order-status tracking — you script against the DhanHQ v2 REST API and POST to https://api.dhan.co/v2/orders. This guide covers both paths, with Pine Script v6, a real alert payload, a sample API order, current rate limits, pricing, and the SEBI 2026 rules you must follow.

I’m Jayadev Rana, a TradingView-certified Pine Script developer. Over 8+ years I’ve coded 7,700+ strategies for traders in 14+ countries, and Dhan is one of the brokers I wire up most often for Indian clients — so this is the setup I actually use, not a paraphrase of the docs.

Two native ways to automate Dhan from TradingView

There are two genuinely native routes, and neither needs a paid middleman:

  • Dhan Webhooks (no-code): Dhan added Webhooks as an order type on its web platform. TradingView sends a JSON alert straight to a Dhan URL, and Dhan places the order. Best for most retail strategies.
  • DhanHQ v2 API (code): A full REST + WebSocket API. You run a small server that receives the alert, applies your logic, then calls Dhan’s order endpoint. Best when you need custom sizing, risk checks, or multi-leg baskets.

Dhan also shows up as an integrated broker inside TradingView’s “Connect with Broker” trade panel (tv.dhan.co) for manual click-trading from the chart, but that is semi-manual — it is not the same as unattended alert automation. The webhook and the API are what you want for hands-off trading. This is the same pattern I set up for other Indian brokers in my Fyers webhook guide and Angel One webhook guide.

Option A: Dhan’s native webhook (free, no code)

I recommend this route to most traders because Dhan’s webhook order type is free and there is no bridge software to babysit.

1) Generate the webhook and JSON in Dhan

Log into the Dhan web platform, open the Webhooks section, click Generate Webhook and pick a validity, then click Generate JSON for the order you want (equity intraday/delivery, options CE/PE, or futures). Dhan hands you a URL plus a JSON object. A representative payload looks like this:

{
  "secret": "YOUR_DHAN_WEBHOOK_SECRET",
  "alertType": "multi_leg_order",
  "transactionType": "B",
  "orderType": "MKT",
  "quantity": "1",
  "exchange": "NSE",
  "symbol": "RELIANCE",
  "instrument": "EQ",
  "productType": "I",
  "price": "0"
}

Always copy the exact JSON that Dhan’s “Generate JSON” screen produces — the secret and field values are issued by Dhan. One thing that trips people up, and tripped me the first time, is that the secret is tied to the exact webhook URL. Regenerate the URL and every old alert silently stops working until you paste the new JSON back in. Treat the URL and secret as a matched pair.

2) Paste it into a TradingView alert

Create a TradingView alert, tick Webhook URL under Notifications, paste the Dhan URL, and put only the JSON (nothing else) in the Message box. I almost always fire on “Once Per Bar Close” so an intrabar repaint doesn’t double-fire an order — I explain that trade-off in my note on Pine Script alert frequencies.

The Pine Script v6 side

If you drive the webhook from a strategy, embed the Dhan JSON in alert_message and fire one alert on “Order fills and alert() function calls”. Here is a minimal Pine Script v6 EMA-cross example:

//@version=6
strategy("Dhan Webhook Bot", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1)

fastLen = input.int(9, "Fast EMA")
slowLen = input.int(21, "Slow EMA")

fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)

buyMsg  = '{"secret":"YOUR_SECRET","alertType":"multi_leg_order","transactionType":"B","orderType":"MKT","quantity":"1","exchange":"NSE","symbol":"RELIANCE","instrument":"EQ","productType":"I","price":"0"}'
sellMsg = '{"secret":"YOUR_SECRET","alertType":"multi_leg_order","transactionType":"S","orderType":"MKT","quantity":"1","exchange":"NSE","symbol":"RELIANCE","instrument":"EQ","productType":"I","price":"0"}'

if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, alert_message = buyMsg)

if ta.crossunder(fast, slow)
    strategy.close("Long", alert_message = sellMsg)

Paper-trade this before going live. Match quantity and symbol in the JSON to what your Pine logic assumes — TradingView does not reconcile your strategy’s position with Dhan’s, so a single missed alert can desync the two. For anything past a simple cross, I move the logic into a proper strategy development build with explicit state handling.

Want this wired up cleanly for your account, including the VPS and static IP? Message me on WhatsApp: +91 77352 68199.

Option B: Full control with the DhanHQ v2 API

When a client needs custom position sizing, order tracking, or multi-leg option baskets, I skip the no-code webhook and script against the API. You authenticate with an access token (a JWT) generated from the Dhan web portal; under the 2026 rules it is valid for 24 hours before you re-authenticate. Placing an order is a single POST:

curl --request POST \
  --url https://api.dhan.co/v2/orders \
  --header 'Content-Type: application/json' \
  --header 'access-token: YOUR_JWT_ACCESS_TOKEN' \
  --data '{
    "dhanClientId": "1000000003",
    "correlationId": "tv-ema-001",
    "transactionType": "BUY",
    "exchangeSegment": "NSE_EQ",
    "productType": "INTRADAY",
    "orderType": "MARKET",
    "validity": "DAY",
    "securityId": "11536",
    "quantity": 1,
    "price": 0
  }'

Dhan replies with an orderId and orderStatus (TRANSIT, PENDING, TRADED, REJECTED and so on). Watch securityId: Dhan uses numeric security IDs from its instrument master (11536 is TCS on NSE), not the ticker, so you map each symbol to its ID before going live. The overall flow mirrors other brokers — if you’ve read my Zerodha Kite Connect pricing and rate limits breakdown, this will feel familiar.

Auth, static IP and rate limits

Order placement, modification and cancellation require static IP whitelisting — you register one or two static IPs (I use a cloud VPS) in Dhan’s developer console. Current DhanHQ v2 rate limits:

API type Rate limit
Order APIs 10 requests / sec
Data APIs 5 requests / sec
Quote APIs 1 request / sec
Non-Trading APIs 20 requests / sec

Is the Dhan API free? Pricing in 2026

Dhan’s Trading API is free, and the native webhook order type is free too. The Data API (live WebSocket feed, quotes, historical and intraday data) is free if you’ve executed 25 or more trades in the last 30 days; otherwise it costs ₹499 plus applicable taxes per month, renewing every 30 days. For pure order automation off TradingView alerts you often do not need the paid Data API at all, since your signals already come from TradingView.

SEBI’s 2026 algo rules — what actually changes

From 1 April 2026, SEBI’s retail algo framework applies to API-based automation. Two practical points matter most: every automated order must carry an exchange-issued Algo-ID so it can be traced back to its source, and your API access must be locked to a whitelisted static IP. Dhan handles Algo-ID tagging at its end — you can even see an algoId field in the order response — and it already enforces static-IP whitelisting on order APIs, so the broker is aligned with the rules. Self-developed strategies that cross the exchange’s order-frequency threshold must additionally be registered through your broker. I covered the developer side of this in my guide on building SEBI-compliant algos. None of it blocks retail automation; it just means you route through a registered broker’s API (Dhan qualifies) and keep your IP and tagging in order.

My setup checklist

  • Paper or replay test the Pine strategy before any live alert.
  • Match JSON symbol, quantity and productType to your Pine logic.
  • Use “Once Per Bar Close” alerts to avoid double fires from repaint.
  • Host the API bot on a static-IP VPS whitelisted with Dhan.
  • Log every orderId and orderStatus so a rejected order never goes unnoticed.

FAQ

Does Dhan have a native TradingView integration?

Yes. Dhan offers a free native webhook order type that receives TradingView JSON alerts directly, and Dhan is also an integrated broker inside TradingView’s Connect-with-Broker panel for manual chart trading. Neither needs a paid third-party bridge.

Is the Dhan API free for algo trading?

The Trading API and the webhook order type are free. The Data API is free after 25 trades in 30 days, otherwise ₹499 plus taxes per month.

Do I need coding to connect Dhan to TradingView?

No. The webhook route is no-code: generate a URL and JSON in Dhan, then paste the JSON into a TradingView alert. You only need code (the DhanHQ v2 API) for custom sizing or multi-leg logic.

What are the DhanHQ API rate limits?

Order APIs allow 10 requests per second, Data APIs 5 per second, Quote APIs 1 per second and Non-Trading APIs 20 per second, alongside a daily cap on total requests.

Is a static IP mandatory for the Dhan API in 2026?

Yes, for order placement, modification and cancellation under SEBI’s 2026 rules. Register one or two static IPs (a VPS works) in Dhan’s developer console.

Want a done-for-you Dhan + TradingView bot — Pine Script, webhook JSON, VPS and static-IP setup, fully SEBI-aware? Reach me on WhatsApp: +91 77352 68199, or explore my Pine Script development services.

Risk disclaimer: Trading and algorithmic automation carry a substantial risk of loss and are not suitable for every investor. Nothing here is investment advice or a promise of profit. Automated orders can fail, misfire or slip during fast markets or outages. Test every strategy on paper first, use only capital you can afford to lose, and comply with SEBI and your broker’s terms. Past performance does not guarantee future results.

Leave a Reply

Your email address will not be published. Required fields are marked *