Websocket Live Price Ticker - Java

Flawless
Dear Team,

For streaming live prices, below mentioned code is given in example:-

ArrayList tokens = new ArrayList<>();
tokens.add(53287175);
KiteTicker tickerProvider = new KiteTicker(kiteconnect);
tickerProvider.setOnConnectedListener(new OnConnect() {
@Override
public void onConnected() {
try {
/** Subscribe ticks for token.
* By default, all tokens are subscribed for modeQuote.*/
tickerProvider.subscribe(tokens);
} catch (IOException e) {
e.printStackTrace();
} catch (WebSocketException e) {
e.printStackTrace();
}
}
});

I have below mentioned queries:-

1) In the above code, The live price is received in ArrayList, Is there a way to get it on a float variable and overwrite the value in the variable when new tick is received. (I am talking about value of only Last Traded Price which i want in a variable and overwrite it when new tick is received) How to do it?

2) When tick is received in ArrayList, is it received only at the arraylist object index of zero [0] or it is received also in other indexes like [1] [2] [3] etc.

3) Can i subscribe to more than one script simultaneously for streaming live prices via websocket..lets say... 2 scripts or 3 scripts?
  • sujith
    Hi,
    1) In the above code, The live price is received in ArrayList, Is there a way to get it on a float variable and overwrite the value in the variable when new tick is received. (I am talking about value of only Last Traded Price which i want in a variable and overwrite it when new tick is received) How to do it?
    Above code has only till subscribing for ticks. You get data in onTick(ArrayList ticks) callback and please go through tick data structure here. It is already available in double.
    2) When tick is received in ArrayList, is it received only at the arraylist object index of zero [0] or it is received also in other indexes like [1] [2] [3] etc.
    It can be any number based on number of tokens you have subscribed for. You can always check size and do your operation on it.
    3) Can i subscribe to more than one script simultaneously for streaming live prices via websocket..lets say... 2 scripts or 3 scripts?
    You can subscribe for multiple scrips at a time.
Sign In or Register to comment.