# π€ AutoTrader
### Build Your Own Algorithmic Trading System β From Zero to Production
[](LICENSE)
[](https://python.org)
[](https://react.dev)
[](https://nats.io)
[](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!
]]>