A Python-based algorithmic trading bot for the Hyperliquid decentralized perpetuals exchange. The bot implements a multi-timeframe trend-following strategy with ATR-based volatility targeting and Chandelier Exit risk management.
- Multi-Timeframe Analysis: Daily trend (SMA/EMA) + Intraday signals (VWAP/RSI)
- Automated Trading: Fully automated entry with dynamic position sizing
- ATR Volatility Targeting: Position size calculated from risk % and ATR-based SL distance
- Chandelier Exit: Dynamic trailing stop that follows price using ATR multiplier
- Kill Switch: Emergency shutdown via Ctrl+C (cancels all orders, closes positions)
- Live Dashboard: Real-time terminal display of market data and positions
- Limit Orders for Entry: Earn maker rebates by placing limit orders at best bid/ask
- Macro Filters: Block trades based on funding rate or low volatility conditions
- State Recovery: Automatically recovers position tracking after bot restarts
- Telegram Alerts: Real-time notifications for trades and bot status
- Interactive Telegram Bot: Remote control via Telegram commands
The bot includes an interactive Telegram interface for remote monitoring and control:
| Command | Description |
|---|---|
/status |
Account balance, positions, and unrealized PnL |
/config |
Current configuration (strategy, ATR parameters, risk) |
/pause |
Pause new trade entries (keeps managing existing positions) |
/resume |
Resume trading |
/panic |
|
/help |
Show available commands |
Security: The bot only responds to the TELEGRAM_CHAT_ID defined in your .env file.
The bot follows a trend-continuation strategy:
| Condition | Action |
|---|---|
| Price > Daily SMA + VWAP cross up + RSI exiting oversold | LONG |
| Price < Daily SMA + VWAP cross down + RSI exiting overbought | SHORT |
Entry Logic:
- Daily Trend: Price above/below SMA determines direction (only LONG when bullish, only SHORT when bearish)
- VWAP Confirmation: Price must cross VWAP in the trend direction
- RSI Timing: RSI must be exiting extreme zone (< 30 for longs, > 70 for shorts)
Exit Logic (Chandelier Exit):
- No fixed Take Profit - positions trail with ATR-based stop
- LONG:
SL = max(prev_SL, highest_high - ATR Γ trail_multiplier) - SHORT:
SL = min(prev_SL, lowest_low + ATR Γ trail_multiplier)
- Python 3.13+
- uv package manager
- Hyperliquid account with API access
# Clone the repository
git clone https://github.com/yourusername/bot_hyperliquide.git
cd bot_hyperliquide
# Install dependencies
uv sync- Set up your API credentials (copy the example and fill in your details):
cp .env.example .env
nano .envHYPERLIQUID_PRIVATE_KEY=your_private_key_here
HYPERLIQUID_WALLET_ADDRESS=0xYourWalletAddressHere
HYPERLIQUID_TESTNET=true
# Optional: Telegram notifications
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_CHAT_ID=your_chat_id_here- Adjust trading parameters in
config.json:
{
"trading": {
"symbols": ["BTC", "ETH"],
"margin_type": "isolated",
"max_leverage": 10
},
"strategy": {
"daily_ma_type": "SMA",
"daily_ma_period": 50,
"intraday_timeframe": "15m",
"rsi_period": 14,
"rsi_oversold": 30,
"rsi_overbought": 70
},
"risk_management": {
"risk_percent_per_trade": 2.0,
"atr_period": 14,
"atr_sl_multiplier": 1.5,
"atr_trailing_multiplier": 2.0,
"use_limit_orders": false,
"limit_order_timeout": 60
},
"notifications": {
"enable_telegram_alerts": false
}
}To receive trade alerts on your phone:
-
Create a Telegram Bot:
- Message @BotFather on Telegram
- Send
/newbotand follow the prompts - Copy the bot token
-
Get your Chat ID:
- Start a chat with your new bot
- Visit:
https://api.telegram.org/bot<YourBotToken>/getUpdates - Look for
"chat":{"id":XXXXXXXX}- that's your chat ID
-
Configure:
- Add credentials to
.env - Set
"enable_telegram_alerts": trueinconfig.json
- Add credentials to
Notification types:
- π€ Bot startup/shutdown
- π’/π΄ Trade opened (LONG/SHORT) with ATR-based SL
- π° Trade closed via Chandelier Exit with PnL
- π Trailing stop updates
β οΈ Error alerts
uv run python main.pyPress Ctrl+C at any time to trigger an emergency shutdown:
- β Cancels all pending orders
- π Closes all open positions at market price
- π Exits gracefully
The backtest/ folder contains a grid search optimizer to find the best ATR parameters:
uv run python backtest/run_optimization.pyThis will:
- Fetch last 30 days of BTC 15m candles from Hyperliquid
- Test ATR multiplier combinations (SL: 1.0-2.5, Trail: 1.5-3.0)
- Print a detailed performance report
- Directly update
config.jsonwith optimal parameters - Send Telegram notification with results (if configured)
Metrics available:
total_pnl- Total profit/loss (default)sharpe_ratio- Risk-adjusted returnsprofit_factor- Gross profit / gross losswin_rate- Percentage of winning trades
bot_hyperliquide/
βββ .env # API credentials (NEVER commit!)
βββ .env.example # Template for .env
βββ config.json # Trading parameters
βββ pyproject.toml # Project dependencies
β
βββ main.py # Entry point (run this)
β
βββ backtest/ # Parameter optimization
β βββ backtester.py # ATR volatility targeting simulation
β βββ optimizer.py # Grid search optimizer
β βββ run_optimization.py # Run optimization script
β
βββ src/
β βββ config/
β β βββ settings.py # Configuration loader
β β
β βββ exchange/
β β βββ client.py # Hyperliquid SDK wrapper
β β
β βββ strategy/
β β βββ indicators.py # Technical indicators (SMA, RSI, VWAP, ATR)
β β βββ signals.py # Entry signal logic
β β
β βββ risk/
β β βββ manager.py # ATR volatility targeting, Chandelier Exit
β β
β βββ utils/
β βββ logger.py # Terminal logging
β βββ notifier.py # Telegram notifications
β βββ telegram_bot.py # Interactive Telegram commands
β
βββ tests/ # Test scripts
| Parameter | Description | Default |
|---|---|---|
symbols |
Trading pairs | ["BTC", "ETH"] |
max_leverage |
Maximum allowed leverage | 10 |
margin_type |
Margin mode | isolated |
| Parameter | Description | Default |
|---|---|---|
daily_ma_type |
Moving average type | SMA |
daily_ma_period |
MA period | 50 |
intraday_timeframe |
Candle timeframe | 15m |
rsi_period |
RSI calculation period | 14 |
rsi_oversold |
Oversold threshold | 30 |
rsi_overbought |
Overbought threshold | 70 |
| Parameter | Description | Default |
|---|---|---|
risk_percent_per_trade |
% of account to risk per trade | 2.0 |
atr_period |
ATR calculation period | 14 |
atr_sl_multiplier |
ATR multiplier for initial SL | 1.5 |
atr_trailing_multiplier |
ATR multiplier for Chandelier Exit | 2.0 |
use_limit_orders |
Use limit orders for entry | false |
limit_order_timeout |
Seconds to wait for limit fill | 60 |
| Parameter | Description | Default |
|---|---|---|
funding_filter_enabled |
Block trades when funding is extreme | false |
funding_threshold |
Funding rate threshold (%) | 0.01 |
volatility_filter_enabled |
Block trades in low volatility | false |
volatility_threshold |
ATR ratio threshold | 0.5 |
# Test the Hyperliquid client (requires valid .env)
uv run python tests/test_client.py
# Test indicators (no API required)
uv run python tests/test_indicators.py
# Test risk manager (no API required)
uv run python tests/test_risk_manager.py
# Test signal generation (no API required)
uv run python tests/test_signals.pyEdit src/strategy/indicators.py:
def add_macd(df: pd.DataFrame, fast: int = 12, slow: int = 26, signal: int = 9) -> pd.DataFrame:
df = df.copy()
macd = ta.macd(df["close"], fast=fast, slow=slow, signal=signal)
df = pd.concat([df, macd], axis=1)
return dfEdit src/strategy/signals.py in the analyze() method to customize entry conditions.
USE AT YOUR OWN RISK. This bot is provided for educational purposes only.
- Trading cryptocurrencies involves substantial risk of loss
- Past performance does not guarantee future results
- Never trade with money you cannot afford to lose
- Always test on testnet before using real funds
- The authors are not responsible for any financial losses
MIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.