Unable to get NIFTY 50 ticks using java client 3.4.0

er_surendra_sharma
Hi,

I have subscribed for NIFTY 50 in tick provider. But tick provider is not giving any tick value. I appreciate if someone can help me on this.
Below is code snippet
1. Get token on NIFTY 50
List instruments = this.kiteConnect.getInstruments(Constants.EXCHANGE_NSE);
LOG.info("NSE Exchange list");
for (Instrument instrument : instruments) {
if(instrument.tradingsymbol.equalsIgnoreCase("NIFTY 50")) {
LOG.info("Token added is " + instrument.instrument_token + " for " + instrument.tradingsymbol);
this.tokenToSymbol.put(instrument.instrument_token, instrument.tradingsymbol);
this.tokens.add(instrument.instrument_token);
}
}
Corresponding logs
2024-10-03 11:01:23,914 [http-nio-8080-exec-3] INFO java.lang.Class - NSE Exchange list
2024-10-03 11:01:23,915 [http-nio-8080-exec-3] INFO java.lang.Class - Got instruments list
2024-10-03 11:01:23,915 [http-nio-8080-exec-3] INFO java.lang.Class - Token 256265, trading symbol NIFTY 50 and name NIFTY 50
2024-10-03 11:01:23,919 [http-nio-8080-exec-3] INFO java.lang.Class - Token added is 256265 for NIFTY 50



2. After connecting ticker, subscribed and set mode

tickerProvider.connect();

/** You can check, if websocket connection is open or not using the following method.*/
boolean isConnected = tickerProvider.isConnectionOpen();
LOG.info("Ticker connection status: " + isConnected);
if(tokens != null && !tokens.isEmpty()) {
LOG.info("Token to subscribe=" + tokens.get(0));
if (LOG.isInfoEnabled()) {
LOG.info("Subscribed for "+ tokens.size());
}
tickerProvider.subscribe(tokens);
tickerProvider.setMode(tokens, KiteTicker.modeLTP);
}
Corresponding logs
2024-10-03 11:01:24,059 [ReadingThread] INFO java.lang.Class - ==Connected at 2024-10-03T11:01 ==
2024-10-03 11:01:24,060 [http-nio-8080-exec-3] INFO java.lang.Class - Ticker connection status: true
2024-10-03 11:01:24,065 [http-nio-8080-exec-3] INFO java.lang.Class - Token to subscribe=256265
2024-10-03 11:01:24,065 [http-nio-8080-exec-3] INFO java.lang.Class - Subscribed for 1

3. On tick invocation
private final class OnTicksImpl implements OnTicks {
@Override
public void onTicks(ArrayList ticks) {
if (ticks != null && !ticks.isEmpty()) {
// some logic
} else {
LOGGER.info("Ticks are empty");
}
Corresponding logs
2024-10-03 11:01:27,040 [ReadingThread] INFO java.lang.Class - Ticks are empty
2024-10-03 11:01:30,040 [ReadingThread] INFO java.lang.Class - Ticks are empty
2024-10-03 11:01:33,040 [ReadingThread] INFO java.lang.Class - Ticks are empty
2024-10-03 11:01:36,040 [ReadingThread] INFO java.lang.Class - Ticks are empty
2024-10-03 11:01:39,041 [ReadingThread] INFO java.lang.Class - Ticks are empty
Sign In or Register to comment.