Creating New Broker Plugins
Relevant source files
The following files were used as context for generating this wiki page:
OpenAlgo is a full-stack algorithmic trading environment designed to provide a common interface for executing strategies across multiple brokers without tying strategy code to a specific adapter. The platform achieves this through a plugin architecture that normalizes broker-specific APIs into a unified REST API layer.
Plugins are discovered at startup and are gated by the VALID_BROKERS environment variable. Each plugin must implement a set of standardized modules for order management, market data, and account services to ensure compatibility with OpenAlgo's surfaces, including the Python Strategy Host and the Flow no-code builder.
Sources: README.md:16-22, CLAUDE.md:144-148, CLAUDE.md:214-215
Plugin Architecture and Structure
Each broker plugin resides within the broker/ directory. The system uses structural discovery; support for a specific broker is determined by whether the corresponding modules and functions exist within that broker's subdirectory.
Directory Layout
A standard broker plugin must follow a specific internal structure:
| Component | Path | Description |
|---|---|---|
| Plugin Info | plugin.json | Metadata including broker type and supported exchanges. |
| Order API | api/order_api.py | Implementation of place, modify, and cancel orders. |
| Data API | api/data.py | Historical OHLCV, quotes, and market depth. |
| Account/Funds | api/funds.py | Account margin and funds data. |
| Streaming | streaming/{broker}_adapter.py | Market data WebSocket adapter. |
| Symbology | mapping/ | Logic for mapping OpenAlgo symbols to broker-specific tokens. |
Sources: scripts/generate_broker_compatibility.py:44-77, CLAUDE.md:129-136
Component Relationship Diagram
The following diagram illustrates how the normalized API layer interacts with the broker-specific plugin components.
Sources: CLAUDE.md:104-122, README.md:95-103
Core Implementation Requirements
1. Unified API Methods
To be considered fully compatible, a plugin should implement the following primary functions. Stubs that return empty data or raise NotImplementedError are tracked by audit scripts to identify support gaps.
- Order Management:
place_order_api,modify_order,cancel_order, andget_order_book. - Market Data:
get_quotes,get_depth, andget_history. - Account:
get_margin_data(Funds) andget_positions.
Sources: scripts/generate_broker_compatibility.py:44-75, test/test_broker_integration.py:84-250
2. Symbol Mapping and SymToken
OpenAlgo standardizes symbols across all brokers (e.g., NIFTY24APR24FUT). Plugins must use the SymToken schema to map these to broker-specific symbols and tokens.
- Fields required:
symbol(OpenAlgo),brsymbol(Broker),exchange,brexchange,token,lotsize. - Exchanges: Support must be mapped for
NSE,BSE,NFO,MCX, etc.
Sources: CLAUDE.md:129-136, CLAUDE.md:141-143
3. Streaming Adapters
Streaming is split into two distinct adapters to allow market data and order updates to be handled independently.
- Market Data Adapter: Must implement
subscribe,connect, andon_message. It connects to the ZeroMQ bus (port 5555) to publish normalized ticks. - Order Update Adapter: Inherits from
BaseOrderUpdateAdapterand suppliesget_ws_urlandnormalize.
Sources: scripts/generate_broker_compatibility.py:82-90, scripts/generate_broker_compatibility.py:149-166, CLAUDE.md:105-115
Market Data Pipeline
The market data pipeline is decoupled using a ZeroMQ bus to ensure the proprietary broker feeds do not block client delivery.
Sources: CLAUDE.md:105-115, README.md:105-112
Integration Testing
New plugins must be validated using the automated test runner to ensure they meet the api/v1 contract.
Test Scenarios
| Category | Test Function | Validation |
|---|---|---|
| Auth | test_auth | Validates broker token sanity via funds endpoint. |
| Orders | test_orders | Tests MARKET/LIMIT/SL types in Analyzer (sandbox) mode. |
| Data | test_marketdata | Verifies LTP, Depth, and Historical candle retrieval. |
| WebSocket | test_websocket | Ensures ticks are received for LTP, Quote, and Depth. |
Sources: test/test_broker_integration.py:100-350
Development and Audit Tools
Developers should use the following scripts when building new integrations:
generate_broker_compatibility.py: Regenerates the compatibility report by parsing implementation nodes..claude/skills/broker-integration/SKILL.md: Contains detailed procedures for adding or modifying plugins.
Sources: scripts/generate_broker_compatibility.py:15-38, CLAUDE.md:46-49