websocket streaming

glob_arber
glob_arber edited March 2018 in Java client
I've been getting this strange behaviour when trying to stream prices from websocket.
It gets price for the first time and no updates after that.

I'm getting the same output when upgrading to kiteconnect3 API.

Please advise.

output:
TKN : 14598402 O:10345.0 H:10396.0 L:10330.05 C:10384.5 LTP:10384.5 LTQ75.0 PRC_CHNG0.0
BUY Depth : 0:0.0,0:0.0,0:0.0,0:0.0,0:0.0
SELL Depth : 0:0.0,0:0.0,0:0.0,0:0.0,0:0.0

Here is the tickerUsage() method:
public void tickerUsage(KiteConnect kiteConnect, final ArrayList<Long> tokens) throws IOException, WebSocketException, KiteException {

final KiteTicker tickerProvider = new KiteTicker(kiteConnect);
tickerProvider.setOnConnectedListener(new OnConnect() {
@Override
public void onConnected() {
try {

tickerProvider.subscribe(tokens);
tickerProvider.setMode(tokens, KiteTicker.modeFull);
} catch (IOException e) {
e.printStackTrace();
} catch (WebSocketException e) {
e.printStackTrace();
}catch (KiteException ke){
ke.printStackTrace();
}
}
});

tickerProvider.setOnTickerArrivalListener(new OnTick() {
@Override
public void onTick(ArrayList<Tick> ticks) {
//Parsing tick
for (Tick obj:ticks) {
System.out.println("TKN : "+obj.getToken()+"\tO:"+obj.getOpenPrice()+"\tH:"+obj. getHighPrice()+"\tL:"+obj.getLowPrice()+" \tC:"+obj.getClosePrice()+"\tLTP:"+obj.getLastTradedPrice()+"\tLTQ"+obj.getLastTradedQuantity()+"\tPRC_CHNG"+obj.getNetPriceChangeFromClosingPrice());


java.util.Map<java.lang.String,java.util.ArrayList<Depth>> d = obj.getMarketDepth();
String buy = "buy";
String sell = "sell";

int buy_d1 = d.get(buy).get(0).getOrders();
int buy_d2 = d.get(buy).get(1).getOrders();
int buy_d3 = d.get(buy).get(2).getOrders();
int buy_d4 = d.get(buy).get(3).getOrders();
int buy_d5 = d.get(buy).get(4).getOrders();

double buy_p1 = d.get(buy).get(0).getPrice();
double buy_p2 = d.get(buy).get(1).getPrice();
double buy_p3 = d.get(buy).get(2).getPrice();
double buy_p4 = d.get(buy).get(3).getPrice();
double buy_p5 = d.get(buy).get(4).getPrice();


int sell_d1 = d.get(sell).get(0).getOrders();
int sell_d2 = d.get(sell).get(1).getOrders();
int sell_d3 = d.get(sell).get(2).getOrders();
int sell_d4 = d.get(sell).get(3).getOrders();
int sell_d5 = d.get(sell).get(4).getOrders();

double sell_p1 = d.get(sell).get(0).getPrice();
double sell_p2 = d.get(sell).get(1).getPrice();
double sell_p3 = d.get(sell).get(2).getPrice();
double sell_p4 = d.get(sell).get(3).getPrice();
double sell_p5 = d.get(sell).get(4).getPrice();

System.out.println("BUY Depth : "+buy_d1+":"+buy_p1+","+buy_d2+":"+buy_p2+","+buy_d3+":"+buy_p3+","+buy_d4+":"+buy_p4+","+buy_d5+":"+buy_p5);

System.out.println("SELL Depth : "+sell_d1+":"+sell_p1+","+sell_d2+":"+sell_p2+","+sell_d3+":"+sell_p3+","+sell_d4+":"+sell_p4+","+sell_d5+":"+sell_p5);
}
}
});

tickerProvider.setTryReconnection(true);
tickerProvider.setTimeIntervalForReconnection(5);
tickerProvider.setMaxRetries(10);
tickerProvider.connect();

//boolean isConnected = tickerProvider.isConnectionOpen();
//System.out.println(isConnected);
tickerProvider.setMode(tokens, KiteTicker.modeFull);

//tickerProvider.unsubscribe(tokens);
//tickerProvider.disconnect();
}
  • glob_arber
    The timestamps also look wrong.
    last price 10384.5
    open interest 14,336,025
    day high OI 17,676,900
    day low OI 14,324,325
    change -0.081
    tick timestamp Thu Feb 22 15:30:00 IST 2018
    tick timestamp date Thu Feb 22 15:30:00 IST 2018

    Looks like its pointing to a wrong price server ?
    Please advise when you get a chance.
  • sujith
    Can you mention the instrument token that you are using?
  • sujith
    We can't find this in today's instrument file. I would suggest using latest instrument dump.
  • sujith
    14598402 is not there in today's instrument dump.
  • glob_arber
    scratch that.
    The token is for Feb NIFTY FUT contract..that's the reason for the timestamp.
    Thanks for your help.
This discussion has been closed.