Kite Connect Node JS Ticker library Issue With Ticker Subscribed Data

AakashK
We are not getting all Subscribed data from ticker at every Websocket tick response

Here is the code

const getTrendingStocksAndInitiateTiker = async (access_token) => {
return new Promise((resolve, reject) => {
// tickerStocksArray = [];
tickerStocksArray = [256265];
tickerStockDetails[256265] = {symbol: "NIFTY 50", name: "NIFTY 50" , exchange : 'NSE'}
stocksModel.find({ tradingsymbol : { $in: defaultTrendingStockArray }}, (error, stocks) => {
if (error)
return reject({ status: 400 , message: error.message })
for(let stock of stocks){
tickerStocksArray.push(parseInt(stock.instrument_token));
tickerStockDetails[stock.instrument_token] = { symbol: stock.tradingsymbol, name: stock.name , exchange : stock.exchange }
}
if (!!ticker)
ticker.disconnect();
ticker = new KiteTicker({
api_key: process.env.KITE_API_KEY,
access_token: access_token,
debug:true
});
tickerIntiate(ticker);
resolve(true);
})
})
}

const tickerIntiate = (ticker) => {
// set autoreconnect with 10 maximum reconnections and 5 second interval
if(!!ticker)
ticker.disconnect();
console.log('reinitiating ticker')
ticker.autoReconnect(true, 10, 5)
ticker.connect();
ticker.on("ticks", onTicks);
ticker.on("connect", subscribe);
ticker.on("noreconnect", function() {
console.log("noreconnect");
});
ticker.on("error", function(error) {
console.log('error',error);
});
ticker.on("close", function() {
console.log("trending ticker closed connection");
});
ticker.on("disconnect", function(error) {
console.log("trending ticker disconnecting with error",error);
});
ticker.on("reconnect", function(reconnect_count, reconnect_interval) {
console.log("Reconnecting: trending error attempt - ", reconnect_count, " interval - ", reconnect_interval);
});
}

const onTicks = (ticks) => {
updatedTicks = ticks
}

const subscribe = () => {
var items = tickerStocksArray;//[738561];//instruments;//[738561];
ticker.subscribe(items);
ticker.setMode(ticker.modeFull, items);
}
Tagged:
  • rakeshr
    We are not getting all Subscribed data from ticker at every Websocket tick response
    We didn't get you. Do you mean you are getting tick data for only one instrument i.e when here you have subscribed to 2 instruments?
    var items = tickerStocksArray;//[738561];//instruments;//[738561];
    ticker.subscribe(items);
    Also, you will receive a tick for a subscribed instrument only if there are changes in any tick field.
  • AakashK
    //[738561];//instruments;//[738561]; this is commented code to indicate that to what do be passed in but var items = tickerStocksArray; In this tickerStocksArray we are passing 50 instrument token we are not getting all tick data
  • AakashK
    @rakeshr Please reply
  • sujith
    @AakashK,
    You can check out Websocket queries on FAQs.
Sign In or Register to comment.