How to use same request token for whole day ??

aakashps1995
Every time i need to generate new requestToken then restart my application,
that's why my application not properly working,
Please reply how can i use same request token for whole day..
  • cisk
    Why generate request token again and again for the whole day? Once you get "access token" using your request token, use it for the entire trading session, valid for the day. You only have to generate new access token everyday(trading session from 9.15am to 3.30pm) manually
  • aakashps1995
    @cisk, please see this code and tell me what is my fault
    //------------------------------------------------------------//
    public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub

    try {

    String apiKey = "";
    String clientId = "";
    String apiSecret = "";
    String requestToken = "";

    KiteConnect kiteConnect = new KiteConnect(apiKey);
    kiteConnect.setUserId(clientId);

    kiteConnect.registerHook(new SessionExpiryHook() {
    @Override
    public void sessionExpired() {
    System.out.println("session expired");
    }
    });

    UserModel userModel = kiteConnect.requestAccessToken(requestToken, apiSecret);
    kiteConnect.setAccessToken(userModel.accessToken);
    kiteConnect.setPublicToken(userModel.publicToken);

    String stock1 = "INFY";

    Quote quote1 = kiteConnect.getQuote("NSE", stock1);
    System.out.println(quote1.lastPrice);

    } catch (KiteException e) {
    System.out.println(e.message+" "+e.code+" "+e.getClass().getName());
    } catch (JSONException e) {
    e.printStackTrace();
    }


    }

    //------------------------------------------------------------/
  • sujith
    @aakashps1995,
    Don't call the requestAccessToken method every time you run the app.
    Once you get access token, store it and re-use it for subsequent runs.
Sign In or Register to comment.