Historical data on NIFTY 50 vs. CRUDEOIL18JUNFUT

I tried getting historical data on CRUDEOIL18JUNFUT, token: 53703431 but the array returned was empty. On the other hand NIFTY 50, token: 256265 returned values.

I am using javakiteconnect. The following code:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date from = new Date();
Date to = new Date();
try {
from = formatter.parse("2017-05-25 12:00:00");
to = formatter.parse("2017-05-25 22:49:12");
}catch (ParseException e) {

HistoricalData historicalData = kiteConnect.getHistoricalData(from, to, "256265", "60minute", false);

When I replace 256265 with 53703431, the array returned is empty. Why is that?
  • xida
    It appears that historical candles for instruments only at NSE and BSE are available. All other exchanges, viz. CDS, MCX and NFO are not returning any historical data. I looped through the entire csv and found that instruments on all exchanges, except CDS, MCX and NFO return empty lists.
  • sujith
    You can fetch continuous data to fetch data for expired futures instruments.
    We only have day candles for expired instruments.
    For more details, you can check out documentation here.
  • xida
    @sujith The instrument I mentioned above has not expired.
    53703431 209779 CRUDEOIL18JUNFUT Light Sweet Crude Oil 0 6/19/2018

    I believe the reasons are elsewhere. They might partly have to do with a possible bug in the API. I have written on this here:

    But even if we fix this bug there might be some other problem of historical data on all exchanges except BSE and NSE, particularly MCX.

    It could also be, simply, unavailability over weekends.

    My code is working now. Let's see over the coming weekend.
  • Matti
    Matti edited May 2018

    That is not how this works. Let me explain:

    At any given time, there are 3 active contracts, Current Month, Next Month, and Far Month. Each of these is assigned an exchange token. This token, however, may be reused by the exchange. So the May contract token may have been assigned to the September contract. So you can't use the old token to fetch candles for old/expired contracts.

    To address this, Kite assigns a unique instrument token for each contract that is never reused. For fetching candles of expired contracts (only day candles are available for such contracts) you'll have to use the unique Kite instrument token and set the value of the 'continuous' param as '1'. This is how you'll receive the day candles for that instrument (in your case CRUDEOIL) for a given period(in your case MAY 2017) that you define using the 'from' and 'to' params.
  • xida
    Slightly confused - CRUDEOIL18JUNFUT is not an expired contract. In fact my code works with continuous = false. With true it gave an input exception.
  • Matti
    Matti edited May 2018
    May 2017 is an expired contract, correct?
  • xida
    In that case, why does the following Java code return the correct candles, with the same data as shown in the Kite.zerodha charts.
    Date from = new GregorianCalendar(2017, 11, 21, 11, 0, 0).getTime();
    Date to = new Date(System.currentTimeMillis() + 330 * 1000 * 60);
    HistoricalData historicalData = kiteConnect.getHistoricalData(from, to, "53703431", "60minute", false);
  • sujith
    Since you can't send a date object as request param in an URL. The API expects a client to send the date in this format.
    In order to do basic validation of input data, javakiteconnect expects users to send a date object.
  • xida
    Oh I meant with respect to the continuous flag.
  • sujith
    If you set the continuous flag as true then it means you are trying to fetch data for an expired instrument using the current month instrument token.
Sign In or Register to comment.