Getting TokenException on market quote APIs

pratikmachve
KiteConnect kiteSdk = new KiteConnect("*****");

//String token = Authenticator.login();
//kiteSdk.generateSession(token, "***_secretkey");

String token = "***_previously_obtained_access_token";


List instruments = kiteSdk.getInstruments("NSE"); //Working fine

String[] instruments = {"256265"};
//String[] instruments = {"256265","NSE:INFY",};
Map resultMap = kiteSdk.getLTP(instruments); //Failing with following exception

com.zerodhatech.kiteconnect.kitehttp.exceptions.TokenException
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:48)
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:20)
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.getRequest(KiteRequestHandler.java:152)
at com.zerodhatech.kiteconnect.KiteConnect.getQuote(KiteConnect.java:732)
at com.kite.KiteBot.main(KiteBot.java:37)


I haven't subscribed to history API and I am trying to run this after market hours, getting exception on getLTP() API.
Can you pls help me understand what am I missing here? or I cannot access market quote APIs after market hours, if I haven't subscribed to history apis?
I have 2FA and I am doing a manual login.
  • sujith
    The getInstruments API isn't authenticated. The getLTP API call is authenticated by the Kite Trade. Once you obtain an access token store it and reuse it in subsequent runs for the day. Don't call generate session again.
  • pratikmachve
    Thanks Sujith, my bad, I was missing following :(

    kiteSdk.setAccessToken(accessToken);
This discussion has been closed.