Real-Time Data Pipeline
Relevant source files
The following files were used as context for generating this wiki page:
The Real-Time Data Pipeline in OpenAlgo is a high-performance, three-layer streaming architecture designed to decouple broker-specific market data feeds from end-user delivery. It ensures that data processing is non-blocking and scalable across multiple product surfaces, including the Python Strategy Host, Flow no-code builder, and various analytical tools.
The pipeline serves as a unified interface for 35+ supported brokers, normalizing proprietary tick data into a standard format for consumption via WebSockets. This infrastructure allows strategies to remain broker-agnostic while maintaining low-latency execution.
Sources: CLAUDE.md:144-154, README.md:11-20
Architecture Overview
The pipeline is structured into three distinct layers to ensure reliability and performance.
| Layer | Component | Function |
|---|---|---|
| Ingestion | Broker Adapters | Connects to proprietary feeds and normalizes ticks. |
| Transport | ZeroMQ Bus | High-performance message bus (fan-in) decoupling feed from delivery. |
| Delivery | WebSocket Proxy | Manages client subscriptions, throttling, and fanning out data. |
Sources: CLAUDE.md:146-154, README.md:112-118
Pipeline Flow Diagram
The following diagram illustrates the flow of market data from the external broker through the OpenAlgo internals to the end client.
Sources: CLAUDE.md:146-154, README.md:112-118
Component Deep Dive
1. Broker Adapters (Ingestion)
Adapters are located in broker/*/streaming/. They are responsible for maintaining connections to the broker's proprietary WebSockets.
- Capacity: Each adapter supports
MAX_SYMBOLS_PER_WEBSOCKET(1000) acrossMAX_WEBSOCKET_CONNECTIONS(3), totaling 3000 symbols per broker. - Normalization: Ticks are converted into a standardized OpenAlgo format before being pushed to the transport layer.
- Connection Management: The
broker_factory.pymanages a single server-side broker feed (_POOLED_ADAPTERS) per user, ensuring that multiple sessions for the same user share the same underlying feed.
Sources: CLAUDE.md:104-106, CLAUDE.md:147-148, scripts/generate_broker_compatibility.py:126-146
2. ZeroMQ Bus (Transport)
The transport layer uses a ZeroMQ bus on a fixed port (default 5555).
- Fan-in Pattern: The WebSocket proxy's SUB socket binds to the port, while every publisher (broker adapters) connects to it.
- Decoupling: This ensures that a slow WebSocket client does not block the broker adapter's ingestion of new ticks.
- Invariant: Publishers must NEVER
bind(). ZMQ allows many PUBs to connect to one bound SUB, preventing port contention across processes.
Sources: CLAUDE.md:88-101, CLAUDE.md:150-151
3. WebSocket Proxy (Delivery)
The proxy runs as a separate process (typically port 8765) and handles the interface with clients.
- Subscription Management: Handles client requests for specific symbols and data types (LTP, Quote, Depth).
- Throttling: Manages the frequency of updates sent to clients to prevent network saturation.
- Product Integration: Fans out data to the
/tradingterminal,/scalpingterminal, and/toolssurface.
Sources: CLAUDE.md:153-154, README.md:28-40
WebSocket Protocol and Formats
Clients interact with the pipeline using a standardized subscription protocol.
Message Types
- LTP (Last Traded Price): Real-time price updates.
- Quote: Includes LTP, volume, and daily high/low.
- Depth: Level 2 order book data (market depth).
Sources: README.md:116-118, okf/sdk/websockets-format.md
Data Structure Examples
The pipeline uses standardized symbol formats across all brokers to ensure consistency.
| Instrument Type | Format Example |
|---|---|
| Equity | INFY, SBIN |
| Futures | BANKNIFTY24APR24FUT |
| Options | NIFTY28MAR2420800CE |
Sources: CLAUDE.md:173-180, okf/viz.html: "bodies" section
Runtime Constraints
Production environments using eventlet and gunicorn impose specific constraints on the pipeline:
- Process Isolation: The proxy often runs as a subprocess (via
install.sh) or a separate container. - Single Worker Requirement:
gunicorn -w 1is mandatory because Flask-SocketIO state is in-process and cannot be shared across multiple workers. - Shared Feed Invariant: Multi-session logins must not tear down the shared broker feed. Teardowns are gated on actual token changes to prevent FINVASIA/Shoonya session churn.
Sources: CLAUDE.md:78-85, CLAUDE.md:104-118
Summary
The Real-Time Data Pipeline is the backbone of the OpenAlgo platform, providing a normalized, high-throughput stream of market data. By utilizing ZeroMQ for internal transport and a dedicated WebSocket proxy for delivery, it achieves strict decoupling between broker interfaces and user applications, enabling robust algorithmic trading across diverse broker environments.
Sources: CLAUDE.md:144-154, README.md:11-20