Not Receiving Tick Data

mrphoebs
Hi guys,

Trying to get tick data from the ticker, but I'm getting zilch.

Input tokens - Nifty 50 tokens
private void initTicker(final ArrayList tokens) throws IOException, WebSocketException {


ticker.setOnConnectedListener(new OnConnect() {
public void onConnected() {
logger.info("Kite ticker connected");
clientConnected.set(true);
try {
ticker.subscribe(tokens);
} catch (IOException e) {
e.printStackTrace();
} catch (WebSocketException e) {
e.printStackTrace();
}
ticker.setMode(tokens, KiteTicker.modeFull);
}
});

ticker.setOnDisconnectedListener(new OnDisconnect() {
public void onDisconnected() {
clientConnected.set(false);
ticker.unsubscribe(tokens);
logger.info("Kite ticker disconnected");
}
});

ticker.setOnTickerArrivalListener(new OnTick() {
public void onTick(ArrayList ticks) {
logger.info("Tick recieved {}", ticks.size());
}
});

ticker.connect();

}
  • sujith
    Hi @mrphoebs,
    Can you elaborate like is it getting connected, are you getting any exception and where are you getting tokens from?
  • mrphoebs
    mrphoebs edited March 2017
    Ticker gets connected, no exceptions, there is just no tick data.

    Got the tokens from NSE instruments and collated the list.

    NIFTY_50_TOKENS = new Long[]{22L,15083L,1270L,236L,275L,5900L,16669L,4668L,10604L,438L,2181L,526L,694L,20374L,881L,910L,4717L,1232L,7229L,1330L,1333L,1348L,1363L,1394L,4963L,14366L,5258L,29135L,1594L,1660L,1922L,11483L,10440L,2031L,10999L,11630L,2475L,14977L,2885L,3045L,3351L,3456L,16965L,3426L,3499L,11536L,13538L,11532L,3787L,11915L,3812L};

    11:33:49.202 [main] INFO com.suman.apollo.market.clients.Kite - Initializing Kite Client
    11:33:49.209 [main] TRACE com.suman.apollo.market.clients.Kite - Using Request Token
    11:33:50.336 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Kite ticker connected
    11:33:51.289 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Tick recieved 0
    11:33:52.390 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Tick recieved 0
    11:33:53.312 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Tick recieved 0
    11:33:54.262 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Tick recieved 0
    11:33:55.258 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Tick recieved 0
    11:33:56.318 [ReadingThread] INFO com.suman.apollo.market.clients.Kite - Tick recieved 0
  • sujith
    sujith edited March 2017
    @mrphoebs,
    Tokens seem to be wrong, Can you let us know where are you getting tokens from?
    Don't append L for numbers.
    For example, Nifty 50 token must look like this 256265
  • mrphoebs
    Oh, The 'L' is just there to initialise the array of Long values (your tokens are a list of Longs aren't they)

    The way I got the tokens is


    List<Instruments> nseInstruments = kiteClient.getInstruments("NSE");
    for(Instrument instrument: nseInstruments){
    System.out.println(instrument.getTradingSymbol() + " " + instrument.getExchangeToken() )
    }


    I assumed the above was an accurate way of getting token values, let me know if this is flawed. Also a pointer to how to get tokens and whether they have a lifecycle would be appreciated.
  • mrphoebs
    I'm guessing I should have used the instrumentToken rather than the exchangeToken, confirm please.
  • sujith
    @mrphoebs,
    Yes, you need to use instrument_token.
    Just to make sure we are sending numbers, we have defined tokens as long array.
    The server won't understand 265256L.
  • mrphoebs
    Yup, just sending a long array, I'm able to receive ticks with the new tokens (until the market closed ofcourse).

    Do Instrument tokens change, and how often do they change? Would you recommend deriving instrument tokens from trading symbols rather than assuming they will remain unchanged over time.

    Please advice.
  • sujith
    @mrphoebs,
    Instruments file is updated everyday. An intrument token will remain same for equity but it might be reused once an F&O contract is expired.
    It is recommended to download instruments file every day once in order to get the latest list of instruments that are being traded for the day.
    You can derive instrument token from tradingsymbol.
Sign In or Register to comment.