How Dhan Broker Auto-Execution Works with IndexpilotAI

Last updated: 30 June 2026 · 8 min read

"Auto-execution" sounds magical until you understand the plumbing. When an IndexpilotAI signal fires and an order shows up in your Dhan account two seconds later, a fairly specific chain of events has happened: signal generation, broker API authentication, risk pre-check, order placement, acknowledgement, position monitoring, and finally an exit. This article walks through that chain in detail so you know exactly what is happening on your behalf — and where the safety checks are.

The big picture

Dhan exposes a REST + WebSocket trading API. IndexpilotAI is built as an authorised client of that API. You authorise it once by pasting your Dhan client ID and access token (generated from the Dhan web console). After that, IndexpilotAI can place, modify and cancel orders only in your account, and only for the segments you've enabled (typically NSE F&O).

The whole flow takes 1–3 seconds on a healthy day:

  1. AI engine generates a signal (entry strike, side, qty, SL, target)
  2. Risk gate validates against your daily loss cap and exposure rules
  3. Order request is sent to Dhan over HTTPS
  4. Dhan returns an order ID
  5. WebSocket pushes order status: PENDING → TRADED
  6. Position monitor starts ticking every 1 second
  7. On SL/target/manual exit, a square-off order is placed the same way

Step 1: Connecting your Dhan account

You generate an access token inside the Dhan web app under "DhanHQ Trading APIs". The token is valid until the next trading day's pre-open, so IndexpilotAI prompts you to refresh it daily. The token is stored encrypted server-side; we never see your Dhan login password and there's no way to withdraw funds — the API doesn't expose that endpoint.

Best practice: enable Dhan's IP allowlist if available, and immediately revoke the token from Dhan's console if you ever stop using IndexpilotAI.

Step 2: Signal generation

The AI engine runs on a dedicated cluster that ingests NIFTY and BANKNIFTY option chain ticks, spot price, futures basis and OI changes. When a model crosses its confidence threshold, a signal object is created with: instrument symbol (e.g. NIFTY-JUL2026-23900-CE), lot quantity based on your configured capital, entry type (MARKET or LIMIT), hard stop-loss and target in rupees per lot. Nothing reaches Dhan yet.

Step 3: The risk gate

Before the order is sent, every signal passes through a pre-trade risk check:

If any check fails, the signal is logged and dropped silently — better a missed trade than a blown account. This is the single most important reason auto-execution beats manual trading: humans skip these checks under FOMO.

Step 4: Placing the order on Dhan

The validated order is converted into a Dhan API payload — exchange segment, security ID, transaction type, product type (INTRADAY for MIS, NRML for carry), order type, quantity, price. We send it over HTTPS to api.dhan.co. Typical round-trip from our Mumbai VPS is 40–80ms.

Dhan responds with either an order ID (success) or an error code. Common errors and how IndexpilotAI handles them:

Step 5: Live position monitoring

Once the order fills, the position monitor takes over. It runs on a server-side loop that ticks every 1 second (not every 1 minute — that's an important difference from cheaper signal apps). Each tick:

If a trigger fires, an exit order is queued in the same risk-gate → API path as the entry. The whole cycle from "SL hit on Dhan's tick" to "square-off order live on exchange" usually completes in under 2 seconds.

Step 6: Reconciliation and trade journal

End-of-day, IndexpilotAI pulls your Dhan order book and trade book, reconciles every fill against its own log, and writes a clean entry to your trade journal — strategy, entry, exit, P&L, max drawdown during the trade, time in trade. This is the data you'll need for CA / tax purposes.

Safety: what auto-execution will not do

Want to see it live? Connect your Dhan account inside IndexpilotAI and run paper-mode first — every signal will be logged but no real orders placed, so you can validate before going live. Create your free account →

Related reads

Educational content only. IndexpilotAI is not affiliated with Dhan Securities; Dhan API names and trademarks belong to their owners.