Skip to content

dpk404/hyperliquid-trading-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hyperliquid AI Trading Bot

An AI-powered crypto futures trading bot for Hyperliquid DEX with a full terminal UI, built with Python and Claude AI.

┌──────────────────────────────────────────────────────────────┐
│  HYPERLIQUID AI BOT            [PAPER] [TESTNET]    HH:MM:SS│
├────────────────────┬────────────────────┬────────────────────┤
│ PRICES & MARKET    │ OPEN POSITIONS     │ TECHNICAL          │
│ BTC  $69,833  +1%  │ BTC LONG  0.05     │ RSI MACD ADX BB   │
│ ETH   $2,148  -1%  │ ETH SHORT 2.0      │ 65  +50  32  0.7  │
│ SOL     $175  +3%  │                    │ 28  -20  18  0.1  │
├────────────────────┼────────────────────┼────────────────────┤
│ SIGNALS            │ AI DECISIONS       │ BOT STATS          │
│ BTC LONG str=0.72  │ BTC BUY  conf=85%  │ Equity:  $10,536   │
│ ETH SHORT str=0.65 │ ETH HOLD conf=40%  │ PnL:       +$536   │
│                    │                    │ Win Rate:   62.5%  │
├────────────────────┴────────────────────┴────────────────────┤
│ ACTIVITY LOG                                                 │
│ 14:32:05 SIGNAL BTC LONG strength=0.72                       │
│ 14:32:15 AI     BTC -> BUY conf=85% $0.0012                 │
│ 14:32:16 TRADE  ORDER BUY BTC size=0.02 @ $69,833           │
└──────────────────────────────────────────────────────────────┘
  q Quit  m Settings  p Pause  l Log  d Debug  c Close All  r Reset CB

Features

  • Hybrid AI + Local Analysis — Local technical indicators handle 80% of decisions for free; Claude AI handles the complex 20%
  • Full Terminal UI — 6-panel live dashboard with prices, positions, indicators, signals, AI decisions, and stats
  • Dynamic Coin Scanner — Automatically picks top coins by volatility, trend strength, momentum, and volume
  • Risk Management — Position sizing, trailing stops, daily loss limits, max drawdown circuit breaker, profit targets
  • Paper Trading — Same code path as live trading, backed by simulated execution with real market data
  • Cost Optimized AI — Model tiering (Haiku/Sonnet), similarity-hash caching, summarized prompts (~$0.20-0.60/day)
  • Settings Screen — Change mode, credentials, risk params, and AI config without restarting
  • Backtesting — Validate strategies on historical data before risking capital

Quick Start

# Install uv (package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Setup
uv venv .venv --python 3.12
source .venv/bin/activate
uv pip install -e ".[dev,tui]"

# Launch (interactive menu)
hypertrade

That's it. The interactive menu gives you all options:

╔═══════════════════════════════════════════════════════════╗
║   ██╗  ██╗██╗   ██╗██████╗ ███████╗██████╗              ║
║   ███████║ ╚████╔╝ ██████╔╝█████╗  ██████╔╝             ║
║   ██║  ██║   ██║   ██║     ███████╗██║  ██║              ║
║   TRADE   AI-Powered Crypto Futures on Hyperliquid       ║
╚═══════════════════════════════════════════════════════════╝

  Status: .env found | API key set | Wallet set

? What would you like to do?
❯ Demo Mode        — Simulated data, no keys needed
  Paper Trading    — Real prices, simulated trades
  Live Trading     — Real orders on exchange
  ──────────────
  Settings         — Configure keys, risk, AI
  Check Connection — Test exchange connectivity
  Fetch Data       — Download historical candles
  Run Backtest     — Test strategy on history
  ──────────────
  Quit

Or use direct commands:

hypertrade demo      # Skip menu, straight to demo
hypertrade check     # Test connection
hypertrade fetch     # Download historical data
hypertrade backtest  # Run backtest

