Key takeaways
- REST polling APIs fail during high-volatility market opens; asynchronous WebSockets are mandatory for live trading execution.
- NSE tick data is streamed as compact binary packets, requiring efficient struct unpacking and bitwise decoding in Python.
- Level 2 market depth streams provide real-time bid-ask queues, allowing execution algorithms to calculate dynamic order book imbalance.
- High-throughput time-series databases (TimescaleDB, Redis, QuestDB) persist tick-level data for post-trade slippage analysis.
In systematic quantitative trading, data latency and integrity are paramount. If an execution algorithm receives market prices delayed by even 500 milliseconds, or if a sudden volatility spike drops network packets, algorithmic fills suffer severe slippage.
Many retail quants and emerging funds rely on standard REST polling APIs (e.g., polling an exchange or broker endpoint every second).
During market opens or major RBI monetary policy announcements, REST servers choke under traffic, returning rate-limit errors (HTTP 429) or stale cached quotes.
Institutional quantitative desks build High-Throughput Asynchronous WebSocket Streaming Pipelines to ingest, decode, and store live tick data across thousands of NSE equity and derivative instruments.
Decoding Binary Tick Packets: Struct vs JSON
High-throughput brokers (such as Zerodha Kite, Dhan, or institutional FIX gateways) do not transmit tick data in human-readable JSON. JSON is too bandwidth-intensive and introduces massive string parsing overhead.
Instead, ticks are transmitted as compact binary byte arrays:
- A single market packet consists of a 44-byte or 184-byte binary payload containing instrument token, last traded price (multiplied by 100 as an integer), traded quantity, and 5 levels of market depth.
- Using Python’s native struct module, the decoder unpacks binary data into memory in microseconds:
```python
import struct
Unpack token, ltp, last_quantity, volume
token, ltp, qty, vol = struct.unpack(“>IIII”, packet[0:16]) real_price = ltp / 100.0 ```
Level 2 Market Depth and Order Book Imbalance
Beyond the last traded price (LTP), the most valuable short-term predictive signal in cash equities is Order Book Imbalance (OBI):
The pipeline continuously reconstructs the top 5 bids and asks: $$\text{OBI} = \frac{\sum_{i=1}^{5} Q_{\text{bid}, i} - \sum_{i=1}^{5} Q_{\text{ask}, i}}{\sum_{i=1}^{5} Q_{\text{bid}, i} + \sum_{i=1}^{5} Q_{\text{ask}, i}}$$ When OBI surges above +0.65, buy pressure heavily outweighs sell liquidity, signaling favorable execution conditions for accumulation algorithms.
Columnar Time-Series Storage: ClickHouse and QuestDB
Storing millions of daily ticks for the entire NSE universe requires high-performance columnar time-series storage: - Traditional relational databases (PostgreSQL, MySQL) collapse under the write load of 50,000 writes/second. - Columnar engines (ClickHouse, QuestDB) compress time-series data using gorilla and double-delta compression, allowing instantaneous historical queries across billions of ticks for backtesting execution slippage.
By engineering low-latency WebSocket pipelines and columnar storage, quantitative desks build institutional trading infrastructure capable of capturing persistent alpha in fast-moving Indian markets.
To explore how data feeds integrate with factor models, read our guide on Building an Institutional Python Backtesting Engine and Quantitative Factor Models in Indian Equities.
Frequently asked questions
What is the difference between Level 1, Level 2, and Level 3 market data on the NSE?
Level 1 data provides the best bid and ask price with traded volume. Level 2 (L2) data provides the top 5 bids and asks with corresponding quantities (standard market depth). Level 3 (L3 / tick-by-tick) provides individual order additions, modifications, and cancellations across the entire order book, typically accessible only via direct exchange co-location.
Why is asynchronous programming (asyncio) essential for Indian market data pipelines?
During market openings, the NSE generates tens of thousands of tick updates per second across cash and derivative contracts. Synchronous blocking code causes buffer overflows and network packet drops. Asynchronous event loops (`asyncio` / `aiohttp`) ingest network streams without blocking strategy computation.
How should tick data be stored efficiently without consuming terabytes of disk space?
Desks use specialized columnar time-series databases (such as QuestDB, ClickHouse, or TimescaleDB) that utilize delta-of-delta timestamp compression and Gorillas floating-point compression, reducing raw tick storage footprints by over 80%.