How raahi-bhushan/trading-algo works
Project Type and Purpose
• This is an algorithmic trading toolkit (full-stack library/tool) that provides:
• Broker-agnostic core APIs for order management and market data
• Plug-and-play broker integrations (Zerodha, Fyers, etc.)
• A strategy layer where users implement and run trading algorithms (Survivor, Wave)
• Primary use case: fetch live/historical data, run strategies, place/monitor orders through different brokers.
File Structure
• Top-Level:
.pyproject.toml, uv.lock, .sample.env, .gitignore → build & env config
README.md, CONTRIBUTING.md → documentation
dispatcher.py, orders.py, logger.py → core routing, order utilities, logging
brokers/ → core interfaces and broker implementations
strategy/ → strategy configurations & code
• brokers/ Substructure:
brokers/core → common enums, errors, gateway interface, schemas
brokers/integrations → concrete drivers for each broker
brokers/auth → multiple authentication schemes (manual, tokens, TOTP)
brokers/net → HTTP client and rate-limiter
brokers/mappings, symbols, registry → lookup tables & plugin registry
• Patterns:
• Plugin/Registry pattern for broker drivers
• Layered architecture: Core API → Integrations → Strategy layer
• Configuration-driven initialization via environment variables
README Insights
• Describes supported brokers, setup steps (uv sync), environment config
• Highlights core components: brokers/, dispatcher.py, orders.py, logger.py, strategy/
• Emphasizes strategy invocation and broker gateway usage
a. Main Components:
1. Strategy Layer (strategy/*.py)
2. Core Library
• BrokerGateway (interface + registry)
• Dispatcher (data routing, queue management)
• Orders module (order creation, tracking)
• Logger
3. Broker Integrations
• Auth module (manual, tokens, TOTP)
• Integrations/fyers, zerodha, fyrodha drivers
• Net layer (HTTP client, rate-limiter, WebSocket hooks)
4. External Services
• Broker REST APIs & WebSockets (Fyers, Zerodha)
5. Config & Data Stores
• Environment (.env)
• Strategy config YAML files
b. Relationships & Interactions:
– Strategy invokes BrokerGateway → selects integration driver via registry
– BrokerGateway uses Auth + Net modules → communicates with Broker API
– Dispatcher >> feeds live/historical data into Strategy
– Orders module submits/cancels orders via BrokerGateway
– Logger tracks all events and errors
c. Architectural Patterns / Principles:
– Dependency Inversion: Strategies depend on abstract BrokerGateway, not concrete APIs
– Plugin Architecture: Dynamic registration of new brokers via registry modules
– Single Responsibility: Separate modules for auth, networking, mapping, strategies
– Config-Driven Behavior: .env for secrets, YAML for strategy parameters
d. Key Technologies / Libraries:
– Python 3.10+ (pyproject.toml)
– uv (Astral’s dependency manager)
– HTTP & WebSocket (brokers/net/http.py)
– YAML parsing for strategy configs
– Environment variable loader via sample .env
Elements
– Clear component labels (Strategy, BrokerGateway, Dispatcher, Auth, Net, Drivers, Broker APIs)
• Rectangles for in-process modules (Strategy, Core)