Issue with Fetching Historical Data for Nifty


Issue with Fetching Historical Data for Nifty

Hi everyone,

I am currently facing an issue while trying to fetch historical data for Nifty using the Dhan Trade API. Interestingly, I am able to retrieve the same historical data for Bank Nifty without any problems.

Here’s what I’ve done so far:

  • I used the get_historical_data() method with the following parameters:
    • tradingsymbol = 'nifty'
    • exchange = 'INDEX'
    • timeframe = '5'

While the Bank Nifty data works fine, for Nifty, I get the error:
“Exception in Getting OHLC data as ‘INDEX’”

Screenshot attached for reference.

Can anyone please help me identify what’s causing this issue or how to fix it?

@Tradehull_Imran

use security ID, for Nifty - 13

Post Content:
Hello everyone,

As suggested by @Happy_Life, I updated my code to use the security ID 13 for NIFTY while fetching historical data. Here’s the updated code snippet:

data = tsl.get_historical_data(tradingsymbol="13", exchange="INDEX", timeframe="5")

However, I am still facing the same issue, and the data isn’t being fetched properly. Below is the error I encountered:

Can someone please help me troubleshoot this? Am I missing anything else?

@Tradehull_Imran

Hi @sammed_patil

use below code

chart = tsl.get_historical_data(tradingsymbol = 'NIFTY',exchange = 'INDEX',timeframe="5")

also do post the question on below thread,

Not working for me either sir, @tradehull_Imran “Exception in Getting OHLC data as ‘INDEX’”. this is the error, i tried NSE at the Place of INDEX, then its showing data but wrong

Have You Got Any Solution ? @sammed_patil

I got the solution, i am using tradehull v2 - ATM Issue, in v2 there is the issue in historical data logic, and in tradehull v2 Ratelimits , hisorical data working fine for Nifty or any other index, but in rate limit there is another issue detecting otm stirke selection, and in v2 ATM its working fine. So check the script and make some change accordingly.