|
@@ -1,338 +0,0 @@
|
|
|
-# 🚀 Deployment Guide - How to Run Your Trading Bot
|
|
|
-
|
|
|
-This guide explains the different ways to run your Hyperliquid trading bot and best practices for each approach.
|
|
|
-
|
|
|
-## 📋 Overview
|
|
|
-
|
|
|
-You have **three different bot types**:
|
|
|
-
|
|
|
-| Bot Type | File | Purpose | Running Time |
|
|
|
-|----------|------|---------|--------------|
|
|
|
-| **Telegram Bot** | `telegram_bot.py` | Remote control interface | Continuous |
|
|
|
-| **Strategy Bot** | `strategy_bot.py` | Automated trading strategies | Continuous |
|
|
|
-| **Terminal Bot** | `simple_bot.py` | Interactive terminal interface | On-demand |
|
|
|
-
|
|
|
-## 🎯 **Different Use Cases**
|
|
|
-
|
|
|
-### **Use Case 1: Manual Trading with Remote Control**
|
|
|
-**Goal**: Monitor and control manually via Telegram
|
|
|
-```bash
|
|
|
-# Run only the Telegram bot
|
|
|
-source venv/bin/activate
|
|
|
-python telegram_bot.py
|
|
|
-```
|
|
|
-- ✅ Control via Telegram from anywhere
|
|
|
-- ✅ Manual decision making
|
|
|
-- ✅ Safe for beginners
|
|
|
-
|
|
|
-### **Use Case 2: Automated Trading**
|
|
|
-**Goal**: Fully automated trading with monitoring
|
|
|
-```bash
|
|
|
-# Terminal 1: Run strategy bot
|
|
|
-source venv/bin/activate
|
|
|
-python strategy_bot.py
|
|
|
-
|
|
|
-# Terminal 2: Run Telegram bot for monitoring
|
|
|
-source venv/bin/activate
|
|
|
-python telegram_bot.py
|
|
|
-```
|
|
|
-- ✅ Automated trading strategies
|
|
|
-- ✅ Remote monitoring via Telegram
|
|
|
-- ✅ Professional setup
|
|
|
-
|
|
|
-### **Use Case 3: Development and Testing**
|
|
|
-**Goal**: Test strategies and debug
|
|
|
-```bash
|
|
|
-# Use terminal bot for quick testing
|
|
|
-source venv/bin/activate
|
|
|
-python simple_bot.py
|
|
|
-```
|
|
|
-- ✅ Interactive testing
|
|
|
-- ✅ Quick market data checks
|
|
|
-- ✅ Debug configuration
|
|
|
-
|
|
|
-## 🔄 **Long-Running vs. Cron Jobs**
|
|
|
-
|
|
|
-### ❌ **DON'T Use Cron Jobs For:**
|
|
|
-- Telegram bot (needs to stay connected)
|
|
|
-- Strategy bot (needs continuous monitoring)
|
|
|
-- Any interactive functionality
|
|
|
-
|
|
|
-### ✅ **DO Use Long-Running Processes:**
|
|
|
-```bash
|
|
|
-# These run forever until you stop them
|
|
|
-python telegram_bot.py # Listens for Telegram commands 24/7
|
|
|
-python strategy_bot.py # Executes strategies every 60 seconds
|
|
|
-```
|
|
|
-
|
|
|
-### ✅ **Optional: Use Cron for Maintenance:**
|
|
|
-```bash
|
|
|
-# Example: Daily log rotation (optional)
|
|
|
-0 0 * * * /path/to/your/log_rotation_script.sh
|
|
|
-```
|
|
|
-
|
|
|
-## 🖥️ **Production Deployment Options**
|
|
|
-
|
|
|
-### **Option 1: Screen/Tmux Sessions**
|
|
|
-```bash
|
|
|
-# Start a screen session
|
|
|
-screen -S trading_bot
|
|
|
-
|
|
|
-# Run your bot
|
|
|
-source venv/bin/activate
|
|
|
-python telegram_bot.py
|
|
|
-
|
|
|
-# Detach: Ctrl+A, then D
|
|
|
-# Reattach: screen -r trading_bot
|
|
|
-```
|
|
|
-
|
|
|
-### **Option 2: Systemd Service (Linux)**
|
|
|
-Create `/etc/systemd/system/trading-bot.service`:
|
|
|
-```ini
|
|
|
-[Unit]
|
|
|
-Description=Hyperliquid Trading Bot
|
|
|
-After=network.target
|
|
|
-
|
|
|
-[Service]
|
|
|
-Type=simple
|
|
|
-User=your_username
|
|
|
-WorkingDirectory=/path/to/trader_hyperliquid
|
|
|
-Environment=PATH=/path/to/trader_hyperliquid/venv/bin
|
|
|
-ExecStart=/path/to/trader_hyperliquid/venv/bin/python telegram_bot.py
|
|
|
-Restart=always
|
|
|
-RestartSec=10
|
|
|
-
|
|
|
-[Install]
|
|
|
-WantedBy=multi-user.target
|
|
|
-```
|
|
|
-
|
|
|
-```bash
|
|
|
-sudo systemctl enable trading-bot
|
|
|
-sudo systemctl start trading-bot
|
|
|
-sudo systemctl status trading-bot
|
|
|
-```
|
|
|
-
|
|
|
-### **Option 3: Docker (Advanced)**
|
|
|
-```dockerfile
|
|
|
-FROM python:3.11-slim
|
|
|
-
|
|
|
-WORKDIR /app
|
|
|
-COPY requirements.txt .
|
|
|
-RUN pip install -r requirements.txt
|
|
|
-
|
|
|
-COPY . .
|
|
|
-CMD ["python", "telegram_bot.py"]
|
|
|
-```
|
|
|
-
|
|
|
-### **Option 4: Process Manager (PM2)**
|
|
|
-```bash
|
|
|
-npm install -g pm2
|
|
|
-pm2 start telegram_bot.py --interpreter python3
|
|
|
-pm2 startup
|
|
|
-pm2 save
|
|
|
-```
|
|
|
-
|
|
|
-## 📊 **Recommended Deployment Strategy**
|
|
|
-
|
|
|
-### **For Beginners:**
|
|
|
-1. **Start with manual control:**
|
|
|
- ```bash
|
|
|
- python telegram_bot.py
|
|
|
- ```
|
|
|
-2. **Test strategies separately:**
|
|
|
- ```bash
|
|
|
- python strategy_bot.py # Watch logs, don't let it trade yet
|
|
|
- ```
|
|
|
-
|
|
|
-### **For Production:**
|
|
|
-1. **Run both bots in separate processes:**
|
|
|
- ```bash
|
|
|
- # Terminal 1 (or systemd service)
|
|
|
- python telegram_bot.py
|
|
|
-
|
|
|
- # Terminal 2 (or systemd service)
|
|
|
- python strategy_bot.py
|
|
|
- ```
|
|
|
-
|
|
|
-2. **Use process monitoring:**
|
|
|
- ```bash
|
|
|
- # Check if bots are running
|
|
|
- ps aux | grep python
|
|
|
-
|
|
|
- # Check logs
|
|
|
- tail -f ~/.local/share/hyperliquid-bot/logs/
|
|
|
- ```
|
|
|
-
|
|
|
-## 🔧 **Bot Intervals and Timing**
|
|
|
-
|
|
|
-### **Strategy Bot Timing:**
|
|
|
-```python
|
|
|
-# In strategy_bot.py
|
|
|
-self.loop_interval = 60 # Run every 60 seconds
|
|
|
-```
|
|
|
-
|
|
|
-**Why 60 seconds?**
|
|
|
-- ✅ Balances responsiveness with API limits
|
|
|
-- ✅ Prevents overtrading
|
|
|
-- ✅ Allows time for proper analysis
|
|
|
-
|
|
|
-**Adjust based on strategy:**
|
|
|
-```python
|
|
|
-# Scalping: More frequent (careful of API limits)
|
|
|
-self.loop_interval = 30 # 30 seconds
|
|
|
-
|
|
|
-# Swing trading: Less frequent
|
|
|
-self.loop_interval = 300 # 5 minutes
|
|
|
-
|
|
|
-# Long-term: Much less frequent
|
|
|
-self.loop_interval = 3600 # 1 hour
|
|
|
-```
|
|
|
-
|
|
|
-### **Telegram Bot:**
|
|
|
-- Runs continuously
|
|
|
-- Responds instantly to commands
|
|
|
-- No interval needed
|
|
|
-
|
|
|
-## 🛡️ **Safety and Monitoring**
|
|
|
-
|
|
|
-### **1. Always Start with Testnet**
|
|
|
-```env
|
|
|
-HYPERLIQUID_TESTNET=true
|
|
|
-```
|
|
|
-
|
|
|
-### **2. Monitor Your Bots**
|
|
|
-```bash
|
|
|
-# Check bot status via Telegram
|
|
|
-/status
|
|
|
-
|
|
|
-# Check logs
|
|
|
-tail -f logs/trading_bot.log
|
|
|
-
|
|
|
-# Check system resources
|
|
|
-htop
|
|
|
-```
|
|
|
-
|
|
|
-### **3. Set Up Alerts**
|
|
|
-```python
|
|
|
-# Add to your strategy bot
|
|
|
-if large_loss_detected:
|
|
|
- await send_telegram_alert("⚠️ Large loss detected!")
|
|
|
-```
|
|
|
-
|
|
|
-### **4. Implement Circuit Breakers**
|
|
|
-```python
|
|
|
-# In your strategy
|
|
|
-if daily_loss > max_daily_loss:
|
|
|
- logger.error("Daily loss limit reached. Stopping trading.")
|
|
|
- self.trading_enabled = False
|
|
|
-```
|
|
|
-
|
|
|
-## 🔄 **Updating and Maintenance**
|
|
|
-
|
|
|
-### **Safe Update Process:**
|
|
|
-1. **Stop bots gracefully:**
|
|
|
- ```bash
|
|
|
- # Ctrl+C or
|
|
|
- sudo systemctl stop trading-bot
|
|
|
- ```
|
|
|
-
|
|
|
-2. **Backup configuration:**
|
|
|
- ```bash
|
|
|
- cp .env .env.backup
|
|
|
- ```
|
|
|
-
|
|
|
-3. **Update code:**
|
|
|
- ```bash
|
|
|
- git pull # or download new version
|
|
|
- ```
|
|
|
-
|
|
|
-4. **Test in terminal:**
|
|
|
- ```bash
|
|
|
- python simple_bot.py
|
|
|
- ```
|
|
|
-
|
|
|
-5. **Restart production bots:**
|
|
|
- ```bash
|
|
|
- python telegram_bot.py
|
|
|
- ```
|
|
|
-
|
|
|
-## 🔍 **Troubleshooting**
|
|
|
-
|
|
|
-### **Bot Won't Start:**
|
|
|
-```bash
|
|
|
-# Check configuration
|
|
|
-python -c "from config import Config; Config.validate()"
|
|
|
-
|
|
|
-# Check dependencies
|
|
|
-pip list | grep hyperliquid
|
|
|
-```
|
|
|
-
|
|
|
-### **Telegram Bot Not Responding:**
|
|
|
-```bash
|
|
|
-# Test token
|
|
|
-curl https://api.telegram.org/bot<YOUR_TOKEN>/getMe
|
|
|
-
|
|
|
-# Check chat ID
|
|
|
-python get_telegram_chat_id.py
|
|
|
-```
|
|
|
-
|
|
|
-### **Strategy Bot Not Trading:**
|
|
|
-```bash
|
|
|
-# Check if trading is enabled in code
|
|
|
-grep -n "Uncomment to enable" strategy_bot.py
|
|
|
-
|
|
|
-# Check balance and positions
|
|
|
-python simple_bot.py
|
|
|
-```
|
|
|
-
|
|
|
-## 📈 **Best Practices**
|
|
|
-
|
|
|
-### **1. Resource Management**
|
|
|
-- Monitor CPU and memory usage
|
|
|
-- Implement proper logging rotation
|
|
|
-- Use rate limiting for API calls
|
|
|
-
|
|
|
-### **2. Security**
|
|
|
-- Keep private keys secure
|
|
|
-- Use environment variables
|
|
|
-- Regularly rotate API keys
|
|
|
-
|
|
|
-### **3. Monitoring**
|
|
|
-- Set up health checks
|
|
|
-- Monitor trading performance
|
|
|
-- Track system metrics
|
|
|
-
|
|
|
-### **4. Testing**
|
|
|
-- Always test on testnet first
|
|
|
-- Use small amounts initially
|
|
|
-- Monitor for several days before scaling
|
|
|
-
|
|
|
-## 🎯 **Quick Commands Reference**
|
|
|
-
|
|
|
-```bash
|
|
|
-# Start manual control bot
|
|
|
-python telegram_bot.py
|
|
|
-
|
|
|
-# Start automated trading bot
|
|
|
-python strategy_bot.py
|
|
|
-
|
|
|
-# Start both (recommended for production)
|
|
|
-python telegram_bot.py &
|
|
|
-python strategy_bot.py
|
|
|
-
|
|
|
-# Test configuration
|
|
|
-python simple_bot.py
|
|
|
-
|
|
|
-# Get Telegram Chat ID
|
|
|
-python get_telegram_chat_id.py
|
|
|
-
|
|
|
-# Check if running
|
|
|
-ps aux | grep "python.*bot"
|
|
|
-
|
|
|
-# Stop all bots
|
|
|
-pkill -f "python.*bot"
|
|
|
-```
|
|
|
-
|
|
|
----
|
|
|
-
|
|
|
-**Remember**: Start simple, test thoroughly, and scale gradually! 🚀
|