Tick data listener not working

sara_u
sara_u edited May 2020 in Java client
Hi there,

I was getting the Tick data for Nifty 50 but suddenly the listener is not working.
Not sure where the issue is, do we get the tick data only during market hours?

Here is the code!!
public Double getMarketCurrentPriceforNifty(KiteConnect kiteConnect) throws WebSocketException, IOException, KiteException {
final KiteTicker tickerProvider = new KiteTicker(kiteConnect.getAccessToken(), kiteConnect.getApiKey());
ArrayList<Long> tokens = new ArrayList<>();
try {
tokens.add(Long.parseLong("256265"));
tickerUsage(kiteConnect, tokens, tickerProvider);
} finally {
// Unsubscribe for a token.
tickerProvider.unsubscribe(tokens);
// After using com.zerodhatech.com.zerodhatech.ticker, close websocket connection.
tickerProvider.disconnect();
}
//setting this to test the logic
//setNiftyPrice(9199.05);
return niftyPrice;
}


public void tickerUsage(KiteConnect kiteConnect, ArrayList<Long> tokens, KiteTicker tickerProvider) throws IOException, WebSocketException, KiteException {

tickerProvider.setOnConnectedListener(new OnConnect() {
@Override
public void onConnected() {
/** Subscribe ticks for token.
* By default, all tokens are subscribed for modeQuote.
* */
tickerProvider.subscribe(tokens);
tickerProvider.setMode(tokens, KiteTicker.modeLTP);
}
});

tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
@Override
public void onDisconnected() {
// your code goes here
}
});

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

/** Set error listener to listen to errors.*/
tickerProvider.setOnErrorListener(new OnError() {
@Override
public void onError(Exception exception) {
//handle here.
}

@Override
public void onError(KiteException kiteException) {
//handle here.
}

@Override
public void onError(String error) {
System.out.println(error);
}
});

tickerProvider.setOnTickerArrivalListener(new OnTicks() {
@Override
public void onTicks(ArrayList<Tick> ticks) {
NumberFormat formatter = new DecimalFormat();
System.out.println("ticks size "+ticks.size());
if(ticks.size() > 0) {
niftyPrice = Double.isNaN(ticks.get(0).getLastTradedPrice())?0.0:ticks.get(0).getLastTradedPrice();
System.out.println("LTP:"+niftyPrice);
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());
}
}
});
// Make sure this is called before calling connect.
tickerProvider.setTryReconnection(true);
//maximum retries and should be greater than 0
tickerProvider.setMaximumRetries(10);
//set maximum retry interval in seconds
tickerProvider.setMaximumRetryInterval(30);

/** connects to com.zerodhatech.com.zerodhatech.ticker server for getting live quotes*/
tickerProvider.connect();

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


tickerProvider.setMode(tokens, KiteTicker.modeLTP);


}
  • sara_u
    please let me know is there any issues in here .
  • sara_u
    @Sujit, can you please help with this is there any issues with Ticks today?
  • sujith
    You won't get feeds once markets close.
  • PR5151
    PR5151 edited May 2020
    Is there any chance we can get LTP of 10 symbol per second, if we use multi threading concept? does kite connect support to handle concurrent request?
Sign In or Register to comment.