Now Live: Updated DhanHQ V2 Trading & Data APIs available

Hello Harish, I managed to do it in python, created my own little library of v2

{‘instrument_token’: 44118, ‘latest_traded_price’: 214.8000030517578, ‘last_traded_quantity’: 15, ‘last_trade_time’: 1728466173, ‘average_trade_price’: 217.6300048828125, ‘volume’: 12718230, ‘total_sell_quantity’: 316335, ‘total_buy_quantity’: 20955720, ‘open_interest’: 3596805, ‘highest_open_interest’: 3596805, ‘lowest_open_interest’: 2036385, ‘day_open_value’: 160.0, ‘day_close_value’: 247.1999969482422, ‘day_high_value’: 269.0, ‘day_low_value’: 132.60000610351562, ‘market_depth’: [{‘bid_quantity’: -2025651047, ‘ask_quantity’: 1006632960, ‘number_of_bid_orders’: 0, ‘number_of_ask_orders’: 256, ‘bid_price’: -134221824.0, ‘ask_price’: -4.039516881921614e-23}, {‘bid_quantity’: 994269017, ‘ask_quantity’: 754974721, ‘number_of_bid_orders’: 0, ‘number_of_ask_orders’: 1536, ‘bid_price’: 7.174648137343064e-43, ‘ask_price’: 2.3061542980199378e+23}, {‘bid_quantity’: -1539090586, ‘ask_quantity’: 2013265921, ‘number_of_bid_orders’: 0, ‘number_of_ask_orders’: 1536, ‘bid_price’: 2.980414137709886e-08, ‘ask_price’: 4.5480827992605555e-08}, {‘bid_quantity’: 742610803, ‘ask_quantity’: 1241513985, ‘number_of_bid_orders’: 1, ‘number_of_ask_orders’: 1792, ‘bid_price’: 1.511433975679392e+23, ‘ask_price’: 6.184061845121064e-39}, {‘bid_quantity’: -1807526016, ‘ask_quantity’: -1023410174, ‘number_of_bid_orders’: 0, ‘number_of_ask_orders’: 3328, ‘bid_price’: -2.647139518883078e-23, ‘ask_price’: -204827024.0}]}

just need to deserialize(unpack) correctly market depth data

this is live data of 51000 pe 9 oct unpacked

1 Like

Hello Hardik, I request you guys to kindly add previous close in full packet, currently previous close packet coming separately.

1 Like

Hello @Hardik

While calling the V2 api to get intraday historical data, I am getting 429 client error. Can you help address this please

<Response [429]>
An error occurred: 429 Client Error: for url: https://api.dhan.co/v2/charts/intraday

when i am trying to update forever order using the following code i am getting the error. Please help me with this.
400
{‘errorType’: ‘Input_Exception’, ‘errorCode’: ‘DH-905’, ‘errorMessage’: ‘Missing required fields, bad values for parameters etc.’}

#for modifying gtt orders via gtt order id
import requests
import json

#pass gtt order id to url

Define the order ID to modify

order_id = ‘9132410141980’

Set up the API endpoint

url = f’https://api.dhan.co/v2/forever/orders/{order_id}’

headers = {
“Content-type”: “application/json”,
“Accept”: “application/json”,
“access-token”:accesstoken
}
#legNamerequired string Order leg of Forever Order where modification is to be done ENTRY_LEG - For Single and First leg of OCO TARGET_LEG - For Second leg of OCO
order_data ={
“dhanClientId”: clientid,
“orderId”: order_id,
“orderFlag”: “SINGLE”,
“orderType”: “LIMIT”,
“legName”: “TARGET_LEG”,
“quantity”: 15,
“price”: 1421,
“disclosedQuantity”: 5,
“triggerPrice”: 1420,
“validity”: “DAY”
}

Convert order_data to JSON

response = requests.put(url, headers=headers, data=json.dumps(order_data))

Print the response

print(response.status_code)
print(response.json())

Hello @shbtechno @nkvasuja

Can you keep a check on the API you are polling or any of other platforms that you use might be polling here.

@nkvasuja Welcome to MadeForTrade community!

Since you are modifying single forever order, the legName would be ENTRY_LEG. Do try with this.

Hello, has anyone tried Live order update (Live Order Update - DhanHQ Ver 2.0 / API Document) . I am not getting any response. @Hardik

I have also tried ENTRY_LEG. but still getting the same error. And when I try to use python function for forever order, it says dhanhq has no such object.

Hi @Hardik

I am using v2 api call to get LTP, same code worked perfectly fine for some time and then later on I am getting 404 error. Can you please assist, is there any outage?
Error : Failed to fetch LTP. HTTP Status Code: 404
Response: 404 page not found
Note: Tried api call around 18:00 as using for MCX…

https://api.dhan.co/v2/marketfeed/ltp

I have also tried TARGET_LEG. but still getting the same error. And when I try to use python function for forever order, it says dhanhq has no such object.

And when i am using dhan forever order python function it says it is not available.

Please help as to how to modify forever order

Hello @raviraj_nayak

Welcome to MadeForTrade community!

Yes, a small change here. MsgCode needs to be integer instead of string, and this should work. Do try with this and let us know.

I will try to replicate. Last time I tried and it was working. On dhanhq Forever Order, we haven’t added v2 on APIs yet. Will let you know once it is live.

@shbtechno There is no outage. Did you retry this after that and were you able to fetch the same?

1 Like

Hi @Hardik ,
After trying same code its working now. Not sure why there was an intermittent issue yesterday.
Thanks for your response.

Hello @shbtechno

Will try to check this, but if it would have been there, the impact would have been noted.

Do you have a retry function built incase the API fails?

Hello @Hardik
Yes retry also didn’t worked as the impact was for more than an hour

Thanks! @Hardik . It worked when MsgCode changed to integer.

1 Like

May I know when will i get the update on resolving the code issue? And when will be v2 added on APIs? Also till then , what is the solution for updating forever orders via api?? Please help me regarding this matter.