A production-grade, research-backed algorithmic trading system combining statistical arbitrage, AI-powered decision making, and institutional-grade risk management for cryptocurrency futures markets.
NOT FINANCIAL ADVICE โข This is a technical demonstration for learning purposes. Cryptocurrency trading is high-risk. Authors assume NO liability for losses. Consult licensed professionals before any real trading.
- ๐ง Multi-Agent AI: Google Gemini 2.5 orchestrating quant, sentiment, and risk analysis
- ๐ 4 Concurrent Strategies: Cointegration, OBI, Correlation+RSI, Mean Reversion
- โก High Performance: Sub-100ms latency via WebSocket streaming
- ๐ก๏ธ Risk Management: Dynamic sizing, trailing stops, drawdown limits
- ๐ Research-Backed: 2024-2025 academic papers from Financial Innovation
- ๐ Live Dashboard: Real-time P&L, positions, and performance metrics
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ORCHESTRATOR AGENT โ
โ Multi-Strategy Coordination & Decision Engine โ
โ (Consensus-based execution with override controls) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
โ QUANT AGENT โ โ SENTIMENT AGENT โ โ RISK AGENT โ
โ โ โ (Gemini 2.5) โ โ โ
โ โข Cointegration โ โ โข News Analysis โ โ โข Position Sizing โ
โ โข Z-Score โ โ โข Event Detection โ โ โข Stop-Loss โ
โ โข Hedge Ratios โ โ โข Market Regime โ โ โข Drawdown Limit โ
โ โข OBI Signals โ โ โข Google Search โ โ โข Exposure Mgmt โ
โ โข RSI/Correlation โ โ Grounding โ โ โข Risk Metrics โ
โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ EXECUTION & DATA LAYER โ
โ โข Smart Order Router (Limit โ Market Fallback) โ
โ โข WebSocket Streaming (Trade & Orderbook) โ
โ โข PostgreSQL + TimescaleDB (Time-Series Storage) โ
โ โข Redis Cache (Low-latency Access) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Bybit Futures API
(Linear Perpetual Contracts)
Engle-Granger Cointegration โข Statistical arbitrage on BTC/ETH pairs via OLS regression hedge ratios
Order Book Imbalance (OBI) โข Real-time bid/ask pressure analysis for momentum capture
Correlation + RSI โข RSI divergence detection on correlated pairs with multi-timeframe confirmation
Mean Reversion โข Z-score entry (ยฑ2ฯ) with Bollinger Bands and adaptive volatility thresholds
Statistics โข Engle-Granger, ADF tests, OLS/Kalman filtering, Kelly Criterion, Z-score normalization
AI โข Google Gemini 2.5 (sentiment + news), Multi-agent consensus, Google Search grounding
Infrastructure โข WebSocket โ Redis โ PostgreSQL/TimescaleDB, Smart order routing, FastAPI dashboard
Performance โข Real-time Sharpe ratio, win rate, drawdown tracking, <100ms execution latency
10 research-backed pairs across BTC/ETH majors, L1 ecosystems, DeFi, and Layer 2s:
- BTC/ETH (Rยฒ > 0.95) โข BTC/LTC โข ETH/SOL โข LTC/DOGE โข DOT/ATOM โข 6 more
Source: Financial Innovation 2025
Prerequisites: Python 3.11+, PostgreSQL/TimescaleDB, Redis, Bybit API
# Setup
git clone https://github.com/Amdev-5/crypto-pairs-trading-ai.git
cd crypto-pairs-trading-ai
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Configure
cp .env.example .env # Add your Bybit API keys
nano config.yaml # Customize pairs, thresholds, risk limits
# Run (Testnet)
python -m src.main # Trading engine
python -m src.dashboard.app # Dashboard โ localhost:3000BYBIT_TESTNET=False in .env (high risk, start small)
Targets: Sharpe >1.5 | Win Rate >55% | Drawdown <20% | Latency <100ms
Risk Controls: Position stop-loss (-3%) โข Daily loss limit โข Max 10 concurrent positions โข Dynamic sizing โข Trailing stops
.
โโโ src/
โ โโโ agents/ # Multi-agent system
โ โ โโโ orchestrator.py # Central coordinator
โ โ โโโ quant_agent.py # Statistical analysis
โ โ โโโ sentiment_agent.py # Gemini AI + news
โ โ โโโ risk_agent.py # Risk management
โ โโโ data/
โ โ โโโ bybit_client.py # WebSocket + REST API
โ โ โโโ database.py # PostgreSQL/TimescaleDB
โ โ โโโ models.py # Data models
โ โโโ strategy/
โ โ โโโ cointegration.py # Statistical tests
โ โ โโโ zscore.py # Z-score calculation
โ โ โโโ signals.py # Signal generation
โ โ โโโ strategies/ # Individual strategy implementations
โ โโโ execution/
โ โ โโโ order_manager.py # Smart order routing
โ โ โโโ position_manager.py # Position tracking
โ โโโ monitoring/
โ โ โโโ performance_tracker.py # Real-time metrics
โ โโโ backtesting/
โ โ โโโ backtest_engine.py # Historical simulation
โ โโโ dashboard/
โ โ โโโ app.py # FastAPI server
โ โ โโโ templates/ # Dashboard UI
โ โโโ main.py # Entry point
โโโ tests/ # Unit & integration tests
โโโ logs/ # Trading logs
โโโ config.yaml # Trading configuration
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment template
# Backtesting
python -m src.backtesting.backtest_engine --start-date 2024-01-01 --end-date 2024-11-26
# Paper Trading (Testnet - Free $10K-$100K)
BYBIT_TESTNET=True python -m src.main
# Unit Tests
pytest tests/ -v --cov=src- Never commit API keys (use
.env) - Use testnet for development
- Start live trading with minimal sizes
- Enable stop-loss and loss limits
- Bybit API:
Order+Positiononly (neverWithdrawal)
High volatility, leverage amplification, cointegration breakdown, system failures, regulatory changes. Educational use only. Trade at your own risk with capital you can afford to lose.
Based on peer-reviewed papers:
- Copula-based cryptocurrency pairs trading (Financial Innovation 2025)
- Dynamic Cointegration Pairs Trading (arXiv 2024)
- HF cryptocurrency relationships (Financial Innovation 2021)
PRs welcome! Add tests, ensure pytest passes. Ideas: Johansen testing, ML regime detection, multi-exchange support, mobile dashboard.
Dashboard (localhost:3000): Live P&L, strategy breakdown, z-score charts, execution timeline
Logging: JSON logs (logs/trading.log) with agent decisions and order details
Alerts: Telegram/Email/Discord (optional)
โ Multi-agent AI, 4 strategies, smart routing, dashboard, risk management, testnet
๐ง ML strategy selection, enhanced backtesting, portfolio optimization
๐ฎ Multi-exchange, options trading, social sentiment, RL strategy discovery
MIT License - See LICENSE for details
Use at your own risk. This software is provided "AS IS" without warranty of any kind.
Issues: GitHub Issues โข Docs: ARCHITECTURE.md
Built with: Bybit API โข Google Gemini โข statsmodels โข pandas โข PostgreSQL/TimescaleDB
โญ Star this repo if you found it valuable!