Unified Broker API
Relevant source files
The following files were used as context for generating this wiki page:
The Unified Broker API is a core architectural component of OpenAlgo, providing a standardized RESTful interface for interacting with 34+ different broker plugins. Located at the /api/v1/ route, it abstracts the complexities of individual broker proprietary APIs into a single, maintained contract. This allow external platforms—such as TradingView, Amibroker, Excel, or custom Python scripts—to execute trades and retrieve market data without modifying code for specific adapters.
The API serves as one of OpenAlgo's four primary product surfaces, sharing a single broker session, market-data infrastructure, and Sandbox engine across the platform. It supports a wide range of operations including order management, portfolio tracking, and real-time market data retrieval across various asset classes like Equities, F&O, Currencies, and Commodities.
Sources: README.md, CLAUDE.md, okf/index.md
Architecture and Data Flow
The Unified Broker API operates as an abstraction layer between external requests and broker-specific plugins. Requests entering the /api/v1/ pipeline pass through security middleware and authentication before reaching the service layer, which communicates with the active broker session.
The request pipeline includes IP banning, API key validation (using JSON body or headers), and centralized logging before hitting the broker-specific adapter.
Pipeline Components
| Component | Responsibility |
|---|---|
| Traffic Logger | Captures API usage analytics, error tracking, and endpoint statistics. |
| Security Middleware | Handles IP banning and 403 Forbidden responses for unauthorized access. |
| API Key Auth | Validates keys passed in the JSON body or X-API-KEY header against peppered hashes. |
| Service Layer | Standardizes internal service-layer functions for data and orders. |
| Broker Plugins | 34+ adapters (e.g., Zerodha, AngelOne, Fyers) that normalize proprietary API calls. |
Core API Capabilities
The API is organized into several service categories that provide uniform functionality regardless of the underlying broker.
Order Management
Standardized endpoints for executing and managing trades. The API supports advanced order types like Smart Orders (position-aware) and Basket Orders.
The API supports an Analyzer Mode (Sandbox) with ₹1 Crore virtual capital, allowing for risk-free strategy testing before live execution.
Sources: CLAUDE.md, README.md, test/test_broker_integration.py:168-180
Portfolio and Account Services
Endpoints for retrieving real-time account status and position data.
- Orderbook: Returns all orders for the day.
- Tradebook: Returns all executed trades.
- Positionbook: Returns current open positions and PnL.
- Holdings: Returns portfolio equity holdings.
- Funds: Returns available cash, collateral, and margin utilization.
Sources: okf/viz.html, test/test_broker_integration.py:214-218
Market Data Services
Provides access to normalized real-time and historical market information.
| Endpoint | Purpose |
|---|---|
/quotes | Last Traded Price (LTP) and basic OHLC for a symbol. |
/depth | Level 2 Market Depth (bids and asks). |
/history | Historical OHLCV data (intraday and daily). |
/search | Global symbol search across all enabled exchanges. |
/multiquotes | Batch quote retrieval for multiple symbols in one call. |
Sources: okf/viz.html, README.md, test/test_broker_integration.py:288-305
Standardization and Symbology
A key feature of the Unified Broker API is the normalization of symbol formats across different exchanges and brokers.
Standard Symbol Format
| Asset Type | Format | Example |
|---|---|---|
| Equity | [Base Symbol] | INFY, RELIANCE |
| Futures | [Base][Expiry]FUT | NIFTY24APR24FUT |
| Options | [Base][Expiry][Strike][Type] | NIFTY28MAR2420800CE |
Supported Exchanges
The API maps internal standardized exchange codes to broker-specific equivalents:
- NSE/BSE: Equity and F&O.
- NFO/BFO: Derivatives (Futures & Options).
- CDS/BCD: Currency derivatives.
- MCX/NCDEX: Commodities.
- NSE_INDEX/BSE_INDEX: Index quotes.
Sources: CLAUDE.md, README.md, test/test_broker_integration.py:125-149
Broker Compatibility and Stubs
Compatibility is determined at runtime based on the presence and implementation status of functions within the broker plugins. The system distinguishes between fully supported features, stubs (defined but not implemented), and unimplemented features.
Stub markers (like NotImplementedError) ensure that a feature like get_history doesn't silently fail by returning empty data, informing the user of actual broker limitations.
Sources: scripts/generate_broker_compatibility.py:27-50
Conclusion
The Unified Broker API is the foundational interface that enables OpenAlgo's "single API, multiple brokers" value proposition. By normalizing symbology, order types, and data formats, it allows traders to build broker-agnostic systems while maintaining access to advanced features like sandbox testing and multi-leg option strategies.