Tick Data for Nifty 50

sara_u
Hi there,

This is my code, for nifty 50 the token is 256265 so I set to get the ticks but the tick size is always 0.

public void monitorCondor() throws WebSocketException, IOException, KiteException {
KiteConnect kiteConnect = new KiteConnect("xyz");
kiteConnect.setAccessToken("xxxxxxx");
kiteConnect.setPublicToken("yyyyyy");
ArrayList tokens = new ArrayList<>();
tokens.add(Long.parseLong("256265"));
tickerUsage(kiteConnect, tokens);

}
tickerUsage is the same as java client code.

I am not getting any ticks, the listener is not getting triggered.
your help is appreciated.
  • sujith
    Please go through the code and understand what you are trying to implement. You need to look into the ticker usage code.
    These examples are meant to demonstrate usage, not just copy-paste.
  • sara_u
    sara_u edited May 2020
    Thanks sujit, I am trying to get Nifty updates from ticker have seen that the Instrument token is 256265

    this is the listener that I am expecting to call back
    @RequestMapping(path = "/monitor", produces = "application/json; charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public void monitorCondor() throws WebSocketException, IOException, KiteException {
    KiteConnect kiteConnect = new KiteConnect("xxxx");
    kiteConnect.setAccessToken("xxxx");
    kiteConnect.setPublicToken("xxxx");
    ArrayList tokens = new ArrayList<>();
    tokens.add(Long.parseLong("256265"));
    tickerUsage(kiteConnect, tokens);

    }
    public void tickerUsage(KiteConnect kiteConnect, ArrayList tokens) throws IOException, WebSocketException, KiteException {

    tickerProvider.setOnTickerArrivalListener(new OnTicks() {
    @Override
    public void onTicks(ArrayList ticks) {
    NumberFormat formatter = new DecimalFormat();
    System.out.println("ticks size "+ticks.size());
    if(ticks.size() > 0) {
    System.out.println("open::"+ticks.get(0).getOpenPrice());
    System.out.println("close::"+ticks.get(0).getClosePrice());
    System.out.println("high::"+ticks.get(0).getHighPrice());
    System.out.println("low::"+ticks.get(0).getLowPrice());
    }
    }
    });

    }

    We are expecting this listener to be invoked for every updates ...
    We are calling this API in 1 minute interval time to get 1-minute updates. Please let me know is that right?
  • sara_u
    got it

    // Unsubscribe for a token.
    tickerProvider.unsubscribe(tokens);

    // After using com.zerodhatech.com.zerodhatech.ticker, close websocket connection.
    tickerProvider.disconnect();

    these 2 lines are the ones ... anyways thanks for looking into it.
This discussion has been closed.