src/utils/zerodha/zerodha-event.utils.ts
ZerodhaEventProcessor (exported as zerodhaEvent) is the core market data engine.
Lifecycle
Tick pipeline
zerodhaConnectionreceives raw Kite tickprocessTick()routes by instrument token → index + segment (cash/futures/options)- Aggregates into
latestSnapshotDataper index - Every 1000ms (
BROADCAST_INTERVAL_MS),broadcastAll():- Emits
io.emit(\$TickData`, payload)` to Socket.IO clients - Emits
marketDataEmitterforlatestDataMapstorage
- Emits
Strike calculation
For options:- Computes base value and CALL/PUT strikes from tick LTP
- Subscribes/unsubscribes option leg tokens dynamically
- Uses
optionChainByExpiryfrom index settings
Segment support
Trading engine input
Controllers read processed snapshots fromlatestDataMap (via socket manager) for recurring buy / trailing sell decisions.