It looks like you're new here. If you want to get involved, click one of these buttons!
public void tickerUsage(KiteConnect kiteconnect) throws IOException,
WebSocketException {
/**
* To get live price use com.rainmatter.ticker 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.
*/
final ArrayList tokens = new ArrayList<>();
/* Iterator<String> token = stockMap.keySet().iterator();
while(token.hasNext()){
tokens.add(token.next().replaceAll(" ", ""));
}
final ArrayList tokens = new ArrayList<>();*/
tokens.add(53287175);
final 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();
}
}
});
tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
@Override
public void onDisconnected() {
// your code goes here
}
});
tickerProvider.setOnTickerArrivalListener(new OnTick() {
@Override
public void onTick(ArrayList<Tick> ticks) {
// System.out.println(ticks.size());
System.out.println("Close Price"+ticks.get(0).getLastTradedPrice());
Tick tick = ticks.get(0);
double closePrice = ticks.get(0).getLastTradedPrice();
double openPrice = ticks.get(0).getOpenPrice();
double highPrice = ticks.get(0).getHighPrice();
double lowPrice = ticks.get(0).getLowPrice();
double volume = ticks.get(0).getVolumeTradedToday();
//if((closePrice-lowPrice)/(highPrice-lowPrice)>0.95){
System.out.println(stockMap.get(tick.getToken()));
//}
}
});
/** connects to com.rainmatter.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);
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This instrument token(53287175) doesn't seem to be existing. Can you let us know for which scrip you are trying?
Use latest instruments dump to get instrument tokens.