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) { e.printStackTrace(); }
HistoricalData historicalData = kiteConnect.getHistoricalData(from, to, "256265", "60minute", false);
When I replace 256265 with 53703431, the array returned is empty. Why is that?
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.
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.
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.
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);
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.
We only have day candles for expired instruments.
For more details, you can check out documentation here.
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.
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.
In order to do basic validation of input data, javakiteconnect expects users to send a date object.