Bug in method: getHistoricalData()?

xida
xida edited May 2018 in Java client
If you take a look at lines 595-600 of class KiteConnect.java here

public HistoricalData getHistoricalData(Date from, Date to, String token, String interval, boolean continuous) throws KiteException, IOException, JSONException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Map<String, Object> params = new HashMap<>();
params.put("from", format.format(from));
params.put("to", format.format(to));
params.put("continuous", continuous ? 1 : 0);
...

The code at 596 converts the Date objects from and to into "yyyy-MM-dd HH:mm:ss". This however, is done without taking the time zone into consideration. This is wrong because date objects by definition are timezone aware. While the code at 596 overlooks their timezones.

Thus in my code if I send the date objects corresponding to the present time and 2 hours earlier in the following manner:
			Date from = new Date(System.currentTimeMillis()-2*1000*60*60);
Date to = new Date(System.currentTimeMillis());
This goes wrong because Indian exchanges work on IST. The server's time -- without taking timezone into consideration -- is converted into "yyyy-MM-dd HH:mm:ss" is anachronous.

For example. My server runs on UTC. So if I want to get the latest candle, then I can not just send the date object created on current time. Instead I have to add an offset of UTC+5.30 to my current time so that the Zerodha API gets the correct IST based time in"yyyy-MM-dd HH:mm:ss".
			Date from = new Date(System.currentTimeMillis()+330*1000*60-2*1000*60*60);
Date to = new Date(System.currentTimeMillis()+330*1000*60);
This can be fixed if the TimeZone of the date objects from and to is taken into consideration
in line 596.
  • xida
    This bug can be fixed by adding the line
    format .setTimeZone(TimeZone.getTimeZone("GMT+0530"));
    after SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); at 597
  • sujith
    We will look into this.
  • sujith
    It doesn't matter. You don't need to pass timezone to fetch historical data.
    You were not getting data because you didn't set the continuous flag to true.
This discussion has been closed.