I have gone through all the Algo Trading videos uploaded through Dhan but not able to use the API to fetch historical data. Getting error for the expiry - {‘status’: ‘failure’, ‘remarks’: “expiry_code value must be [‘0’,‘1’,‘2’,‘3’]”, ‘data’: ‘’}
I have tried using “0”, ‘0’ and just 0 but getting the same error.
The following is my code
from dhanhq import dhanhq
client_id = “Used my client_ID”
access_token = “Used my access token”
dhan = dhanhq(client_id, access_token)
security_id = 13 # NIFTY 50
exchange_segment = “IDX_I” # correct for indices
instrument_type = “INDEX”
expiry_code = 0 # must be int, not string
from_date = “2023-01-01”
to_date = “2023-12-31”
data = dhan.historical_daily_data(
security_id,
exchange_segment,
instrument_type,
expiry_code,
from_date,
to_date
)
print(data)