Best way to retrieve last price of multiple instruments

Dear @rakeshr,

Could you please advice on what is the best way forward to subscribe and retrieve last price of multiple instruments? I have added the following line to subscribe to multiple instruments -

var items = [15020290, 15020034, 877057]; //NIFTY23NOV19600PE, NIFTY23NOV19600CE, TATAPOWER
ticker.setMode(ticker.modeLTP, items);

but in the function onTicks(ticks) {
console.log("NIFTY23NOV19600PE: " + ticks[0].last_price + " NIFTY23NOV19600CE: " + ticks[1].last_price + " TATAPOWER: " + ticks[2].last_price);

I'm randomly getting the following error: TypeError: Cannot read properties of undefined (reading 'last_price')

Thanks very much!
  • sujith
    You won't receive ticks for all tokens in every on_tick. Kite Ticker only sends info when there is a change in any of the params. You can know more about it on FAQs.
  • DM2290
    Got it! Thanks @sujith!

    But then how can I read ticks specific to an instrument? Given that I have subscribed to 3 instruments, ticks[1] might not refer to the 2nd instrument I had subscribed to, right?
  • sujith
    Only first tick you receive will be a cached tick. Post that you will only receive ticks when there is a change in any of the params. You can verify instrument token in each item.
Sign In or Register to comment.