Update for API Traders: New Changes in DhanHQ API Authentication Process and Updates

Hello Everyone,

DhanHQ Trading and Data APIs are now widely used by many traders for its ease of implementation, complete documentation, wide choice of orders, and among many things - the speed of execution brought to you via our core proprietary trading engine - DEXT.

We are committed to making APIs more faster, stable and reliable. In accordance with the SEBI guidelines (which we recently discussed here), there are few updates on how you interact with DhanHQ APIs moving forward. We are making them easier, safer and accessible, while being in compliance with the regulations.

Here is what’s changing on your DhanHQ API experience:

1. Access tokens are now available only for 24 hours:
Keeping in line with the regulations, we are making access token validity to a maximum of 24 hours. While we always encouraged users to generate tokens for a maximum validity of 24 hours, we kept the option open for simplicity, where longer duration tokens could be generated. From now, only 24 hour tokens will be available and longer duration tokens can not be created.

2. API Keys - a new way to authenticate:
We are introducing a new way to login and authenticate your API access - API keys. Now, you can create API key and secret for initiating an OAuth based authentication with added security of 2FA login.

API keys is a preferred method for a lot of developers, wherein the process of generating new access tokens does not need to be done every day on the Dhan Web platform. Do note that the API key is valid for 12 months but you have to create a login session everyday. You can read more about the same here.

3. Authentication via TOTP
Along with the above changes, we are also introducing TOTP, a new method to authenticate 2FA while logging in to your Dhan account, only on API based login for yourself and on partner platforms.

4. Static IP whitelisting:
As an individual using APIs, we would want your Static IP address to be whitelisted with us, in order to continue using APIs post 1st October.

A static IP is a permanent internet address that never changes, unlike the regular dynamic IP your Wi-Fi assigns, which can change each time you reconnect. It must be procured from your ISP or cloud service provider. For retail algo traders, it ensures stable, fixed connectivity for APIs, whitelisting, and low-latency trading.

There are two ways to setup Static IP for your account:

  1. Go to web.dhan.co > DhanHQ Trading APIs > Setup Static IP
  2. Use Setup Static IP directly on APIs - Documentation

Static IP will be required for all Order APIs - to place, modify or cancel different types of orders including normal orders, super orders and forever orders. You can whitelist IPv4 or IPv6 based IP, depending on your choice.

We want to ensure that this transition is smooth for you, and our team is always available for you at help@dhan.co. While we implement the guidelines, we would like to know how we can improve your experience with APIs moving forward.

Do let us know your feedback here, as we continue building products with you.

Thank you
Hardik

3 Likes

Thanks for detailed information/update.

But One doubt,

I have been using api for my portfolio management… So i will use holding, ledger statement and trade history . Which will be called and imported into Google sheet.

I never do trading…

In my case, what to do?

Thank you @Hardik @Dhan for clearing doubts and providing documentation.

1 Like

Hey @NaveenSelvaraj

In that scenario, static IP requirement is not mandatory.

My concern is about first two points you mentioned.

Do I need to create login session every day?

If yes, can you plan to add generating the authentication code in mobile. (refresh will helps instead of deleting and re creating)

It will be helpful for my case as I can do copy and paste it.

@Hardik

Also incase where I need to place orders from google sheets… a lot of IP address will have to whitelsted. my volume are limited to less than 10 a day.
do we still have to get a static ip address…

Do we need static IP for placing orders if we trade through partner platforms?

@Hardik @PravinJ please respond if you get a chance

@NaveenSelvaraj

Yes, this will be required. You can use API key based login to automate with TOTP. We are working on making the refresh part more seamless as well.

@Bishnoi
Yes, google sheets will be a bit tricky if there is no predefined IP through which the API calls are routed.

Hey @Joy969, great to see you active here after a long time. In case of partner platforms, the requirement of static IP is fulfilled by partner itself.

1 Like

Thanks for the details!!
I have a doubt if i’m using any algo like ezquant,tradetron then which ip i have to configure with the dhan account and how can i get the ip?

Hi,

If I’m only using the data api for realtime market feed, do I still need a static ip?

Thanks

@ Hardik - Will you please release a video with all instructions to avoid confusion?

So have you enabled ipv6 thing on your platform, bcos i tried using an ec2 instance with ipv6 address to place order and it resulted in error. ENOTFOUND, and after digging for AAAA records, I got no AAAA records, thus i think ipv6 is not supported yet , or m i wrong, could you please help me figure this ?

Hello @Raja_Makwana @ps24 @PPLN @Abhishek_Tiwari1

Welcome to MadeForTrade community!

If you are adding your access token over there manually, you will have to provide your IP. You can check with the platform on their implementation around the same.

No, Static IP is only required for Order APIs.

Yes, this will be out soon.

It has always been supported and allowed. Do check the DNS setting at your end for this as well.

@Hardik
You’re right,
Another Grey area is family accounts adding another layer of complexity – multiple accounts can’t be managed through a single static IP.

From what I understand:

  • Basic API trading (placing/squaring off orders, fetching data etc.) works fine without a static IP.
  • High-frequency / institutional-grade algo trading usually requires a static IP, since the broker’s RMS (Risk Management System) whitelists your IP for security and ultra-low latency execution.

So, unless you’re running co-located or high-frequency systems, a static IP isn’t mandatory.

Please clearify this

@Hardik

Is threre any limit for Consent because getting Error
ERROR:dhan_token_manager:No consentAppId in response: {‘errorCode’: ‘CONSENT_LIMIT_EXCEED’, ‘errorMessage’: ‘Consent limit Exceeded’}

@ Hardik
When I’m using a new access token generated from the API key and API secret key, I’m getting this error: {‘errorType’: ‘Input_Exception’, ‘errorCode’: ‘DH-905’, ‘errorMessage’: ‘Missing required fields, bad values for parameters etc.’}. However, when I use the normal access key from Dhan Web, it works fine. Why is that?

1 Like

many users are using tradehull module file , will their be any changes to it. kindly arrange for it. else for a layman like us it will be very difficult to implement.

yeah i too observed the same thing