DEV Community

Vinicius Chelles
Vinicius Chelles

Posted on

Running a Crypto Trading Bot on a VPS: Complete Guide

Running a Crypto Trading Bot on a $5 VPS: Complete Guide

I learned this the hard way — after burning $200/month on cloud infrastructure for a trading bot that could've run on a budget VPS. Here's the complete setup.

The Problem

Most trading bot tutorials assume you have a powerful server or run everything locally. That's not realistic for indie developers who want to:

  • Run the bot 24/7 without keeping their laptop awake
  • Access it from anywhere
  • Do it cheap (under $5/month)

The Solution

A $5/month VPS can handle a crypto trading bot without breaking a sweat. Here's how to set it up.

What You Need

  • A budget VPS (Hetzner, DigitalOcean, or Linode — $5/mo tier)
  • Ubuntu 22.04 LTS
  • Node.js 18+
  • PM2 for process management

Step 1: Provision Your VPS

# SSH into your new server
ssh root@your-vps-ip

# Update the system
apt update && apt upgrade -y

# Install Node.js 18
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt install -y nodejs

# Install PM2 for process management
npm install -g pm2
Enter fullscreen mode Exit fullscreen mode

Step 2: Set Up Your Trading Bot

Clone your bot repository or create a minimal one:

# Create project directory
mkdir -p ~/trading-bot
cd ~/trading-bot

# Initialize npm
npm init -y

# Install dependencies
npm install ccxt dotenv

# Create your bot file
cat > bot.js << 'EOF'
const ccxt = require('ccxt');
require('dotenv').config();

async function trade() {
  const exchange = new ccxt.binance({
    apiKey: process.env.API_KEY,
    secret: process.env.API_SECRET,
    enableRateLimit: true,
  });

  // Your trading logic here
  console.log('Bot running...');

  setInterval(async () => {
    try {
      // Fetch prices, check signals, execute trades
      const ticker = await exchange.fetchTicker('BTC/USDT');
      console.log(`BTC/USDT: ${ticker.last}`);
    } catch (error) {
      console.error('Error:', error.message);
    }
  }, 60000);
}

trade();
EOF

# Create .env file
echo "API_KEY=your_api_key" > .env
echo "API_SECRET=your_secret" >> .env
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure PM2

# Start the bot with PM2
pm2 start bot.js --name trading-bot

# Make it start on boot
pm2 startup
pm2 save
Enter fullscreen mode Exit fullscreen mode

Step 4: Set Up Nginx (Optional, for Dashboard)

If you want a web dashboard:

# Install Nginx
apt install -y nginx

# Configure reverse proxy
cat > /etc/nginx/sites-available/trading-dashboard << 'EOF'
server {
    listen 80;
    server_name your-vps-ip;

    location / {
        proxy_pass http://localhost:3000;
    }
}
EOF

ln -s /etc/nginx/sites-available/trading-dashboard /etc/nginx/sites-enabled/
nginx restart
Enter fullscreen mode Exit fullscreen mode

Step 5: Secure Your VPS

# Set up UFW firewall
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

# Set up fail2ban
apt install -y fail2ban
Enter fullscreen mode Exit fullscreen mode

Performance Numbers

Here's what to expect from a $5 VPS (1 vCPU, 2GB RAM):

  • Trade check frequency: Every 10-60 seconds (plenty for most strategies)
  • Concurrent indicators: 10-20 (RSI, MACD, Moving Averages)
  • API calls: 5-10/minute (within Binance rate limits)
  • Uptime: 99.9%+ with PM2 auto-restart
  • Cost: $5/month vs $50-200/month on cloud

Monitoring and Logs

# View logs
pm2 logs trading-bot

# Check status
pm2 status

# Monitor in real-time
pm2 monit
Enter fullscreen mode Exit fullscreen mode

Auto-Update Strategy

Keep your bot running the latest version:

# Pull updates
cd ~/trading-bot
git pull

# Restart with the new version
pm2 restart trading-bot
Enter fullscreen mode Exit fullscreen mode

Why Not Docker?

Docker adds overhead (extra ~200MB RAM, more complexity). For a simple trading bot on a 2GB VPS, running Node.js directly with PM2 gives you:

  • More available memory for indicators
  • Simpler debugging
  • Easier configuration

Conclusion

A $5 VPS is perfectly capable of running a crypto trading bot 24/7. With PM2 managing your processes and proper security (UFW + fail2ban), you have a reliable setup that costs less than a coffee per month.

The key lessons:

  1. PM2 handles restarts automatically
  2. Start simple, then scale up
  3. Monitor with pm2 monit
  4. Always secure your VPS

I'm building Lucromatic, a self-hosted trading bot for Binance. Check the live demo.

Top comments (0)