Documentation
HomeGithubDiscordBlog
  • What is OpenAlgo?
  • OpenAlgo Architecture
  • Mini FOSS Universe
  • Community Support
  • OpenAlgo GPT
  • New Features
    • Fast Scalper
    • API Analyzer
    • Traffic/Latency Monitor
    • Chartink Integration
  • Monetization
  • Connect Brokers
    • Brokers
      • 5Paisa
      • 5paisa (XTS)
      • AliceBlue
      • AngelOne
      • Compositedge
      • Dhan
      • Dhan(Sandbox)
      • Firstock
      • FlatTrade
      • Fyers
      • Groww
      • IIFL (XTS)
      • Jainam Retail (XTS)
      • Jainam Dealer (XTS)
      • Kotak Securities
      • Paytm
      • Pocketful
      • Shoonya
      • Tradejini
      • Upstox
      • Wisdom Capital
      • Zebu
      • Zerodha
  • Installation Guidelines
  • Getting Started
    • Windows Installation
      • Pre-Requesites
      • Setup
      • Install Dependencies
      • Ngrok Config
      • Environmental Variables
      • Start OpenAlgo
      • SSL Verification Failed
      • Accessing OpenAlgo
    • Windows Server Installation
    • Mac OS Installation
      • Pre-Requesties
      • Setup
      • Install Dependencies
      • Ngrok Config
      • Environmental Variables
      • Start OpenAlgo
      • Install certifi
      • Accessing OpenAlgo
    • Amazon Elastic Beanstalk
    • Ubuntu Server Installation
    • Docker Development
    • Testing OpenAlgo in Cloud
    • Upgrade
  • Latency
  • API Documentation
    • V1
      • Accounts API
        • Funds
        • Orderbook
        • Tradebook
        • PositionBook
        • Holdings
      • Orders API
        • Placeorder
        • PlaceSmartOrder
        • BasketOrder
        • SplitOrder
        • ModifyOrder
        • CancelOrder
        • CancelAllOrder
        • ClosePosition
        • OrderStatus
        • OpenPosition
      • Data API
        • Quotes
        • Depth
        • History
        • Intervals
        • Symbol
        • Ticker
      • Websockets
      • Order Constants
      • HTTP Status Codes
      • Rate Limiting
      • API Collections
  • Symbol Format
  • MCP
  • Trading Platform
    • Amibroker
      • AmiQuotes
      • Button Trading Module
      • Button Trading with Split Orders
      • Button Trading with Stoploss
      • SmartOrder Chart Module
      • Trailing Stoploss Execution Module
      • Line Trading Module
      • Equity Exploration Module
      • CSV Exploration Module
      • Options Button Trading Module
      • Spot/Futures to Options Module (Single Leg)
      • Spot/Futures to Options Module (Two Leg)
      • Time Based Execution
    • Tradingview
      • Futures to Options Module
    • ChartInk
    • Python
      • Strategy Management
      • EMA Crossover Strategy
      • EMA Crossover Strategy with Stoploss and Target
      • Supertrend Strategy
      • Supertrend Strategy with yfinance data
      • Voice Based Orders
    • NodeJS
    • Metatrader 5
      • Download & Install Library
      • OpenAlgo MQL5 Functions
      • Include the Header File
      • Sample Expert Advisor
    • Excel
    • Google Spreadsheets
    • N8N
    • Chrome Extension
  • Strategy Management
  • Developers
    • Design Documentation
      • Architecture
      • API Layer
      • Broker Integerations
      • Database Layer
      • Authentication Platforms
      • Configuration
      • Utilities
      • Broker Integration Checklist
  • Change Log
    • Version 1.0.0.25 Launched
    • Version 1.0.0.24 Launched
    • Version 1.0.0.23 Launched
    • Version 1.0.0.22 Launched
    • Version 1.0.0.21 Launched
    • Version 1.0.0.20 Launched
    • Version 1.0.0.19 Launched
    • Version 1.0.0.18 Launched
    • Version 1.0.0.17 Launched
    • Version 1.0.0.16 Launched
    • Version 1.0.0.15 Launched
    • Version 1.0.0.14 Launched
    • Version 1.0.0.13 Launched
    • Version 1.0.0.12 Launched
    • Version 1.0.0.11 Launched
    • Version 1.0.0.10 Launched
    • Version 1.0.0.9 Launched
    • Version 1.0.0.8 Launched
    • Version 1.0.0.7 Launched
    • Version 1.0.0.6 Launched
    • Version 1.0.0.5 Launched
    • Version 1.0.0.4 Launched
    • Version 1.0.0.3 Launched
    • Version 1.0.0.2 Launched
    • Version 1.0.0.1 Launched
    • Version 1.0.0.0 Launched
Powered by GitBook
On this page
  • Broker Integration
  • Abstraction Layer Design
  • Broker Authentication
  • Broker Interaction Example (Place Order - Mermaid Diagram)
  • Connection Management & Error Handling
  1. Developers
  2. Design Documentation

Broker Integerations

Broker Integration

The broker directory is central to OpenAlgo's ability to connect and interact with various stock brokerage platforms. It implements an abstraction layer to provide a consistent interface regardless of the specific broker being used.

Abstraction Layer Design

OpenAlgo likely employs the Adapter Pattern to integrate different broker APIs.

  • Common Interface: A base class or a set of expected function signatures (defined implicitly or explicitly, perhaps in broker/__init__.py or a base adapter file) likely defines the standard operations OpenAlgo needs to perform (e.g., login, logout, place_order, get_order_status, get_positions, get_funds, get_quotes, etc.).

  • Specific Adapters: Each subdirectory within broker/ (e.g., broker/zerodha/, broker/angel/, broker/fyers/) contains a specific adapter implementation for that broker.

  • Adapter Responsibility: Each adapter class/module is responsible for:

    • Importing the broker's official or unofficial Python SDK/library (if available) or making direct HTTP requests to the broker's API.

    • Translating the standard OpenAlgo function calls into the specific methods and parameters required by the target broker's API.

    • Handling broker-specific authentication flows.

    • Parsing the broker's API responses and converting them into a standardized format expected by the rest of the OpenAlgo application.

    • Managing broker-specific error conditions and translating them into common OpenAlgo exceptions where possible.

  • Dynamic Loading: The utils.plugin_loader.load_broker_auth_functions function (seen in app.py) suggests a mechanism to dynamically discover and load available broker adapters and their authentication functions at runtime.

Broker Authentication

Authentication methods vary significantly between brokers. Common mechanisms likely implemented within the individual adapters include:

  • API Key & Secret: Used for programmatic access, often combined with other factors.

  • Request Token / Access Token Flow (OAuth2 variants): Many brokers use a multi-step process:

    1. User logs in via a broker's web portal, authorizing the application.

    2. A short-lived request_token is generated.

    3. The application exchanges the request_token (along with API key/secret) for an access_token and potentially a refresh_token.

    4. The access_token is used in subsequent API calls.

    5. The refresh_token (if provided) is used to obtain new access tokens when the old one expires.

  • Session Cookies: Some integrations might involve simulating a web login and managing session cookies.

  • TOTP (Time-based One-Time Password): Often required as a second factor during login.

  • User Credentials (Username/Password): Direct login using user credentials (less common for APIs, sometimes used in initial token generation).

The brlogin blueprint (blueprints/brlogin.py) likely handles the user-facing part of interactive login flows required by some brokers to generate initial tokens/sessions.

Generic Broker Login Flow (Illustrative Mermaid Diagram)

This diagram illustrates a common OAuth2-like flow often used by brokers for API access.

Broker Interaction Example (Place Order - Mermaid Diagram)

Connection Management & Error Handling

  • Adapters manage API client instances or HTTP sessions.

  • Error handling within adapters translates broker-specific errors (e.g., insufficient funds, invalid symbol, connection issues) into standardized exceptions or error responses for OpenAlgo's core logic.

  • Session expiry and re-authentication logic (using refresh tokens if applicable) should be handled within the adapter or the Broker Interface layer.

PreviousAPI LayerNextDatabase Layer

Last updated 1 month ago