Java Websocket client not giving any output

wealthfromtrading edited August 2018 in Java client
I am facing a problem while trying to get the real time quotes. I am using websocket with java library. Here is the code:
User user =  kiteConnect.generateSession(requestToken, AppConfig.apiSecret);

ArrayList<Long> tokens = new ArrayList<>();

new WebSocketConnection().tickerUsage(kiteConnect, tokens);

this tickerUsage method is nothing but copied and pasted from the Examples of the java library with a few additional log statements. Here is it for quick reference:
/** Demonstrates com.zerodhatech.ticker connection, subcribing for instruments, unsubscribing for instruments, set mode of tick data, com.zerodhatech.ticker disconnection*/
public void tickerUsage(KiteConnect kiteConnect, ArrayList<Long> tokens) throws IOException, WebSocketException, KiteException {
/** To get live price use websocket connection.
* It is recommended to use only one websocket connection at any point of time and make sure you stop connection, once user goes out of app.
* custom url points to new endpoint which can be used till complete Kite Connect 3 migration is done. */
final KiteTicker tickerProvider = new KiteTicker(kiteConnect.getAccessToken(), kiteConnect.getApiKey());

tickerProvider.setOnConnectedListener(new OnConnect() {

public void onConnected() {
/** Subscribe ticks for token.
* By default, all tokens are subscribed for modeQuote.
* */
tickerProvider.setMode(tokens, KiteTicker.modeFull);

tickerProvider.setOnDisconnectedListener(new OnDisconnect() {

public void onDisconnected() {



/** Set listener to get order updates.*/
tickerProvider.setOnOrderUpdateListener(new OnOrderUpdate() {
public void onOrderUpdate(Order order) {
System.out.println("order update "+order.orderId);

tickerProvider.setOnErrorListener(new OnError() {
public void onError(Exception exception) {

public void onError(KiteException kiteException) {

tickerProvider.setOnTickerArrivalListener(new OnTicks() {
public void onTicks(ArrayList<Tick> ticks) {
NumberFormat formatter = new DecimalFormat();
System.out.println("ticks size "+ticks.size());
if(ticks.size() > 0) {
System.out.println("last price "+ticks.get(0).getLastTradedPrice());
System.out.println("open interest "+formatter.format(ticks.get(0).getOi()));
System.out.println("day high OI "+formatter.format(ticks.get(0).getOpenInterestDayHigh()));
System.out.println("day low OI "+formatter.format(ticks.get(0).getOpenInterestDayLow()));
System.out.println("change "+formatter.format(ticks.get(0).getChange()));
System.out.println("tick timestamp "+ticks.get(0).getTickTimestamp());
System.out.println("tick timestamp date "+ticks.get(0).getTickTimestamp());
System.out.println("last traded time "+ticks.get(0).getLastTradedTime());

// Make sure this is called before calling connect.
//maximum retries and should be greater than 0
//set maximum retry interval in seconds

/** connects to server for getting live quotes*/

/** You can check, if websocket connection is open or not using the following method.*/
boolean isConnected = tickerProvider.isConnectionOpen();

/** set mode is used to set mode in which you need tick for list of tokens.
* Ticker allows three modes, modeFull, modeQuote, modeLTP.
* For getting only last traded price, use modeLTP
* For getting last traded price, last traded quantity, average price, volume traded today, total sell quantity and total buy quantity, open, high, low, close, change, use modeQuote
* For getting all data with depth, use modeFull*/
tickerProvider.setMode(tokens, KiteTicker.modeLTP);

// Unsubscribe for a token.

// After using, close websocket connection.
Now when i run the example, nothing is happening. Sometimes, i get a log statement saying "onconnected" (logged on onConnected method) but usually nothing.

Please advice
  • sujith
    Please go through the examples and try to understand before using it.
    The last two lines call unsubscribe and disconnect method of the Kite Ticker. You need to comment those two lines to get continuous streaming data.
  • wealthfromtrading
    thanks sujith. had figured this a couple of days back. thanks anyways for your time.
This discussion has been closed.