Introducing: Dhan Python API Library for Trading APIs

K noted thanks @PravinJ

thanks @PravinJ . This comes for a single leg/position.

I am trying to use the Dhan Pyhton API for creating a Algo.

As per Documentation , I am trying to connect to API and getting the Holdings.
It is taking almost 1-2 minutes to give the Holdings.{Refer ScreenShot Below}

Further, when I am trying to place a Buy Order as per the Documentation following message is appearing:{refer screenShot below}

Whats the issue ??
Why results are displaying so late…

Documentation needs to be improved. Other Brokers are providing very good documentation for every function for easier understanding of API and implementation

1 Like

Hi, you can try the sample code below. There are couple of things in the Documentation that need to be fixed.

  1. exchange_seg= ‘NSE_EQ’ should be exchange_segment=‘NSE_EQ’
  2. There is no argument option for passing corelationID
from dhanhq import dhanhq


client_id = "Enter your client_id here "
access_token = "Enter your access_token here "
dhan = dhanhq(client_id, access_token)

# Place an order (hdfc bank- 1333)
market_order = dhan.place_order(
    security_id='1333',
    exchange_segment='NSE_EQ',
    transaction_type='BUY',
    order_type='MARKET',
    product_type='INTRADAY',
    quantity=10,
    price=0,
    trigger_price=0,
    validity='DAY',
    after_market_order='False'
)
print(market_order)

# Place limit order
limit_order = dhan.place_order(
    security_id='1333',
    exchange_segment='NSE_EQ',
    transaction_type='BUY',
    order_type='LIMIT',
    product_type='INTRADAY',
    quantity=10,
    price=100,
    trigger_price=0,
    validity='DAY',
    after_market_order='False'
)
print(limit_order)

# Place StopLoss Order
SL_Buy_order = dhan.place_order(
    security_id='1333',
    exchange_segment='NSE_EQ',
    transaction_type='BUY',
    order_type='STOP_LOSS',
    product_type='INTRADAY',
    quantity=1,
    price=110,
    trigger_price=100,
    validity='DAY',
    after_market_order='False'
)
print(SL_Buy_order)

# Intraday daily minute charts
intra_data = dhan.intraday_daily_minute_charts('11536', 'NSE_EQ', 'EQUITY')
print(intra_data)

# Fetch all orders
dhan.get_order_list()
print(dhan.get_order_list())

# Get positions
dhan.get_positions()

# Get holdings
dhan.get_holdings()

# Get fund limits
dhan.get_fund_limits()
print(dhan.get_fund_limits())

@Market_Wizard

Sample Code worked. But as suggested by you, Lot of corrections required in documentation.
Code as per recent documents not working.

One More thing why Code is running extrmely slow. Taking more than a minute …

What is the cause and solution for the same.

I ran the same sample code at my end and it took less than a second. You need to check at your end what is causing the delay.

Thank you @Market_Wizard for helping with the clarification here.

We have noted and will make the changes. For correlation ID, it is an optional field and can be added at user’s end if required.

yes, It is taking very long for first API call almost 1 min plus. subsequent API calls happening quickly

Hello @9985243221
Welcome to Dhan Community!

We have added some fixes in our python library - here. This will help with the delayed API response. Hence, we request you to reinstall the library in order to get updated version.

Hi @Hardik , when can we expect the order slicing option to come to python library?

Hello @stanly_thomas

Our team is working on releasing next version of Python library which will include order slicing and couple of other APIs in the library as well. We will keep you updated here.

1 Like

Dear Dhan team, it’s very good to use your python API. But most of the functions are not able to access as the parameter type mismatches. I want to remind you that providing an API is useless if you don’t provide clear documentation for the API. It is very difficult to use your API without documentation.

Please provide the documentation too

Hello @Dhanu

Welcome to Dhan Community! It’s exciting to see increasing no. of individual contributors and traders using DhanHQ APIs.

We are in the process of adding detailed documentation soon for our Python library as well on DhanHQ.

@Dhanu @stanly_thomas @bsjhala
We have added Python Library documentation along with the new library. Check out the detailed post here:

Hi Pravin
Yes it is regarding data feed
I have excel based trade management system which I showed a demo in Kandivali office 8-9 months ago. The file was working on Fyers login but I wanted it to modify to match it with Dhan’s feed.
But came to know that it requires web-socket.

It was almost at completion stage in the month of February

But testing took another month to rollout

I had word with Vishal last month at Kandivali office.
He said MCX feed is pending and Dhan would like to rollout all segments at once.

since then there is no update.

is there any video provided by Dhan to understand API and Algo trading better , any video to start from

Hi @hustler

We have a video series on DhanHQ Youtube channel on how to get started with DhanHQ APIs, you can watch that here: (How to use an API? DhanHQ API Documentation Tutorial for Beginners in the Stock Market | Dhan - YouTube)

Hello @sac777

Yes. The team is working on getting Live Market Feed over websocket for API users. However, there has been unforeseen delays here, due to the recent MCX trading platform migration.

Rest assured, our team is working to ship this soon. We will keep you updated here on the community as soon as we are live with this.

Yes,

But
I posted detailed reply from my laptop
Replies are not seen when I access the community page on Mobile phone