Skip to content

Introduction

Getting Started

alt

DhanAPI is a state-of-the-art platform for you to build trading and investment services & strategies.

It is a set of REST-like APIs that provide integration with our trading platform. Execute & modify orders in real time, manage portfolio, access live market data and more, with lightning fast API collection.

We offer resource-based URLs that accept JSON or form-encoded requests. The response is returned as JSON-encoded responses by using Standard HTTP response codes, verbs, and authentication.

Developer kit:-
Swagger: dhanHQ Swagger
SDK & Libraries: OpenApi Specification

  
python
 
  DhanHQ Python documentation
  
python
 
  DhanHQ Python documentation
  

Login

For Partners

Once the partner is onboarded through offline channel, Dhan team will share Partner credentials for Login. When the Dhan user, login to the partner’s application, the consent flow server-to-server and the partner gets the consent id. Partner has to put credentials in header. Thereafter, the partner starts browser based login flow. Dhan user login using Dhan credentials (email/phone/password/pin). Login flow terminates with redirection to partner server with token id. Finally, the partner shall fetch the user details and access token.

STEP 1:     https://auth.dhan.co/partner/generate-consent

Partner need to add partner_id & partner_secret in the header. The response of this flow will have consent-id. Use this consent-id for the next browser based flow.

01

STEP 2:     https://auth.dhan.co/consent-login?consentId=<consentId>

This flow will terminate on a partner's server with URL <partner-redirect-url>?tokenid= <tokenId>. Use this token-id in the next GET call.

02

STEP 3:     https://auth.dhan.co/partner/consume-consent?tokenId=<token-Id>

In this step, you need to add partner_id & partner_secret in header again.
This flow will end with end user details like ClientId, UCC, PoA status etc..

03


For Individual Traders

Individual traders can directly get their Access Token from web.dhan.co,subject to eligibility. The eligibility criteria to get Access Token is minimum 25 trading orders executed in the last 30days and this is inclusive of Futures, Options, Commodity, Currency & Equity-Intraday. Here's how to get your Access Token:

  • Login to web.dhan.co

  • Click on My Profile and navigate to 'DhanHQ Trading APIs and Access'

Structure

All GET and DELETE request parameters go as query parameters, and POST and PUT parameters as form-encoded. User has to input an access token in the header for every request.

curl --request POST \
--url https://api.dhan.co/orders \
--header 'Content-Type: application/json' \
--header 'access-token: JWT' \
--data '{Request JSON}'

Errors

Error responses come with the error code and message generated internally by the system. The sample structure of error response is shown below.

{
    "errorCode": "",
    "httpStatus": "",
    "internalErrorCode": "",
    "internalErrorMessage": ""
}