Core Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
OpenAlgo is a production-grade algorithmic trading platform designed as a unified self-hosted environment. It integrates a Flask backend with a React 19 frontend to provide multiple trading surfaces, including a REST API, a visual no-code builder, a Python strategy host, and analytical tools. The system is designed for single-user deployments where the server maintains a single broker session and fanned-out WebSocket feeds across all internal surfaces.
The architecture emphasizes decoupling market data feeds from execution logic through a ZeroMQ-based message bus and a dedicated WebSocket proxy. It utilizes isolated databases for main application data, logging, latency tracking, health monitoring, sandbox trading, and historical market data.
Sources: CLAUDE.md:10-18, README.md:18-24, okf/overview.md
Product Surfaces and Routing
OpenAlgo serves as "several products in one," sharing core infrastructure while providing distinct interfaces for different trading styles.
| Surface | Route | Purpose |
|---|---|---|
| Unified Broker API | /api/v1/ | External platform integration (TradingView, Python, etc.) |
| Python Strategy Host | /python | In-browser editor and isolated subprocess execution |
| Flow (No-Code) | /flow | Node-based visual strategy builder |
| Options Suite | /tools | Analytics for Greeks, Option Chains, and Portfolio analysis |
| Charting Terminal | /trading | Line-based chart trading |
| Scalping Terminal | /scalping | Keyboard-driven options/futures scalping |
Sources: CLAUDE.md:13-24, README.md:26-38
Data Pipeline Architecture
The market data pipeline is structured into three distinct layers to ensure that slow clients do not block the incoming data feed from brokers.
Market Data Flow
- Broker Adapters: Connect to proprietary feeds (e.g., Zerodha, AngelOne) and normalize ticks.
- ZeroMQ Bus: A fan-in decoupling layer (default port 5555) where the proxy SUB binds and all publishers connect.
- WebSocket Proxy: Manages client subscriptions and enforces per-symbol throttling (default port 8765).
The ZeroMQ bus is a critical invariant: the proxy's SUB must bind() while publishers connect() to prevent port contention and silent delivery failures.
Sources: CLAUDE.md:88-100, README.md:129-135
Request and Security Middleware
Requests flow through multiple layers of WSGI middleware before reaching the Flask application and service layers.
Middleware Execution Order
Sources: CLAUDE.md:158-166, blueprints/admin.py:465-475
Execution Models
OpenAlgo supports three primary execution environments, each sharing the same broker session logic but utilizing different runtime isolation.
Python Strategy Host
Strategies run as isolated subprocess.Popen processes. This ensures that a memory leak or crash in one script does not impact the main application. The host injects environment variables for authentication and exchange-aligned scheduling.
Sources: frontend/src/pages/python-strategy/PythonStrategyGuide.tsx:238-255
API Analyzer (Sandbox)
A fully isolated environment with 1 Crore sandbox capital. It uses a separate sandbox.db and mimics exchange behavior (e.g., auto square-off) without routing orders to real brokers.
Sources: CLAUDE.md:26-27, README.md:154-162
Multi-Session Management
While OpenAlgo is single-user, it supports up to 5 concurrent active sessions. These sessions share a single server-side broker feed pool, fanned out by the proxy.
Sources: CLAUDE.md:108-115
Data Storage Strategy
The platform utilizes six isolated SQLite/DuckDB databases to maintain strict separation of concerns.
| Database | File Path | Purpose |
|---|---|---|
| Main | db/openalgo.db | User settings, strategy configs, auth |
| Logs | db/logs.db | Operational audit trails |
| Latency | db/latency.db | Order execution performance tracking |
| Health | db/health.db | System and heartbeat metrics |
| Sandbox | db/sandbox.db | Isolated paper trading data |
| Historify | db/historify.duckdb | Historical market data store |
All SQLite engines use NullPool to ensure fresh connections per operation, preventing cursor state corruption across concurrent requests.
Sources: CLAUDE.md:129-133, CLAUDE.md:144-150, frontend/src/pages/admin/Diagnostics.tsx:322-340
Diagnostic and Audit Systems
The administration module provides real-time diagnostics and error tracking via the /admin surface.
- Error Grouping: Errors from
log/errors.jsonlare aggregated by fingerprint (exception type + module) to help developers identify recurring issues. - Connectivity Probes: The system performs TCP-only probes to the database, loopback HTTP, the WebSocket proxy, and broker API hosts to verify reachability.
- Safety Gating: Diagnostic reports exclude sensitive values (e.g.,
APP_KEY,API_KEY_PEPPER, tokens), reporting only their presence as booleans.
Sources: blueprints/admin.py:596-615, frontend/src/pages/admin/Diagnostics.tsx:343-375
Summary
The OpenAlgo architecture is a modular, multi-surface system designed for stability and high-performance data delivery. By utilizing a ZeroMQ fan-in bus for market data and subprocess isolation for custom Python strategies, it provides a robust environment for both manual and automated trading across 35 supported brokers.
Sources: README.md:88-100, CLAUDE.md:13-24