InputException while receiving Historical Market Data

debon1410
debon1410 edited July 27 in Java client
Hi All,
I am new to Zerodha API - I was trying to fetch historical data - and receiving the below error :
Exception in thread "main" com.zerodhatech.kiteconnect.kitehttp.exceptions.InputException
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:54)
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:20)
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.getRequest(KiteRequestHandler.java:69)
at com.zerodhatech.kiteconnect.KiteConnect.getHistoricalData(KiteConnect.java:732)
at Examples.getHistoricalData(Examples.java:68)
at userConnect.main(userConnect.java:50)
-------------------------------------------------------------------------------------------------
Below is my code (Copied from GitHub Example):
  /** Get historical data for an instrument.*/
public void getHistoricalData(KiteConnect kiteConnect) throws KiteException, IOException {
/** Get historical data dump, requires from and to date, intrument token, interval, continuous (for expired F&O contracts), oi (open interest)
* returns historical data object which will have list of historical data inside the object.*/
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date from = new Date();
Date to = new Date();
try {
from = formatter.parse("2019-09-20 09:15:00");
to = formatter.parse("2019-09-20 15:30:00");
}catch (ParseException e) {
e.printStackTrace();
}
HistoricalData historicalData = kiteConnect.getHistoricalData(from, to, "54872327", "15minute", false, true);
System.out.println(historicalData.dataArrayList.size());
System.out.println(historicalData.dataArrayList.get(0).volume);
System.out.println(historicalData.dataArrayList.get(historicalData.dataArrayList.size() - 1).volume);
System.out.println(historicalData.dataArrayList.get(0).oi);
}

-------------------------------------------------------------------------------------------------------------
Note : I am Subscribed to Historical Data -



Can someone help.

  • sujith
    One has to re-login after subscribing to historical data, in order to use it.
  • debon1410
    I Subscribed yesterday for the data - Today I have logged out and in multiple time.

    How to test if my subscription is working or not. Please help.
  • sujith
    Your subscription seems fine. Can you run in debug mode and paste the complete stack trace here?
    Make sure to remove app and client-specific tokens.
  • debon1410
    below is the logs - I masked the authorization token
    -----------------------------------------------------------------------
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: --> GET https://api.kite.trade/instruments/historical/54872327/15minute?continuous=0&from=2019-09-20 09:15:00&oi=1&to=2019-09-20 15:30:00
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: User-Agent: javakiteconnect/3.0.0
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: X-Kite-Version: 3
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: Authorization: token xxxxxxxxxxxxx:xxxxxxxxxxxxxxxx
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: --> END GET
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: <-- 400 https://api.kite.trade/instruments/historical/54872327/15minute?continuous=0&amp;from=2019-09-20 09:15:00&amp;oi=1&amp;to=2019-09-20 15:30:00 (75ms)
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: date: Mon, 27 Jul 2020 10:22:59 GMT
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: content-type: application/json
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: content-length: 91
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: set-cookie: __cfduid=d0b544e640bb2892d8a23483ee2f638211595845379; expires=Wed, 26-Aug-20 10:22:59 GMT; path=/; domain=.kite.trade; HttpOnly; SameSite=Lax
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: cf-cache-status: DYNAMIC
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: cf-request-id: 0431651beb0000899d3c254200000001
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: strict-transport-security: max-age=15552000; includeSubDomains
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: server: cloudflare
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: cf-ray: 5b95a473190f899d-MAA
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO:
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: {"status":"error","message":"contract not found","data":null,"error_type":"InputException"}
    Jul 27, 2020 3:52:58 PM okhttp3.internal.platform.Platform log
    INFO: <-- END HTTP (91-byte body)
    Exception in thread "main" com.zerodhatech.kiteconnect.kitehttp.exceptions.InputException
    at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:54)
    at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:20)
    at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.getRequest(KiteRequestHandler.java:69)
    at com.zerodhatech.kiteconnect.KiteConnect.getHistoricalData(KiteConnect.java:732)
    at Examples.getHistoricalData(Examples.java:81)
    at userConnect.main(userConnect.java:51)
    -----------------------------------------------------------------------------------------------------------
    Hope this helps
  • sujith
    contract not found As the error message says, you seem to be fetching data for an invalid instrument.
  • debon1410
    debon1410 edited July 29
    Can you please let me know which are valid instruments - I tried "RELIANCE", "NSE:RELIANCE", "NSE-RELIANCE" - all are giving same error . I am able to fetch OHLC data with "NSE:RELIANCE " - is naming convention of historical data is different. Where do I find a list?
  • rakeshr
    @debon1410
    You need to use instrument_token not symbol for historical data fetch. Check all input param detail for Historical data APIs here.
    You can get complete instrument dump from here.
Sign In or Register to comment.