How to Create Your Dhan API Key
The process of obtaining an API Access token through Dhan is a simple procedure that allows you to incorporate your trading strategies into automated systems. The token is your identifier unique and is also an security to enable all API communications on your Dhan platform.
Steps For Detailed Token Generation Process
- Access Dhan Web Platform: Navigate to Dhan Web Platform: Go to web.dhan.co by using your favourite web browser. Then login to an existing Dhan account with the credentials you registered with. You must have a stable internet connection to complete this procedure.
- Log in to your profile settings After you have logged into your account successfully, you can see your profile picture or avatar in the upper-right part of the display. This section of your profile contains the account-related settings and configurations.
- Enter the API Access Section: From the drop-down menu that is displayed when you click on the profile photo, click the option that reads “Access DhanHQ APIs”. This section is designed specifically for people who want to integrate their trading operations through third-party apps as well as automated platforms.
- complete payment process, if necessary Based on the type of account you have and your the current level of your subscription you might be required to pay a modest activation cost to gain API access capabilities. This fee assists in maintaining the infrastructure and ensures high-quality service in the interest of API users.
- Create Your Unique Token Once you have completed the required payment there is the option “Generate Token” within the API access section. Click this button to generate your own unique API Access token.
- Secure Token Storage After the token is generated you must immediately save the token by copying it and storing it in a safe location. This token is highly sensitive and provides the direct connection to your account, therefore ensure it is treated with the same level of security that you would your password for your account.
Understanding Dhan API Rate Limiting System
Dhan API Dhan API implements a comprehensive rate-limiting system that ensures an equitable usage of the system, ensure stability, and shield all users from possible interruptions in service. These limits are designed to ensure that functionality is balanced with the performance of the system.
Trading Order Rate Limits
API enforces strict limits on order placement. API enforces strict restrictions on order processing to avoid overloading the system and guarantee fair access to the market for all participants.
Limits per Second Your automated systems are able to place up to 25 orders in a single second. This restriction prevents fast-fire orders that could affect the stability of markets.
Per-Minute Restrictions within a 60 second period the system is able to allow up to 250 order entries. This extended timeframe allows flexibility to strategies that require rapid trading, while ensuring the stability of the overall system.
Hourly constraints The duration of an hour access to your API allows up to 1000 orders. This limit is sufficient for the majority of algorithmic trading strategies, and also prevents excessive resource consumption by the system.
Daily Limits: The system limits daily order placing at 7000 transactions per 24 hour period. This large daily limit guarantees traders with even active strategies be effective without triggering artificial limitations.
Historical Market Data Access Limits
When you request historical prices, charts, or any other information about markets The API applies the following restrictions:
The automated systems of your system can request as many as 5 records of historic chart information per second, which is enough capacity for most analytical software. Furthermore, the system is able to handle up to 100,000 requests for historical data each day, which will allow for a comprehensive backtesting and analytical requirements for the majority of trading strategies.
Real-Time Market Data Quotas
Live price feeds as well as market data in real-time The API allows one live price inquiry per second. Although there no daily limit set for live price requests the limitation per second makes sure that real-time information streams remain steady and responsive to all users.
Rationale Behind API Rate Limiting
Fair Resource Distribution
Rate limitations guarantee that everyone API users have equal access to resources of the system by preventing a single application or user from dominating capacity on servers and diminishing the quality of service for other users.
System Protection and Stability
By regulating the speed of requests that are received by regulating the rate of incoming requests, the API infrastructure stays steady and responsive, even in times of extreme market volatility, when trading activity usually increases substantially.
Account Security Measures
Rate limiters are an additional security measure aiding in identifying and stop potentially harmful actions as well as compromised accounts which may attempt to make an unorthodox number of orders.
Market Integrity Maintenance
They help to maintain an orderly market by stopping the creation of large orders that could influence market prices or generate artificial volatility.
Implementing Dhan API Authentication in Python
After you have received your API token and have it, the next step is the integration of this authentication method in your Python trading software. This will establish an encrypted connection between your own custom software and Dhan trading platform.
Authentication Setup Process
The authentication process begins by downloading the necessary libraries and then connecting with the Dhan API servers. The previously acquired API token acts as your principal authentication credential, working similar to an electronic signature that confirms your identity on every API request.
Using Tradehull for Simplified Integration
Tradehull is a full wrapper library that greatly simplifies using the Dhan API. The third-party application handles a lot of the complicated authentication process, request formatting and response parsing that could otherwise need manual implementation.
The Tradehull library takes away a lot of the technical issues associated with API communication which allows you to concentrate on implementing your trading strategies rather than coordinating low-level details for connection. It has pre-built functions to handle routine tasks like placing orders, retrieving information about portfolios and market data and directing positions.
Best Practices for API Implementation
When you are implementing the Dhan API integration you should consider using error-handling mechanisms to effectively manage network issues and rate limit exceptions and other possible disruptions. Also, consider implementing logging capabilities to monitor your API use and to identify any patterns that could be approaching the limits of your rate.
Think about implementing connection pooling as well as request queuing methods to maximize your API use efficiency and make sure that your APIs are operating within the set limit of performance while increasing speed.
Security Considerations and Token Management
Your API token is a direct link directly to the trading accounts you have, and must be secured with the highest security. Do not include tokens in your code source, particularly in the event that your code will be stored in versions control systems.
Instead, make use of environment variables or secure configuration files or specialized secret management services to store and retrieve to your API credentials. Make sure you rotate regularly your API tokens to ensure best practice in security. Also, immediately re-issue tokens if you think they’ve been compromised.
Be sure to monitor your API usage regularly via your Dhan platform to make sure that your API usage is consistent with the legitimate trading applications. Make sure to report any suspicious activity directly to Dhan Support services.
Step 1: Install the Tool
You first need to install Tradehull SDK on your computer.
📦 Just open your terminal (or command prompt) and type this:
pip install Dhan-Tradehull
👉 You can also find it here: Dhan-Tradehull on PyPI
Step 2: Use This Code to Connect
Now let’s write a small Python program to connect to Dhan using your token:
from Dhan_Tradehull import Tradehull
client_code = "your_client_code"
token_id = "your_token_id"
tsl = Tradehull(client_code, token_id)
What’s Really Happening?
The computer is telling you:
“Here’s my Dhan key, please log me in.”
If your login is successful it will display your Dhan profile – like it says:
“Hi! Yes, I know you. You’re in!”
What Can You Do Next?
Once you’re registered, you are able to make use of Python to:
Live prices of stocks
Sell or buy stocks
Review your Portfolio (your investments and money)
Check out charts and market data
Set stop-loss targets and set stop-loss orders.
Make the trading platform of your dreams!
What Can Your Robot Friend Do?
After you’ve signed into your account, your robot buddy (thanks Dhan-Tradehull) Dhan-Tradehull) is now ready to assist you in trading like a professional!
And do you know what? You don’t need to remember the spells (codes) because they’re ready to be written!
With Dhan-Tradehull your robot can:
Get live stock prices
Check out charts from the past
Place, cancel, or alter orders, cancel or change
Find smart option data such as Greeks (Delta, Theta …)
Find options strikes (ATM, ITM, OTM)
Present your portfolio
Make use of stop-loss orders or sliced orders to automate the process
Try All These Features Yourself!
You can browse and copy all of the ready-to-use codes on this page:
All information is presented in a a simple manner.
You can select the actions you wish to take and then copy the code from there.