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.
- 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)
- 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
- Kimi K2.5 integration for autonomous decision making
- Knowledge persistence across trading sessions
- Self-improving through accumulated experience
- Configurable intervention intervals (default: 4 hours)
- One-command deployment with Docker Compose
- Non-root container for security
- Health checks and automatic restarts
- Volume persistence for data and logs
- Real-time status monitoring
- Position management with PnL tracking
- Circuit breaker control
- Configuration editor
- Secrets management (masked inputs)
- LLM intervention trigger and history
# 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# 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| 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) |
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| 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 |
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
| 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 |
# 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# 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 --buildBased 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 |
- Circuit Breaker: Halts trading on 15% drawdown
- Stop-Loss Enforcement: Required on every trade
- Kelly Criterion: Fractional position sizing
- Max Leverage: Enforced maximum leverage
- Testnet First: Always test on testnet before mainnet
- Go to Hyperliquid
- Connect your main wallet
- Navigate to Settings > API
- Create a new API wallet
- Copy the API wallet private key to
HL_PRIVATE_KEY - Use your main wallet address for
HL_WALLET_ADDRESS
- Testnet: Use the Hyperliquid Testnet Faucet
- Mainnet: Deposit USDC to your perps account
In Hyperliquid UI, approve your API wallet for trading.
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
USE AT YOUR OWN RISK. This bot trades real money. Always:
- Test thoroughly on testnet first
- Start with small position sizes
- Monitor closely for the first 48 hours
- Never risk more than you can afford to lose
MIT License - see LICENSE for details.
- Academic research from arXiv, MDPI, ScienceDirect
- Hyperliquid Python SDK
- Kimi K2.5 for LLM capabilities
- OpenRouter for API access