How to get historical futures data through data api?

I am trying to fetch 5-min candle data for futures using
https://api.dhan.co/v2/#/operations/intradaycharts
From the api-scrip-master file: Using the below row to fetch data for BANKNIFTY futures. But since the security id is only for BANKNIFTY-Dec2024-FUT, data is only given for that.

NSE	D	35025	FUTIDX	0	BANKNIFTY-Dec2024-FUT	15	BANKNIFTY DEC FUT	12/24/24 14:30	-0.01	XX	5	M	FUT		
However, this only gives data for BANKNIFTY-Dec2024-FUT

I want to get continuous data for futures for the last 10 years, but the api-scrip-master does not include the security-ids for the historical futures symbols.
Like I want to get data for:
BANKNIFTY-Jan2023-FUT,
BANKNIFTY-Feb2023-FUT,
BANKNIFTY-Mar2023-FUT,
BANKNIFTY-Apr2023-FUT,
BANKNIFTY-May2023-FUT,
and so on..
How do I get that through dhan api? Please help me out

1 Like

@hardik is this possible via API ? I think only the latest three month fut contracts are there in the scripmaster file.

@Hardik

I have to bring Bachan ji again :slightly_smiling_face:

1 Like

Hey @t7support @Shubham_Patwa

Sorry to miss this. Yes, it is possible to fetch data for past expiries as well, in case of futures contract.

Since we maintain futures data on rollover (which you can see on charts), the same is also available on APIs.

@Shubham_Patwa however, this endpoint looks incorrect. Can you tell me how did you get this endpoint?

1 Like

Thanks @Hardik.

@Hardik how to get security id of expired contracts ?

Sorry..my bad
I am using this url : "https://api.dhan.co/v2/charts/intraday"

yes. please do tell?

This is the major question @Hardik . How do we get the security id of expired contracts? Without this we cannot fetch the historical data.

@Hardik
Upstox is providing this feature of getting the historical futures data which are even expired. Even ICICI direct is providing this. Can DHAN provide this as well?

1 Like

Hey @Shubham_Patwa

For futures contract, you can fetch the data basis of current expiry itself and you should be able to get the data for previous expiries.

For options contract, we only provide instrument data for the current expiry.

@Hardik
For this endpoint:

https://api.dhan.co/v2
/charts/intraday

This is the payload:

From the docs: 
{
  "securityId": ,
  "exchangeSegment":,
  "instrument":,
  "interval": ,
  "oi": ,
  "fromDate": ,
  "toDate":
}

What do you mean we can get the data for previous expires on the basis of current expiry itself? How to get the security ids?

Can you please elaborate more? I did not understand it. May be an example?
What should be the security ids? What should be the fromDate and toDate?

I need only Futures data like BANKNIFTY futures at 5 min level

@Hardik ?

@Hardik
can you please let me know

Hey @Shubham_Patwa,

For stock and index futures, we have continuous charts available for the daily and higher time frames. This means if you fetch the near-month expiry date for any contract — for example, Banknifty Aug Futures expiry (security ID 64100) you’ll get daily candle data from 2011 right up to the current date.

If you fetch intraday data though, it will only be available for the last 3 months since NSE future contracts remain active for that period.

Please note; we don’t provide expired contracts data, but this method is a handy workaround you can use.

@Trishul_Devadiga
Ok Got it.
But even for equity data, I can fetch intraday data only from 2017 onwards. Data is not available since inception which is claimed on the website.

Like for example, ‘BHEL’ is available on charts from sept. 2003.
But from the api, I can only fetch it from March 2017.
Using this endpoint :

> "https://api.dhan.co/v2/charts/intraday"

Can you tell about this please?

@Hardik
Can you please let me know

@Trishul_Devadiga

Hey @Shubham_Patwa ,

As checked, the endpoint shared by you appears to be for intraday charts. Please note that you can fetch data only up to 5 years in intraday, and in a single stretch, you can retrieve data for a maximum of 90 days.

Further , you may refer Historical Data - DhanHQ Ver 2.0 / API Document .