Hi,
I am trying to run below code and I am getting DH-905 error. No matter what I change, getting the same error.
GET request is executed successfully as shown in the image below but POST is returning DH-905 and unable to understand what I am doing wrong.
Code in Jupyter Notebook:
Code:
import pandas as pd
from dhanhq import dhanhq
from config import client_id, access_token
import requests
# to add dhan credentials to the notebook
dhan = dhanhq(client_id, access_token)
dhan_headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'access-token': access_token}
response = requests.get(url= "https://api.dhan.co/v2/super/orders", headers=dhan_headers)
response.status_code
post_data = {
"dhanClientId": "110abcdefg",
"correlationId": "123abc678",
"transactionType": "BUY",
"exchangeSegment": "NSE_EQ",
"productType": "CNC",
"orderType": "LIMIT",
"securityId": "18268",
"quantity": 1,
"price": 164.00,
"targetPrice": 167.00,
"stopLossPrice": 155.00,
"trailingJump": 1.00
}
response = requests.post(url="https://api.dhan.co/v2/super/orders", headers=dhan_headers, data=post_data)
response.json()
Any help is appreciated. Thanks.
HI @ekveer, can you remove the “correlationId”: “123abc678” and check again.
Also, you can refer to Super Order - DhanHQ Ver 2.0 / API Document and in your endpoint you need to give command of a POST request.
Thanks Mohseen for your response. Actually GROK came to the rescue. Below change made all the difference and it is working now.
We have to send data to JSON field in requests.post instead of DATA field.
New Code:
import pandas as pd
from dhanhq import dhanhq
from config import client_id, access_token
import requests
# to add dhan credentials to the notebook
dhan = dhanhq(client_id, access_token)
dhan_headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'access-token': access_token}
response = requests.get(url= "https://api.dhan.co/v2/super/orders", headers=dhan_headers)
response.status_code
post_data = {
"dhanClientId": "110abcdefg",
"correlationId": "123abc678",
"transactionType": "BUY",
"exchangeSegment": "NSE_EQ",
"productType": "CNC",
"orderType": "LIMIT",
"securityId": "18268",
"quantity": 1,
"price": 164.00,
"targetPrice": 167.00,
"stopLossPrice": 155.00,
"trailingJump": 1.00
}
response = requests.post(url="https://api.dhan.co/v2/super/orders", headers=dhan_headers, json=post_data)
response.json()
1 Like