It looks like you're new here. If you want to get involved, click one of these buttons!
kiteLivePrice(String token, boolean subscribe) {
KiteTicker tickerProvider = tickerProviderInitialize();
ArrayList<Long> tokens = new ArrayList<>();
ArrayList<Long> tokensUnsubscribe = new ArrayList<>();
tokens.add(Long.valueOf(KiteAppConstants.NIFTYID));
if (!CommonUtils.isEmpty(token)) {
if (subscribe) {
tokens.add(Long.valueOf(token));
} else
tokensUnsubscribe.add(Long.valueOf(token));
}
tickerProvider.setOnConnectedListener(new OnConnect() {
@Override
public void onConnected() {
/**
* Subscribe ticks for token. By default, all tokens are subscribed for
* modeQuote.
*/
tickerProvider.unsubscribe(tokensUnsubscribe);
tickerProvider.subscribe(tokens);
tickerProvider.setMode(tokens, KiteTicker.modeFull);
}
});
tickerProvider.setOnTickerArrivalListener(new OnTicks() {
public void onTicks(ArrayList<Tick> ticks) {
for (Tick tick : ticks) {
PrintWriter writer = null;
try {
if (Long.valueOf(KiteAppConstants.NIFTYID).equals(tick.getInstrumentToken())) {
writer = new PrintWriter(KiteAppConstants.DATASTOREPATH + "TickerStore.txt");
writer.print(tick.getLastTradedPrice());
writer.close();
} else {
if(subscribe) {
writer = new PrintWriter(KiteAppConstants.DATASTOREPATH + "BuyTickerStore.txt");
writer.print(tick.getLastTradedPrice());
writer.close();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
});
Sample test executed:
kiteLivePrice("11308290",true);
Thread.sleep(30000);
kiteLivePrice("11308290",false);
Thread.sleep(1000);
clearBuyTickerStore(); /* Clearing text file **/
kiteLivePrice("11307522",true);
Thread.sleep(30000);
kiteLivePrice("11307522",false);
Thread.sleep(1000);
clearBuyOrderPlacedOrder();