TypeError: Cannot read properties of undefined (reading 'apply')


the socket works for 2-3 mins than randomly stops
with this error, i subbed to bnf future
Not able to understand what is going wrong
node js code for refrence

ticker.on("ticks", onTicks);

async function onTicks(data1) {
try {
const data = data1[0];

if (!data) {
console.error("Received empty data array.");

const symbol = data.instrument_token.toString();
const parsedData = await parseSymbol(symbol);

const lotSize = symbolDataLot[parsedData.script] || null;

symbolData[parsedData.symbol] = {
ltp: data.last_price,
high_price: data.ohlc.high,
low_price: data.ohlc.low,
open_price: data.ohlc.open,
ch: data.change.toFixed(2),
chp: data.change.toFixed(2),
bid_price: data.depth.buy.length > 0 ? data.depth.buy[0].price : null,
ask_price: data.depth.sell.length > 0 ? data.depth.sell[0].price : null,
exch_feed_time: data.exchange_timestamp,
lotSize: lotSize,

if (subscriptions[parsedData.symbol]) {
subscriptions[parsedData.symbol].forEach(socketId => {
io.to(socketId).emit('dataUpdate', symbolData[parsedData.symbol]);
console.log(`Updated data sent for ${parsedData.symbol} to socket ${socketId}`);
} catch (error) {
console.error(`Error processing message: ${error}`);

function subscribe(item) {
item = parseInt(item); // Convert item to an integer
var items = [item]; // Create an array with the integer item
ticker.subscribe(items); // Subscribe with the array of integers
ticker.setMode(ticker.modeFull, items); // Set the mode with the array of integers
Sign In or Register to comment.