Java WebSocket Example

sriks6711
I want to get live prices of instruments (every 1-second tick) and clearly, using WebSocket streaming is the way to go. I am using Java and downloaded the JAR and got the IDE setup and am able to connect to Kite programmatically, execute orders and such but when I come to using WebSockets, am stumped. Here is what is happening, or rather not happening -

In Test.java, this is the code in line#128-130:
ArrayList tokens = new ArrayList<>();
tokens.add(Long.parseLong("256265"));
examples.tickerUsage(kiteConnect, tokens);

The output am seeing after a lot of debug is:
[true]

I have gone through the code in Examples.java and the "true" is being printed out because of code in line#472 and line#473:
boolean isConnected = tickerProvider.isConnectionOpen();
System.out.println(isConnected);

It seems that connection is established but am not able to see the output am expecting to see via tickerProvider.setOnTickerArrivalListener() which should print the last price, open interest, day high OI etc.

Am I missing something? Am I doing something wrong?
Tagged:
  • sujith
    The example demonstrates the usage of Kite Ticker. It demonstrates connecting, subscribing, setting mode, unsubscribe, disconnect Kite Ticker. You need to comment out unsubscribe and disconnect/close to keep receiving tick data.
  • sriks6711
    Thank you for the response. Will follow your suggestion and keep you posted
  • sriks6711
    Got the output I expected to see - even on a Saturday which wonderfully is a mock trading day by luck. Thank you @sujith
This discussion has been closed.