@Daljit_singh I Also faced this issue, the websocket feed has two important timestamp information that helped me filter out things…
currentTs : The timestamp of the tick itself, i use it to filter the market hours live ticks
tick_ts_ms = int(data['currentTs'])
# Convert tick ts (e.g. 1746157500000) to datetime (rounded to minute)
tick_ts = tick_ts_ms / 1000 # e.g., 1746157561414
tick_dt = datetime.fromtimestamp(tick_ts)
#Skip Before 9:15:00
if tick_dt.hour < 9 or (tick_dt.hour == 9 and tick_dt.minute < 15):
return
# Skip if after 15:30:01
if tick_dt.hour > 15 or (tick_dt.hour >= 15 and tick_dt.minute >= 30):
return
ltt : The last traded time of the instrument.
I keep storing the the last processed ltt for instruments and only if the ltt changes i process the tick. This helps me avoid duplication in my data…also helps in less storage usage.
ltt = int(ltpc.get("ltt", 0))
second_ts = ltt // 1000
last_sec = last_processed_second[instrument_key]
if last_sec != -1 and second_ts > last_sec:
#Process here
store_data()
#Update the last processed second
last_processed_second[instrument_key] = second_ts
There is one more check you can make, some instruments may remain illiquid for the day and may not have a ltt of today, you may want to avoid them also. So from one of my initial tick, I set a variable current session date. If the tick date for today doesnt match with the date from ltt i do not process that data for that intrument.
ltt_dt = datetime.fromtimestamp(ltt / 1000).date()
if ltt_dt != current_session_date:
#Stale Tick, skip...
continue