Skip to content

catsika/Hyperliquid-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hyperliquid HYPE Accumulator β€” Spot Grid Bot

A high-performance spot grid trading bot written in Go, designed to accumulate HYPE on the Hyperliquid DEX. Features a rich terminal dashboard, WebSocket-driven fill detection, geometric grid spacing, and automatic risk management.

Warning

Trading risk disclaimer: this bot places real orders with real funds. Crypto markets are volatile and you can lose capital quickly. Use this software at your own risk.

Safe first run: start with small capital, low leverage/no leverage, conservative grid settings, and monitor closely before scaling up.

Important

Security first: never commit .env, private keys, wallet secrets, or exchange credentials to git. Keep secrets local, and immediately rotate/revoke any key that was exposed or committed (even briefly).


🎯 How It Works

  1. You define a price range (e.g., Β±3% around current price)
  2. The bot builds a grid of buy/sell levels using geometric spacing
  3. Buy orders are placed below the current price, sell orders above
  4. On each sell, the bot keeps a percentage of HYPE (e.g., 5%) as profit
  5. Rinse and repeat β€” the more the price oscillates, the more HYPE you accumulate

Key Features

  • Geometric grid spacing β€” Equal percentage gaps between levels (better than linear for volatile assets)
  • Near-price weighting β€” Concentrates more capital near the current price for higher fill rates
  • Auto-recentering β€” Grid automatically rebuilds when price drifts too far from center
  • WebSocket fills β€” Instant fill detection via WS, with REST sync as safety net
  • Heartbeat monitoring β€” Detects stale WS connections and auto-reconnects
  • Fee tracking β€” Accurate P&L accounting including trading fees
  • Telegram notifications β€” Daily accumulation reports sent to your phone
  • Terminal dashboard β€” Real-time TUI with grid visualization, P&L, and trade history
  • Headless mode β€” Perfect for VPS/Docker deployment
  • Graceful shutdown β€” Cancels all orders on Ctrl+C

πŸš€ Quick Start

Prerequisites

  • Linux host (for gridbot-linux) or Docker
  • A Hyperliquid account with USDC and/or HYPE balance

1. Clone

git clone https://github.com/catsika/Hyperliquid-Bot.git
cd Hyperliquid-Bot

2. Configure local secrets

cp .env.example .env
# Edit .env with your own wallet + key (keep this file local)

3. Apply conservative first-run settings

Start small and tighten risk controls before live scaling. Example:

CAPITAL_ALLOCATION=0.10
INITIAL_DEPLOY_PCT=0.20
GRID_LEVELS=6
MAX_DRAWDOWN_PCT=0.05

4. Run

chmod +x ./gridbot-linux
./gridbot-linux

πŸ” Security Guidance

  • Never paste private keys into chats, issues, screenshots, or logs.
  • Never commit secrets to git history (.env, key files, exported account dumps).
  • Use dedicated API/wallet credentials with least privilege where possible.
  • If a key is ever exposed or committed, treat it as compromised: rotate immediately.
  • Review SECURITY.md for vulnerability reporting and coordinated disclosure.

🐳 Advanced: Docker Deployment

# Build
docker build -t hype-gridbot .

# Run (mount your .env file)
docker run -d --name hype-gridbot --env-file .env hype-gridbot

βš™οΈ Configuration

All settings are configured via environment variables (.env file):

API Credentials

Variable Description
HL_ACCOUNT_ADDRESS Your Hyperliquid wallet address
HL_PRIVATE_KEY Your private key (never shared, stays local)

Grid Parameters

Variable Default Description
GRID_LEVELS 30 Number of grid levels (20-50 recommended)
GRID_RANGE_PCT 0.03 Grid range as % of spot price (0.03 = Β±1.5%)
SELL_BACK_PCT 0.95 Sell back 95%, keep 5% HYPE per round-trip
CAPITAL_ALLOCATION 0.95 % of USDC to deploy in the grid
NEAR_PRICE_WEIGHT 2.0 Weight multiplier for levels near spot (1.0 = uniform)
RECENTER_THRESHOLD_PCT 0.6 Auto-recenter when price exits 60% of range

Risk Management

Variable Default Description
STOP_LOSS_PRICE 0.0 Hard stop-loss price (0 = disabled)
MAX_DRAWDOWN_PCT 0.10 Max 10% drawdown from peak equity triggers emergency sell
MIN_ORDER_SIZE_USD 5.0 Minimum order size in USD

Timing & Display

Variable Default Description
MAINTENANCE_INTERVAL_SECONDS 5.0 How often to sync and maintain the grid
DEBUG_MODE False Show debug information

Notifications (Optional)

Variable Default Description
TELEGRAM_BOT_TOKEN "" Telegram bot token for daily reports
TELEGRAM_CHAT_ID "" Telegram chat ID for daily reports

πŸ— Architecture

gridbot-linux                # Prebuilt Linux binary
internal/
β”œβ”€β”€ config/config.go          # Configuration loading & validation
β”œβ”€β”€ exchange/
β”‚   β”œβ”€β”€ client.go             # Hyperliquid REST API wrapper
β”‚   β”œβ”€β”€ websocket.go          # WebSocket client with heartbeat monitoring
β”‚   └── types.go              # Shared types
β”œβ”€β”€ grid/
β”‚   β”œβ”€β”€ engine.go             # Core grid logic (build, place, fill, recenter)
β”‚   β”œβ”€β”€ engine_test.go        # Unit tests
β”‚   └── risk.go               # Risk management (stop-loss, max drawdown)
β”œβ”€β”€ accounting/
β”‚   └── tracker.go            # P&L, fee tracking, HYPE accumulation stats
β”œβ”€β”€ tui/
β”‚   └── dashboard.go          # Terminal UI rendering
└── notifier/
    └── notifier.go           # Telegram notification sender

Data Flow

WebSocket ──→ Fill Events ──→ Engine.HandleFill() ──→ Counter Orders
         ──→ Price Updates ──→ Engine.UpdatePrice()

Maintenance Ticker ──→ Engine.Maintain()
                       β”œβ”€β”€ updateAccountData()
                       β”œβ”€β”€ syncOrders() (REST safety net)
                       β”œβ”€β”€ checkRisk()
                       β”œβ”€β”€ auto-recenter (if needed)
                       └── fillGridGaps()

πŸ“Š Example

With default settings (GRID_LEVELS=30, GRID_RANGE_PCT=0.03, SELL_BACK_PCT=0.95):

  • If HYPE is at $25.00, the grid spans $24.625 β€” $25.375
  • 30 levels with geometric spacing (~0.1% between each)
  • More capital concentrated near $25.00 (2x weight)
  • Each round-trip (buy β†’ sell) keeps 5% of the HYPE
  • If price oscillates 10 times through a level: ~0.5 HYPE accumulated from that level alone

πŸ§ͺ Running Tests

go test ./internal/... -v

πŸš€ Advanced: VPS Deployment (systemd)

# Copy gridbot.service to systemd
sudo cp gridbot.service /etc/systemd/system/
sudo systemctl enable gridbot
sudo systemctl start gridbot

# Check logs
sudo journalctl -u gridbot -f

⚠️ Disclaimer

This bot is for educational purposes. Trading crypto involves significant risk. Grid bots perform best in ranging/sideways markets β€” strong trends can lead to losses. Only trade with funds you can afford to lose. The authors are not responsible for any financial losses.

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors