Skip to content

jim788e/HyperliquidUsdcSimpleBot

Repository files navigation

πŸš€ Hyperliquid Trading Bot

Python 3.8+ License: MIT Hyperliquid

A powerful, user-friendly trading bot for Hyperliquid with USDC-based trading, leverage support, and comprehensive risk management.

✨ Features

  • 🎯 USDC-based Trading: Trade with easy-to-understand USDC amounts
  • ⚑ Leverage Support: 1x to 10x leverage with automatic position sizing
  • πŸ–₯️ Interactive Interface: User-friendly parameter configuration
  • πŸ›‘οΈ Risk Management: Built-in stop loss, take profit, and position limits
  • πŸš€ Market Orders: Fast execution with market price orders
  • πŸ“Š Position Management: Open, close, and monitor positions
  • πŸ”„ Real-time Updates: Live position monitoring and PnL tracking

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/your-username/hyperliquid_trader.git
cd hyperliquid_trader

2. Install Dependencies

# Option 1: Use setup script (recommended)
python setup.py

# Option 2: Manual installation
pip install -r requirements.txt

3. Configure API Keys

# Copy environment template
cp config.env.example .env

# Edit .env with your API keys
# Get API keys from: https://app.hyperliquid.xyz/API

4. Start Trading

# Quick start (recommended)
python start_trading.py

# Direct trading interface
python trade_usdc.py

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • Hyperliquid account
  • API Agent Wallet (get from Hyperliquid API)
  • Minimum $10 in your API wallet

πŸ”§ Configuration

Environment Variables (.env)

# Hyperliquid API Configuration
HYPERLIQUID_API_KEY=your_api_key_here
HYPERLIQUID_SECRET_KEY=your_secret_key_here
HYPERLIQUID_BASE_URL=https://api.hyperliquid.xyz

# Trading Configuration
DEFAULT_SYMBOL=ETH
DEFAULT_SIDE=long
DEFAULT_SIZE=0.1
DEFAULT_LEVERAGE=1.0

# Risk Management
MAX_POSITION_SIZE=1.0
STOP_LOSS_PERCENTAGE=5.0
TAKE_PROFIT_PERCENTAGE=10.0

# Monitoring
MONITORING_INTERVAL=5
ENABLE_WEBSOCKET=true

# Advanced Risk Management
MAX_DAILY_LOSS=100.0
MAX_POSITION_PERCENTAGE=0.1
MAX_LEVERAGE=10.0
EMERGENCY_STOP_LOSS=20.0

Available API Functions

The bot provides comprehensive API access:

Account Information:

  • get_account_value() - Get total account value in USD
  • get_user_state() - Get complete user account state
  • get_position(coin) - Get position for specific coin
  • get_available_balance() - Get available trading balance

Market Data:

  • get_l2_book(coin) - Get order book data
  • get_candles(coin, interval, start_time, end_time) - Historical price data
  • get_trades(coin) - Recent trades for a coin
  • get_meta() - Exchange metadata and asset information

Trading Operations:

  • place_market_order(coin, is_buy, sz, leverage) - Execute market orders
  • place_order(coin, is_buy, sz, limit_px, leverage) - Place limit orders
  • update_leverage(coin, leverage) - Update position leverage
  • cancel_order(oid) - Cancel specific order
  • cancel_all_orders(coin) - Cancel all orders

Position Management:

  • buy(usdc_amount, use_usdc) - Buy with USDC amount
  • sell(usdc_amount, use_usdc) - Sell with USDC amount
  • close_position() - Close specific position
  • close_all_positions() - Emergency close all positions

πŸ’‘ Usage Examples

Trading Commands

# Interactive trading interface
python trade_usdc.py

# Show help and options
python trade_usdc.py help

# Quick start launcher
python start_trading.py

Main Menu Functions

The trading interface provides 4 main options:

  1. Check Positions - View all open positions and PnL

    • Shows account value and balance
    • Displays position details (symbol, side, size, entry price, leverage)
    • Shows unrealized PnL for each position
    • Overall account status (profit/loss)
  2. Place Trade - Execute new trades

    • Interactive parameter configuration
    • Symbol selection (ETH, BTC, SOL, AVAX)
    • Position side (long/short/close)
    • USDC amount input
    • Leverage setting (1x-10x)
    • Risk management parameters
  3. Close All Positions - Emergency exit all positions

    • Lists all open positions
    • Confirmation prompt
    • Closes all positions at market price
    • Shows success/failure status
  4. Exit - Close the interface

Trading Scenarios

  • Long ETH: $100 with 3x leverage = $300 position
  • Short BTC: $50 with 2x leverage = $100 position
  • Close Position: Market price exit
  • Close All: Emergency exit all positions

πŸ“Š Trading Parameters

Parameter Description Example
Symbol Trading pair ETH, BTC, SOL, AVAX
Side Position direction long, short, close
USDC Amount Investment amount $100
Leverage Position multiplier 3x = 3x position size
Stop Loss Risk management 5% below entry
Take Profit Profit target 10% above entry

πŸ›‘οΈ Risk Management

  • Stop Loss: Automatic exit at specified loss percentage
  • Take Profit: Automatic exit at specified profit percentage
  • Position Limits: Maximum position size controls
  • Daily Limits: Maximum daily loss protection
  • Emergency Stop: Circuit breaker for extreme losses

🎯 Supported Assets

  • ETH (Ethereum)
  • BTC (Bitcoin)
  • SOL (Solana)
  • AVAX (Avalanche)
  • And more...

πŸ“ˆ Leverage Examples

Investment Leverage Position Value
$100 1x $100
$100 3x $300
$100 5x $500
$100 10x $1,000

πŸ”§ Project Structure

hyperliquid_trader/
β”œβ”€β”€ πŸ“ .github/                 # GitHub workflows and templates
β”œβ”€β”€ πŸ“„ trade_usdc.py            # Main trading interface
β”œβ”€β”€ πŸ“„ hyperliquid_client.py   # API client (hybrid SDK + direct API)
β”œβ”€β”€ πŸ“„ trading_bot.py          # Trading logic and risk management
β”œβ”€β”€ πŸ“„ config.py               # Configuration management
β”œβ”€β”€ πŸ“„ start_trading.py        # Quick start launcher
β”œβ”€β”€ πŸ“„ setup.py               # Setup and installation script
β”œβ”€β”€ πŸ“„ requirements.txt       # Python dependencies
β”œβ”€β”€ πŸ“„ config.env.example     # Environment template
β”œβ”€β”€ πŸ“„ .gitignore            # Git ignore rules
β”œβ”€β”€ πŸ“„ LICENSE               # MIT License
β”œβ”€β”€ πŸ“„ CONTRIBUTING.md       # Contribution guidelines
β”œβ”€β”€ πŸ“„ QUICK_START.md        # Quick start guide
β”œβ”€β”€ πŸ“„ hyperliquid_analysis.md # Technical analysis
└── πŸ“„ README.md             # This file

πŸ›‘οΈ Safety Features

  • βœ… Input Validation: All parameters validated
  • βœ… Balance Checks: Prevents over-trading
  • βœ… Error Handling: Graceful error recovery
  • βœ… Position Limits: Maximum position controls
  • βœ… Risk Controls: Stop loss and take profit
  • βœ… Account Value Monitoring: Real-time account value tracking
  • βœ… Position Size Validation: Prevents oversized positions
  • βœ… Leverage Limits: Maximum leverage controls (1x-10x)
  • βœ… Emergency Stop: Circuit breaker for extreme losses
  • βœ… Confirmation Prompts: Trade confirmation before execution

🚨 Troubleshooting

Common Issues

  1. "Insufficient margin" error

    • Check your API Agent Wallet balance
    • Ensure funds are transferred to API wallet
    • Verify minimum order requirements ($10+)
  2. "Account value $0.00"

    • Fund your API Agent Wallet
    • Check API key configuration
    • Verify wallet address in .env
  3. Leverage not working

    • Fixed in latest version
    • Position size now correctly calculated with leverage

Getting Help

  • Check your .env configuration
  • Verify API keys are correct
  • Ensure sufficient account balance
  • Check minimum order requirements

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

How to Contribute

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

Trading cryptocurrencies involves substantial risk of loss. This software is provided as-is without warranty. Use responsibly and never risk more than you can afford to lose.

πŸ”— Links

πŸ“Š Technical Details

This bot uses a hybrid approach:

  • Official Hyperliquid Python SDK for trading operations
  • Direct API calls for market data and account information
  • Comprehensive risk management with stop loss and take profit
  • Real-time position monitoring and PnL tracking

Architecture Overview

  • Hybrid API Client: Combines SDK and direct API calls
  • Trading Bot: Handles trading logic and risk management
  • Interactive Interface: User-friendly parameter configuration
  • Configuration Management: Environment-based settings
  • Setup Automation: Automated dependency installation

Key Components

  1. HyperliquidClient: API client with hybrid approach
  2. TradingBot: Core trading logic and risk management
  3. TradingConfig: Configuration management
  4. Interactive Interface: User-friendly trading interface
  5. Setup Scripts: Automated installation and configuration

For detailed technical analysis, see hyperliquid_analysis.md.


⭐ Star this repository if you find it helpful!

About

A standalone trading bot for Hyperliquid with USDC-based trading and leverage support.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages