Need Help - DhanHQ Order Placement using Python

Hi @bsjhala

Product type should be either INTRADAY or MARGIN. Intraday as name suggests for intraday position and Margin for carryforward/overnight position.

In the above screenshot we can see that the finnifty option strike and banknifty option strike is having a different symbol format. The date part within the symbol is shwoing differently. For finnifty symbol, the month string is showing using just one character ‘N’ for november, while for banknify the month is represented using 3 characters as “NOV”. And the date and year is at different places in both symbols. Please have a look into this issue. This is causing issue in getting security id from the symbol.

1 Like

Hi @stanly_thomas Thank you for highlighting this challenge with FINNIFTY.

I have modified the code by adding “FinNifty_monthly” parameter in the get_security_ID_and_LTP() function to overcome this challenge with FINNIFTY and uploaded into GitHub

Link to GitHub

If using the code for FINNIFTY Monthly expiry, please pass the FinNifty_monthly = True as an argument.

security_id, security_ltp = get_security_ID_and_LTP(symbol='FINNIFTY', expiry_date='2022-11-29', strike_price=18550, option_type='CE', FinNifty_monthly=True)

dhan.place_order(security_id=security_id, exchange_segment= dhan.FNO, transaction_type= dhan.SELL, quantity=40, order_type=dhan.LIMIT, 
                 product_type= dhan.INTRA, price=security_ltp)

If using the code for anything else other than FINNIFTY Monthly expiry, we NO NEED to pass the FinNifty_monthly = True parameter

security_id, security_ltp = get_security_ID_and_LTP(symbol='FINNIFTY', expiry_date='2022-11-15', strike_price=18650, option_type='CE')

dhan.place_order(security_id=security_id, exchange_segment= dhan.FNO, transaction_type= dhan.SELL, quantity=40, order_type=dhan.LIMIT, 
                 product_type= dhan.INTRA, price=security_ltp)
1 Like

@PravinJ / @Naman / @Hardik

I am trying to get historical data using Dhan HQ, but there seems to be an issue with fetching Option related historical data.

I tried everything that is mentioned in the Dhan HQ API document, but it is working only for stock and index historical data and not for Option historical data.

Please find below image and let me know if it is a limitation or am I doing anything wrong with syntax? The first cell in the image contains code for fetching NIFTY historical data and it worked. Whereas the code to fetch historical data for BANKNIFTY24NOV2242300CE is returning a ‘success’ status, but not returning any data. I have even looked into the api_master_scrip.csv file to make sure I am using correct input arguments.


Hello @ravi_krishna

Options data is only available on Intraday Historical Data API currently. This is the reason you are not able to get data for the same.


Thank you for the response. Is there any plan to provide historical Options data in future? Or should I consider this as completely out of scope?

Hello @ravi_krishna

At Dhan, we are always building on our user’s feedback. We have noted this and will evaluate it to incorporate in our roadmap.

1 Like

@Hardik / @PravinJ / @Naman

I use the historical_minute_charts() every day for my analysis but these days I see too much lag in the data. For example, today is 24th November and I am trying to fetch data until 23rd November. But what I get is only until 22nd November. May I know at what time your data servers get updates? Can’t we update the data at the end of each day?

Please find below screenshot to understand the issue. Look at the to_date in the function and the max date in the output, I still see data until only 22nd November when we are already on 24th November. 23rd missing.

Hello @ravi_krishna

For the historical data API, our systems update last day OHLC next morning. As highlighted by you, 23rd November data should have been visible by today morning.

We troubleshooted this and found out that the data is being updated as scheduled for all instruments except INDIAVIX (you can recheck this at your end). We are getting this fixed as well, so that such instance doesn’t happen again.

1 Like


Thank you for the response and explanation.


As suggested by you, I have rechecked on my end but I still see some issues. For example, I am getting data for NIFTY only until 22-Nov-2022. 23rd is still missing in this case. Please fix the issue.

If possible, after fixing the issue please double check with NIFTY, BANKNIFTY, INDIAVIX and one/two stocks like INFY and TCS too.

Also, could you please mention some tentative time by which the systems update data every morning? It helps me plan accordingly.

Hello @ravi_krishna

The data gets updated every morning around 8.30 AM. The fix was delivered. Do check and let us know if you are able to retrieve the same.

Also, over here, from_date is not inclusive and to_date is inclusive.

Hope this helps!

I don’t see STOP LOSS LIMIT value in place_order function. Could you help me in understanding this?

Hello @poojamlvya

First of all, welcome to Dhan Community!
Over here, STOP_LOSS or SL is your Stop Loss Limit order type. To place this type of order, you need to enter values for the following two variables:

  1. price - Limit price at which order should be placed
  2. trigger_price - Price at which order should get triggered

Hope this helps! You can always reach out to @Dhan_Help at for any such queries.

how to close this position with a SELL order at market price ??

How do we close a buy position in FNO ? I tried SELL INTRADAY MARKET order ,but it didnt work !!!

Hello @alok.nayak

You can refer to the documentation here for placing orders via DhanHQ Python Library. If there is any error that you are facing, then it is better if you copy paste the request and response here so that we can help you out.

There should be some sample codes which simple crossover strategies available from dhan.

with simple order
sl order
limit order
trailing Sl etc.

so that even noob cod users can come on platform.

this laso make business

Hello @RajeshK

We have added a bunch of sample codes to help users get started fast. This is available on the GitHub repository page and PyPi project page.

It will be great if all python traders here can help compile a topic where we can add all such sample codes in a single thread in this community.

Hi team Dhan,

@Hardik @Naman - Can you guys please tell what is the use (or higher advantage) of placing orders using scripts as compared to placing orders via app? I just want to understand if there is some great benefit of using scripts.

Let me know!