Written by Geet Ramchandani
Published 6 min read
To connect Dhan to TradeCraft, you add the static IP that TradeCraft gives you to your Dhan account, switch on TOTP in Dhan's API settings, and paste your Client ID, Dhan PIN and TOTP secret into TradeCraft. It takes about 10 minutes, once. After that you never have to log in to Dhan for TradeCraft again: your access renews itself.
Before you start
- A Dhan account, and the PIN you log in to Dhan with.
- A laptop or desktop, logged in to web.dhan.co.
- One sitting of about 10 minutes. TradeCraft holds your IP address for 90 minutes while you finish.
- No payment. Dhan's Trading APIs are free. You do not need the paid Data APIs.
You will move between two browser tabs, TradeCraft and Dhan Web. Keep both open.
Step 1: Get your static IP from TradeCraft
- Log in to TradeCraft and open Brokers in the sidebar.
- Under Link a Broker Account, find Dhan and click Connect.
- The Register your trading IP window opens with an address. Click the copy button next to it.

Step 2: Add the static IP on Dhan
- On web.dhan.co, click your Profile.
- Select Get Trading & Data APIs. On some accounts this is labelled DhanHQ Trading APIs.
- Scroll down and click Add IP.
- Paste the IP from Step 1 as your primary IP and save. Leave the secondary IP empty.


Step 3: Note your Client ID
Your Client ID is shown on your Dhan Profile page, under your name. Copy it. You paste it into TradeCraft in Step 5.

Step 4: Set up TOTP and copy the secret
Stay on the Get Trading & Data APIs page.
- Click Setup TOTP.
- If prompted, confirm with the OTP Dhan sends to your mobile or email.
- Dhan shows a QR code and a text code next to it.
- Copy the text code. This is your TOTP secret for TradeCraft.


Step 5: Connect in TradeCraft
- Go back to the TradeCraft tab. In the Register your trading IP window, click I've registered it.
- The Connect Dhan window opens. Fill in:
| Field in TradeCraft | What to paste |
|---|---|
| Client ID | Your Dhan Client ID from Step 3 |
| PIN | The PIN you log in to Dhan with |
| TOTP Secret | The text code from Step 4 |
- Click Connect. You'll see Dhan connected. Its access renews itself — no daily login.


Dhan does not share your name with TradeCraft, so the account is listed by Client ID. Click the pencil next to it to give it a name, such as Dhan — main.
After you connect
There is nothing to do each day. Dhan sessions last 24 hours, and TradeCraft renews yours on its own. If the account ever shows Session expired, click Reconnect. It renews without asking you for anything.
If you reset TOTP or change your PIN in Dhan, TradeCraft's copy stops working. When the account next shows Session expired, click Reconnect: the renewal fails, TradeCraft asks for your details again, and you enter the new ones.
If something goes wrong
| What you see | What it means | What to do |
|---|---|---|
| Could not compute Dhan TOTP | What you pasted is not a TOTP secret | Paste the text code shown with the QR, not a 6-digit code |
| Dhan token response contained no accessToken, or Invalid TOTP | Wrong PIN or TOTP secret | Check your PIN; if it repeats, redo Step 4 and paste the latest secret |
| Client ID is required to set up automatic token refresh | The Client ID field is empty | Paste it from your Dhan profile |
| Orders rejected with DH-905 Invalid IP | The IP on Dhan does not match TradeCraft's, or was added after you connected | Compare the IPs; if they match, click Reconnect in TradeCraft |
| DH-902 | Trading APIs are not active on your account | Open Get Trading & Data APIs on Dhan and check Trading APIs are enabled |
| Dhan will not let you change the IP | The 7-day lock | Wait until the date Dhan shows, then update it |
Still stuck? Write to [email protected] with the exact error message. Never include your PIN or TOTP secret.
Key takeaways
- Dhan's Trading APIs are free — you do not need the paid Data APIs.
- Add the TradeCraft IP on Dhan first. It is locked for 7 days once set.
- Paste the text code shown with the TOTP QR, not a 6-digit code.
- Connect once: after that, your Dhan access renews itself.
Frequently asked questions
- Is the Dhan API free?
- Dhan's Trading APIs are free, and they are all TradeCraft needs. Dhan's Data APIs are a separate paid subscription (₹499 a month plus taxes) that you do not need for TradeCraft.
- Do I have to log in to Dhan every day?
- No. Once you have set up TOTP and connected, TradeCraft renews your Dhan access on its own. If the account ever shows as expired, click Reconnect in TradeCraft and it renews without asking you for anything.
- Which PIN does TradeCraft ask for?
- The PIN you use to log in to Dhan. It is not a trading password, a TPIN or a 6-digit TOTP code.
- What is the TOTP secret, and why does TradeCraft need it?
- When you open Setup TOTP, Dhan shows a QR code and a text code next to it. That text code is the TOTP secret. TradeCraft uses it to generate the required OTP automatically each day, so you do not have to log in by hand.
- Can I change the static IP later?
- Only after 7 days. Once an IP is set on Dhan it cannot be modified for the next 7 days, so check it carefully before you save.
Want to try this yourself?
TradeCraft lets you build a strategy, backtest it against historical data, and deploy it on paper before risking a rupee — using your own broker account.
About the author
Geet Ramchandani
Founder & Engineer, TradeCraft
Geet is the founder of TradeCraft, a platform built for retail traders to automate their strategies and mirror trades across broker accounts. With 5+ years of experience trading the markets and hands-on experience with algorithmic trading, he writes about trading systems, execution, backtesting, risk, and what it takes to build them in the real world.
Keep reading
- BrokersWhat Is Mirror Trading? How to Copy Trades Across Broker AccountsOne master account, and everything you trade there shows up in your others — even at a different broker. What it does for you, how to switch it on, and the limits worth knowing before you lean on it.
- BrokersHow to Connect Your Zerodha Account to TradeCraft (Free Kite Connect API)Create a free Kite Connect app, register the static IP TradeCraft gives you, and paste two keys. Every screen, in order, plus what to do when Zerodha says no.