Web socket live feeds are getting 2-3 seconds delay

Hi @Jagdish_j_ptl,

I don’t think there is any issue with live feed delay. I’m pasting below screenshot for info:

I took the same timestamp & instrument example of yours, here’s how to interpret:

uts => currentTs (a.k.a upstoxTimeStamp) coming as part of every payload
rts => receivedTimeStamp (system time, depends on which time server your OS is synced to, in my case since I’m using MacOS, it will be time.apple.com)
ltt => lastTradedTime (time traded at source)

Upstox themselves have 300-400 ms difference w.r.t LTT (which is on the higher side, for all computation & scaling/distribution reasons). If you look at rts & uts, rts says system received faster than what Upstox payload received, which cannot be (this proves that the time sync servers that we use have variations [it varies upto 500-600ms, generally on day-to-day, nobody cares about this])

In your case, there could be 2 possibilities:

  1. Your log prints are directly running on receiving thread and blocking the socket (which is getting queued up, probably) and causing more OS thread context switches.
  2. Your time sync server has couple of seconds variation compared to what NSE/Upstox server are using.

FYI, I’ve tested with streaming more than 3000 instruments and I don’t see any frustrating lag (only negligible like 50-60 ms, with CPU usage peaking hardly 3-5%). Check your CPU usage too while running your program.