Architecture

WebSocket ──> DataFeed ──> IndicatorEngine ──> SignalGenerator
                                                     │
                                          ┌──────────┴──────────┐
                                   Local Decision (80%)    Claude AI (20%)
                                          └──────────┬──────────┘
                                                 Strategy
                                                     │
                                          RiskManager ──> OrderManager ──> Hyperliquid
                                                     │
                                          PositionTracker / StopLossEngine / CircuitBreaker

Key principle: Pre-compute all indicators locally, send only a 200-token summary to Claude (not 15,000 tokens of raw candles). This cuts AI costs by 75x.

Project Structure

src/
├── core/           Config, event bus, orchestrator (main loop)
├── exchange/       Hyperliquid SDK wrapper, WebSocket data feed, paper exchange
├── analysis/       Technical indicators (pandas-ta), signal generator, coin scanner
├── ai/             Claude API client, prompt builder, response parser, cache
├── strategy/       Trading strategies (momentum, mean reversion)
├── risk/           Position sizing, stop-loss engine, circuit breaker
├── execution/      Order manager, position tracker
├── monitoring/     Structured logging, metrics, alerts
└── tui/            Terminal UI (Textual), settings screen, demo orchestrator
backtest/           Historical data loader, backtesting.py integration
config/             YAML configuration files
scripts/            Connection checker, historical data fetcher

Trading Modes

Mode Testnet What Happens
paper true Simulated trades, testnet data. Start here.
paper false Simulated trades, real mainnet prices
live true Real orders on Hyperliquid testnet (free test money)
live false Real money on mainnet (prompts for confirmation)

TUI Keyboard Shortcuts

Key Action
q Quit
m Open Settings (mode, credentials, risk, AI config)
p Pause / Resume trading
l Focus activity log
d Toggle debug mode
c Close all positions + auto-pause
r Reset circuit breaker

Configuration

All settings configurable via:

  1. YAML file (config/default.yaml)
  2. Environment variables (.env)
  3. TUI Settings screen (press m)

Key settings:

exchange:
  mode: paper                    # paper | live
  testnet: true                  # true | false

trading:
  coins: [BTC, ETH]             # Coins to trade (always kept)
  auto_select_coins: false       # Auto-pick top coins by opportunity
  auto_select_top_n: 5           # How many to pick
  default_leverage: 3

risk:
  max_daily_loss_pct: 0.05       # Circuit breaker: 5% daily loss
  max_drawdown_pct: 0.15         # Circuit breaker: 15% drawdown
  profit_target_pct: 0.0         # 0 = disabled, 0.10 = stop at +10%
  default_stop_loss_pct: 0.02    # 2% per-trade stop loss
  default_take_profit_pct: 0.04  # 4% per-trade take profit

claude:
  routine_interval_seconds: 900  # AI analysis every 15 min
  daily_cost_cap_usd: 50.0       # Hard daily spending limit

AI Cost Optimization

Technique Effect
Two-tier models (Haiku routine, Sonnet major) 90% of calls at 10-20x lower cost
Pre-computed indicator summaries (~200 tokens) 75x fewer input tokens vs raw candles
Similarity-hash response cache (30-min TTL) ~30% fewer API calls
Local rule-based decisions for 80% of trades 80% of decisions are free
Hard daily cost cap with local-only fallback Prevents runaway costs

Projected cost: ~$0.20-0.60/day

Dependencies

Documentation

See docs/GUIDE.md for the full user guide covering:

  • Installation & setup
  • Wallet setup & testnet instructions
  • All CLI commands with examples
  • TUI dashboard & settings screen
  • Dynamic coin scanner
  • Profit target
  • Configuration reference
  • Backtesting
  • Troubleshooting

Disclaimer

This software is for educational and research purposes. Algorithmic trading carries significant financial risk. Past performance does not guarantee future results. Always start with paper trading and minimal capital. Never trade with money you cannot afford to lose.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages