Skip to content

ertanuj96/AutoTrader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

# πŸ€– AutoTrader ### Build Your Own Algorithmic Trading System β€” From Zero to Production [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![Python 3.12+](https://img.shields.io/badge/Python-3.12+-3776AB?logo=python&logoColor=white)](https://python.org) [![React 18](https://img.shields.io/badge/React-18-61DAFB?logo=react&logoColor=black)](https://react.dev) [![NATS](https://img.shields.io/badge/NATS-JetStream-27AAE1?logo=nats.io)](https://nats.io) [![Docker](https://img.shields.io/badge/Docker-Compose-2496ED?logo=docker&logoColor=white)](https://docker.com) **An open-source, event-driven algorithmic trading platform designed to be your go-to framework for building, testing, and deploying automated trading strategies.** [Quick Start](#-quick-start) Β· [Architecture](#-architecture) Β· [Documentation](#-documentation) Β· [Contributing](#-contributing) Β· [Roadmap](#-roadmap) --- ## 🎯 What is AutoTrader? AutoTrader is an **institutional-grade personal trading system** built from the ground up with a focus on: - **Event-driven architecture** β€” Every trading action (tick, signal, order, fill) flows as an immutable event through NATS - **Low-latency execution** β€” Designed for the lowest practical latency achievable through retail broker APIs - **Complete observability** β€” Real-time dashboard with PnL, positions, Greeks, latency analytics, and exposure monitoring - **Strategy experimentation** β€” Plug in your own strategies with a clean, decoupled interface - **Risk-first design** β€” Built-in risk engine with drawdown protection, exposure limits, and kill switch - **Historical data accumulation** β€” Every tick, signal, order, and fill is persisted for backtesting and ML Whether you're a quantitative developer, an algo trading enthusiast, or someone who wants to learn how professional trading systems work β€” AutoTrader gives you a production-ready foundation to build on. --- ## ✨ Features | Feature | Description | |---------|-------------| | πŸ“Š **Market Data Service** | Real-time tick ingestion via broker WebSocket, normalization, and event publishing | | 🧠 **Strategy Engine** | Pluggable strategy framework with built-in EMA crossover example | | ⚑ **Execution Engine** | Order placement, modification, cancellation, and fill tracking | | πŸ›‘οΈ **Risk Engine** | Real-time margin checks, exposure limits, drawdown protection, and kill switch | | πŸ“ˆ **React Dashboard** | Live PnL charts, position management, strategy controls, latency monitoring | | πŸ”Œ **Broker Adapter** | Modular broker integration (currently INDstocks, easily extensible) | | πŸ’Ύ **Dual Storage** | Redis for hot state + ClickHouse for historical analytics | | πŸ“‘ **NATS Messaging** | JetStream-powered event bus with replay capability | | πŸ“‰ **Grafana + Prometheus** | Infrastructure and trading metrics monitoring | | 🧾 **Paper Trading** | Full simulation mode for strategy development without risking capital | --- ## πŸ—οΈ Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ React Dashboard (Vite) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Dashboard API (FastAPI) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Redis (Live State) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ NATS (Event Bus) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Market Data β”‚ Strategy β”‚ Risk Engine β”‚ Execution β”‚ β”‚ Service β”‚ Engine β”‚ β”‚ Engine β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Broker Adapter β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Exchange (NSE / MCX) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ ClickHouse Prometheus (Historical) + Grafana ``` ### Tech Stack | Component | Technology | |-----------|------------| | Strategy Layer | Python 3.12+ | | Event Bus | NATS JetStream | | Live State | Redis 7 | | Historical Storage | ClickHouse | | Dashboard Backend | FastAPI | | Dashboard Frontend | React 18 + Vite | | Monitoring | Prometheus + Grafana | | Containerization | Docker Compose | --- ## πŸš€ Quick Start ### Prerequisites - [Docker & Docker Compose](https://docs.docker.com/get-docker/) - [Python 3.12+](https://python.org) - [Node.js 20+](https://nodejs.org) ### 1. Clone & Configure ```bash git clone https://github.com/ertanuj96/AutoTrader.git cd AutoTrader # Copy and configure your environment cp .env.example .env # Edit .env with your broker API credentials ``` ### 2. Start Infrastructure ```bash # Start NATS, Redis, ClickHouse, Prometheus, and Grafana docker-compose up -d ``` ### 3. Start the Trading Core ```bash cd trading-core pip install -e . python -m pts.main ``` ### 4. Start the Dashboard API ```bash cd dashboard-api pip install -e . uvicorn app.main:app --port 8001 ``` ### 5. Start the Dashboard UI ```bash cd dashboard-ui npm install npm run dev ``` Open [http://localhost:5173](http://localhost:5173) to see your trading dashboard. --- ## πŸ“‚ Project Structure ``` AutoTrader/ β”œβ”€β”€ trading-core/ # Core trading engine (Python) β”‚ └── pts/ β”‚ β”œβ”€β”€ main.py # Async orchestrator β€” starts all services β”‚ β”œβ”€β”€ market_data.py # WebSocket tick ingestion & normalization β”‚ β”œβ”€β”€ strategy_engine.py # Pluggable strategy framework β”‚ β”œβ”€β”€ risk_engine.py # Risk checks, exposure limits, kill switch β”‚ β”œβ”€β”€ execution_engine.py# Order lifecycle management β”‚ β”œβ”€β”€ broker_adapter.py # Broker API abstraction layer β”‚ β”œβ”€β”€ state_manager.py # Redis state management β”‚ β”œβ”€β”€ persistence.py # ClickHouse historical storage β”‚ β”œβ”€β”€ events.py # Canonical event definitions β”‚ β”œβ”€β”€ config.py # Configuration management β”‚ └── metrics.py # Prometheus metrics β”‚ β”œβ”€β”€ dashboard-api/ # REST + WebSocket API (FastAPI) β”‚ └── app/ β”‚ β”œβ”€β”€ main.py # FastAPI app with WebSocket support β”‚ β”œβ”€β”€ deps.py # Dependency injection β”‚ └── routes/ β”‚ β”œβ”€β”€ orders.py # Order endpoints β”‚ β”œβ”€β”€ positions.py # Position endpoints β”‚ β”œβ”€β”€ strategies.py # Strategy control endpoints β”‚ └── system.py # System health & metrics β”‚ β”œβ”€β”€ dashboard-ui/ # Real-time trading dashboard (React + Vite) β”‚ └── src/ β”‚ β”œβ”€β”€ App.jsx # Main dashboard layout β”‚ └── components/ β”‚ β”œβ”€β”€ Header.jsx # Connection status & branding β”‚ β”œβ”€β”€ StatsRow.jsx # Key trading metrics β”‚ β”œβ”€β”€ PnlChart.jsx # Real-time PnL visualization β”‚ β”œβ”€β”€ StrategyManager.jsx# Strategy start/stop/pause β”‚ β”œβ”€β”€ PositionsPanel.jsx # Active positions table β”‚ β”œβ”€β”€ OrderBook.jsx # Order history β”‚ β”œβ”€β”€ LatencyMonitor.jsx # Execution latency analytics β”‚ └── ExposureGauge.jsx # Portfolio exposure visualization β”‚ β”œβ”€β”€ platform-docs/ # Architecture & design documents β”‚ β”œβ”€β”€ PTS-001-Architecture-and-Vision-v0.1.md β”‚ β”œβ”€β”€ PTS-002-Event-Model-and-Message-Contracts-v0.1.md β”‚ └── PTS-003-Data-Model-and-Storage-Architecture-v0.1.md β”‚ β”œβ”€β”€ monitoring/ # Observability configuration β”‚ β”œβ”€β”€ prometheus.yml β”‚ └── grafana/ β”‚ β”œβ”€β”€ provisioning/ β”‚ └── dashboards/ β”‚ β”œβ”€β”€ docker-compose.yml # Infrastructure services β”œβ”€β”€ .env.example # Environment variable template └── .gitignore ``` --- ## πŸ“š Documentation Detailed design documents are in the [`platform-docs/`](platform-docs/) directory: | Document | Description | |----------|-------------| | [PTS-001](platform-docs/PTS-001-Architecture-and-Vision-v0.1.md) | Architecture & Vision β€” System overview, design principles, technology choices | | [PTS-002](platform-docs/PTS-002-Event-Model-and-Message-Contracts-v0.1.md) | Event Model β€” NATS subjects, event envelopes, all message contracts | | [PTS-003](platform-docs/PTS-003-Data-Model-and-Storage-Architecture-v0.1.md) | Data Model β€” ClickHouse schemas, Redis key design, retention policies | --- ## 🀝 Contributing We welcome contributions from the community! Whether it's fixing bugs, adding strategies, improving documentation, or building new features β€” every contribution matters. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. ### How to Contribute 1. **Fork** the repository 2. **Create** a feature branch (`git checkout -b feature/amazing-strategy`) 3. **Commit** your changes (`git commit -m 'Add amazing strategy'`) 4. **Push** to the branch (`git push origin feature/amazing-strategy`) 5. **Open** a Pull Request ### Ideas for Contributions - 🧠 New trading strategies (mean reversion, momentum, pairs trading, etc.) - πŸ”Œ Broker adapters for other platforms (Zerodha, Alpaca, Interactive Brokers) - πŸ“Š Additional dashboard components (volatility surface, order flow) - πŸ§ͺ Backtesting framework - πŸ“– Tutorials and documentation - πŸ› Bug fixes and performance improvements --- ## πŸ—ΊοΈ Roadmap ### Phase 1 β€” Foundation βœ… - [x] Market data ingestion - [x] Single strategy execution - [x] Execution engine - [x] Real-time dashboard - [x] Historical storage (ClickHouse) ### Phase 2 β€” Multi-Strategy & Risk - [ ] Multi-strategy portfolio management - [ ] Advanced risk engine with position-level controls - [ ] Portfolio-level Greeks aggregation ### Phase 3 β€” Analytics - [ ] Greeks engine (real-time IV computation) - [ ] Volatility surface visualization - [ ] Slippage and execution quality analysis ### Phase 4 β€” Backtesting - [ ] Historical event replay from ClickHouse - [ ] Walk-forward testing framework - [ ] Strategy comparison and ranking ### Phase 5 β€” Intelligence - [ ] Adaptive execution algorithms - [ ] Liquidity-aware order routing - [ ] ML-assisted trade signal ranking --- ## ⚠️ Disclaimer **AutoTrader is for educational and research purposes.** Trading in financial markets involves substantial risk. Past performance is not indicative of future results. Always paper trade first and understand the risks before deploying with real capital. --- ## πŸ“ License This project is licensed under the MIT License β€” see the [LICENSE](LICENSE) file for details. ---
**Built with ❀️ for the algo trading community** If you find AutoTrader useful, please ⭐ star the repo β€” it helps others discover it!
]]>

About

πŸ€– Build Your Own Algorithmic Trading System β€” An open-source, event-driven platform with real-time dashboard, risk management, and pluggable strategies

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages