Skip to content

f0x-sketch/hyperliquid-ai-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Hyperliquid AI Trading Bot

An autonomous AI-powered trading bot for Hyperliquid DEX perpetual futures, featuring advanced machine learning strategies, LLM-driven decision making, and a modern web dashboard.

Python 3.11 Docker License: MIT


✨ Features

🧠 Multi-Regime Ensemble Strategy

  • Hidden Markov Model for market regime detection (Trending/Ranging/Volatile)
  • Dynamic strategy switching based on market conditions
  • Kelly Criterion position sizing with fractional Kelly (25%)
  • Academic research-backed approach (57+ peer-reviewed studies)

πŸ“Š Advanced Signal Layer

  • Volume-Weighted: VWAP deviation, OBV divergence, MFI extremes
  • Order Flow: Bid-ask imbalance, market depth slope
  • Funding Rate: Arbitrage detection, momentum signals
  • Liquidation Cascade: OI surge detection, whale activity

πŸ€– LLM Intervention System

  • Kimi K2.5 integration for autonomous decision making
  • Knowledge persistence across trading sessions
  • Self-improving through accumulated experience
  • Configurable intervention intervals (default: 4 hours)

🐳 Docker Ready

  • One-command deployment with Docker Compose
  • Non-root container for security
  • Health checks and automatic restarts
  • Volume persistence for data and logs

🌐 Web Dashboard

  • Real-time status monitoring
  • Position management with PnL tracking
  • Circuit breaker control
  • Configuration editor
  • Secrets management (masked inputs)
  • LLM intervention trigger and history

πŸš€ Quick Start

Option 1: Docker (Recommended)

# Clone the repository
git clone https://github.com/f0x-sketch/hyperliquid-ai-bot.git
cd hyperliquid-ai-bot

# Create environment file
cp .env.example .env
nano .env  # Add your credentials

# Build and run
docker-compose up -d --build

# Access Web UI
open http://localhost:8080

Option 2: Local Installation

# Clone the repository
git clone https://github.com/f0x-sketch/hyperliquid-ai-bot.git
cd hyperliquid-ai-bot

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/macOS
# or: .\venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
nano .env  # Add your credentials

# Run the bot
python run.py

βš™οΈ Configuration

Environment Variables

Variable Required Description
HL_PRIVATE_KEY βœ… API wallet private key (for signing orders)
HL_WALLET_ADDRESS βœ… Main wallet address (for queries)
HL_NETWORK βœ… testnet or mainnet
KIMI_API_KEY ⬜ Kimi API key for LLM intervention
OPENROUTER_API_KEY ⬜ OpenRouter API key (fallback)

Strategy Parameters

EnsembleStrategyConfig:
    regime_lookback: 100        # Bars for regime detection
    signal_threshold: 0.6       # Min confidence to trade
    kelly_fraction: 0.25        # Fractional Kelly (25%)
    max_drawdown_limit: 0.15    # 15% max drawdown
    funding_arb_threshold: 0.0005  # 0.05% funding gap

Risk Management

Parameter Default Description
Max Leverage 5x Maximum position leverage
Risk per Trade 2% Maximum risk per position
Max Drawdown 15% Circuit breaker threshold
Max Daily Loss 3% Daily loss limit

πŸ“ Project Structure

hyperliquid-ai-bot/
β”œβ”€β”€ πŸ“„ bot.py                 # Main trading bot orchestrator
β”œβ”€β”€ πŸ“„ run.py                 # Entry point with web UI
β”œβ”€β”€ πŸ“„ api.py                 # FastAPI web server
β”œβ”€β”€ πŸ“„ config.py              # Configuration management
β”œβ”€β”€ πŸ“„ executor.py            # Order execution & tracking
β”œβ”€β”€ πŸ“„ risk.py                # Risk management & circuit breaker
β”œβ”€β”€ πŸ“„ market_data.py         # WebSocket + REST data feeds
β”œβ”€β”€ πŸ“„ memory.py              # SQLite trade journal
β”œβ”€β”€ πŸ“„ knowledge.py           # Knowledge management system
β”œβ”€β”€ πŸ“„ llm_intervention.py    # LLM decision engine
β”œβ”€β”€ πŸ“„ strategy_manager.py    # Strategy registry & scoring
β”œβ”€β”€ πŸ“„ backtest.py            # Historical simulation
β”œβ”€β”€ πŸ“„ optimizer.py           # Parameter optimization
β”œβ”€β”€ πŸ“„ llm_reviewer.py        # LLM self-review
β”œβ”€β”€ πŸ“ strategies/
β”‚   β”œβ”€β”€ base.py               # Base strategy class
β”‚   β”œβ”€β”€ ema_cross.py          # EMA crossover strategy
β”‚   β”œβ”€β”€ bollinger_rsi.py      # Bollinger + RSI strategy
β”‚   β”œβ”€β”€ ml_signal.py          # XGBoost ML strategy
β”‚   β”œβ”€β”€ ensemble_strategy.py  # Multi-regime ensemble
β”‚   β”œβ”€β”€ regime_detector.py    # HMM regime detection
β”‚   └── signal_layer.py       # Advanced signals
β”œβ”€β”€ πŸ“ tests/                 # Unit tests
β”œβ”€β”€ πŸ“ static/                # Web UI assets
β”œβ”€β”€ πŸ“ data/                  # Models & knowledge
β”œβ”€β”€ πŸ“ logs/                  # Runtime logs
β”œβ”€β”€ πŸ“ reports/               # Daily reports
β”œβ”€β”€ 🐳 Dockerfile             # Docker image
β”œβ”€β”€ 🐳 docker-compose.yml     # Docker orchestration
└── πŸ“„ requirements.txt       # Python dependencies

🌐 Web UI Endpoints

Method Endpoint Description
GET /health Health check
GET /status Account & positions
GET /config Current configuration
POST /config Update configuration
POST /secrets Update API keys
POST /circuit-breaker/reset Reset circuit breaker
POST /bot/start Start trading
POST /bot/stop Stop trading
GET /knowledge Knowledge base
POST /intervention/trigger Trigger LLM review
GET /intervention/history Intervention history

πŸ§ͺ Testing

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ -v --cov=. --cov-report=html

# Run specific test
pytest tests/test_strategies.py -v

🐳 Docker Commands

# Build image
docker-compose build

# Start container
docker-compose up -d

# View logs
docker-compose logs -f

# Check status
docker-compose ps

# Restart
docker-compose restart

# Stop
docker-compose down

# Rebuild after changes
docker-compose up -d --build

πŸ“Š Expected Performance

Based on academic research benchmarks:

Metric Expected Range
Sharpe Ratio 1.5 - 2.5
Max Drawdown < 15%
Win Rate 55 - 65%
Profit Factor 1.8 - 2.5

πŸ›‘οΈ Safety Features

  1. Circuit Breaker: Halts trading on 15% drawdown
  2. Stop-Loss Enforcement: Required on every trade
  3. Kelly Criterion: Fractional position sizing
  4. Max Leverage: Enforced maximum leverage
  5. Testnet First: Always test on testnet before mainnet

πŸ”§ Hyperliquid Setup

1. Create API Wallet

  1. Go to Hyperliquid
  2. Connect your main wallet
  3. Navigate to Settings > API
  4. Create a new API wallet
  5. Copy the API wallet private key to HL_PRIVATE_KEY
  6. Use your main wallet address for HL_WALLET_ADDRESS

2. Fund Your Account

3. Approve API Wallet

In Hyperliquid UI, approve your API wallet for trading.


πŸ“š Documentation


🀝 Contributing

Contributions are welcome! Please read our contributing guidelines before submitting PRs.


⚠️ Disclaimer

USE AT YOUR OWN RISK. This bot trades real money. Always:

  1. Test thoroughly on testnet first
  2. Start with small position sizes
  3. Monitor closely for the first 48 hours
  4. Never risk more than you can afford to lose

πŸ“„ License

MIT License - see LICENSE for details.


πŸ™ Acknowledgments

  • Academic research from arXiv, MDPI, ScienceDirect
  • Hyperliquid Python SDK
  • Kimi K2.5 for LLM capabilities
  • OpenRouter for API access

About

Autonomous AI trading bot for Hyperliquid DEX perpetual futures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages