CODE:-
import requests
import pandas as pd
import json
url = “https://api.dhan.co/charts/historical”
headers = {
- “Content-Type”: “application/json”,*
- “access-token”: removed on purpose # Replace with your actual token*
}
payload = {
- “securityId”: “180854”, # CAMS*
- “exchangeSegment”: “NSE_EQ”,*
- “instrument”: “EQUITY”,*
- “expiryCode”: 0,*
- “oi”: False,*
- “fromDate”: “2024-04-01”,*
- “toDate”: “2024-04-23”,*
- “interval”: “1m”*
}
response = requests.post(url, headers=headers, json=payload)
# Handle response
if response.status_code == 200:
- data = response.json()*
- print(“Raw response:\n”, data) # ← Print full JSON*
- candles = data.get(“candles”, )*
- print (candles, " ##################### candles ######### ")*
- if candles:*
-
df = pd.DataFrame(candles, columns=["timestamp", "open", "high", "low", "close", "volume"])*
-
print(df.head())*
- else:*
-
print("✅ No candle data returned for selected dates.")*
else:
- print(“
Error:”, response.status_code)*
- print(“
Response:”, response.text)*
- print(“
Status Code:”, response.status_code)*
##############################################################
ERROR I AM GETTING IS:
Raw response:
{}
##################### candles #########
No candle data returned for selected dates.
#################
I am stuck due to this kindly send the solution to this as soon as possible. Thanks in advance