Skip to content

Amdev-5/crypto-pairs-trading-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ AI-Powered Cryptocurrency Pairs Trading System

Python 3.11+ License: MIT Bybit AI Trading Strategy

A production-grade, research-backed algorithmic trading system combining statistical arbitrage, AI-powered decision making, and institutional-grade risk management for cryptocurrency futures markets.


โš ๏ธ DISCLAIMER: Educational Research Project Only

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.


๐ŸŽฏ Key Features

  • ๐Ÿง  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

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      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)

๐Ÿ’ก Trading Strategies

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


๐Ÿ› ๏ธ Technical Stack

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


๐Ÿ“Š Trading Pairs

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


๐Ÿš€ Quick Start

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:3000

โš ๏ธ Live Trading: Set BYBIT_TESTNET=False in .env (high risk, start small)


๐Ÿ“ˆ Performance & Risk

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


๐Ÿ—‚๏ธ Project Structure

.
โ”œโ”€โ”€ 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

๐Ÿงช Testing

# 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

๐Ÿ” Security

  • 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 + Position only (never Withdrawal)

โš ๏ธ Risks

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.


๐Ÿ“š Research

Based on peer-reviewed papers:


๐Ÿค Contributing

PRs welcome! Add tests, ensure pytest passes. Ideas: Johansen testing, ML regime detection, multi-exchange support, mobile dashboard.


๐Ÿ“Š Monitoring

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)


๐ŸŽฏ Roadmap

โœ… 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


๐Ÿ“„ License

MIT License - See LICENSE for details

Use at your own risk. This software is provided "AS IS" without warranty of any kind.


๐Ÿ“ž Support

Issues: GitHub Issues โ€ข Docs: ARCHITECTURE.md

Built with: Bybit API โ€ข Google Gemini โ€ข statsmodels โ€ข pandas โ€ข PostgreSQL/TimescaleDB


โญ Star this repo if you found it valuable!

About

AI-powered cryptocurrency pairs trading system with multi-agent architecture, statistical arbitrage, and real-time risk management (Educational/Research)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors