← Back to Blog
TUTORIALS

Deploying Your Trading Bot on a Linux VPS: Complete Setup Guide

June 12, 2026 · 10 min read · LMEX.AI

Running a trading bot from your laptop is fine for testing. Running it for real means putting it on a server that doesn't shut down when you close the lid, doesn't lose connection when your WiFi blips, and doesn't stop at 3am because macOS decided to install updates.


This article walks through choosing a VPS, setting up basic security, running your bot as a systemd service, and the operational practices that make the difference between a bot that runs reliably and one that mysteriously stops every few weeks.


Choosing a VPS


For most retail trading bots, you want:

  • Cheap (the bot uses minimal resources)
  • Reliable (uptime matters more than raw performance)
  • Close to the exchange (latency matters for some strategies)

  • Three providers cover 95% of use cases:


    **Hetzner** — best value. \$4-6/month for a CX11 instance (2 GB RAM, 1 vCPU). German company, datacenters in Germany and Finland. Latency to LMEX endpoints in Hong Kong is 200-300ms. Fine for non-HFT strategies. Excellent reputation for reliability and customer service.


    **DigitalOcean** — most retail-friendly. \$6/month basic droplet. Datacenters globally including Singapore (lowest latency to LMEX). Clean dashboard, good docs, decent for beginners. Slightly more expensive than Hetzner.


    **AWS Lightsail** — most flexible. \$5-10/month. Integrates with broader AWS if you ever need it. Singapore region for low LMEX latency. More complex than DO but worth knowing if you might scale.


    For latency-sensitive strategies (market making, arbitrage), pick a provider with a Singapore or Hong Kong region. For trend following or DCA, any region works fine.


    Skip VPS providers you've never heard of. Cheap is not worth uptime issues that lose money.


    Initial setup and security


    Once you have an Ubuntu 24.04 server (the default for all three providers):


    # Connect (replace with your IP and key)
    ssh root@your-server-ip
    
    # Update everything
    apt update && apt upgrade -y
    
    # Create a non-root user
    adduser tradingbot
    usermod -aG sudo tradingbot
    
    # Copy SSH key for the new user
    rsync --archive --chown=tradingbot:tradingbot ~/.ssh /home/tradingbot
    
    # Disable root login and password auth
    sed -i 's/^PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
    sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
    systemctl restart ssh
    
    # Set up basic firewall
    ufw allow ssh
    ufw --force enable

    That's the bare minimum security setup. Disable root SSH, use keys only, enable firewall.


    For a trading bot, you typically don't need any incoming ports beyond SSH. The bot makes outgoing connections to the exchange; nothing connects to it.


    Installing dependencies


    Reconnect as the new user:


    ssh tradingbot@your-server-ip
    
    # Install Python and pip
    sudo apt install -y python3 python3-pip python3-venv git
    
    # Set up a project directory
    mkdir -p ~/bots/lmex-bot
    cd ~/bots/lmex-bot
    
    # Create virtual environment
    python3 -m venv venv
    source venv/bin/activate
    pip install ccxt python-dotenv

    Clone or copy your bot code into this directory. Create a `.env` file for credentials:


    LMEX_API_KEY=your_key
    LMEX_API_SECRET=your_secret

    Lock it down: `chmod 600 .env`


    Running as a systemd service


    The right way to run a long-running bot on Linux is as a systemd service. This handles:

  • Automatic startup on boot
  • Restart on crashes
  • Logging
  • Resource limits

  • Create `/etc/systemd/system/lmex-bot.service`:


    [Unit]
    Description=LMEX Trading Bot
    After=network.target
    
    [Service]
    Type=simple
    User=tradingbot
    WorkingDirectory=/home/tradingbot/bots/lmex-bot
    ExecStart=/home/tradingbot/bots/lmex-bot/venv/bin/python3 main.py
    Restart=on-failure
    RestartSec=10
    StandardOutput=append:/home/tradingbot/bots/lmex-bot/bot.log
    StandardError=append:/home/tradingbot/bots/lmex-bot/bot.log
    
    # Resource limits
    MemoryLimit=512M
    CPUQuota=50%
    
    [Install]
    WantedBy=multi-user.target

    Enable and start it:


    sudo systemctl daemon-reload
    sudo systemctl enable lmex-bot
    sudo systemctl start lmex-bot
    
    # Check status
    sudo systemctl status lmex-bot
    
    # Follow logs
    sudo journalctl -u lmex-bot -f

    The bot now runs in the background, restarts automatically if it crashes, and starts on reboot.


    Log rotation


    Without log rotation, your bot's log file grows indefinitely and eventually fills the disk. Create `/etc/logrotate.d/lmex-bot`:


    /home/tradingbot/bots/lmex-bot/bot.log {
        daily
        rotate 14
        compress
        delaycompress
        missingok
        notifempty
        create 0644 tradingbot tradingbot
    }

    This rotates logs daily, keeps 14 days of compressed history, doesn't error if the log is missing.


    Monitoring and alerts


    A bot that runs silently isn't useful. You need to know when it stops or starts behaving weirdly.


    Simplest approach: a heartbeat script that runs every 5 minutes via cron and sends an alert if the bot isn't running:


    #!/usr/bin/env python3
    import subprocess
    import requests
    import os
    
    TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN')
    TELEGRAM_CHAT_ID = os.getenv('TELEGRAM_CHAT_ID')
    
    def send_alert(message):
        url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"
        requests.post(url, json={'chat_id': TELEGRAM_CHAT_ID, 'text': message})
    
    result = subprocess.run(
        ['systemctl', 'is-active', 'lmex-bot'],
        capture_output=True, text=True
    )
    
    if result.stdout.strip() != 'active':
        send_alert(f"LMEX bot is not running. State: {result.stdout.strip()}")

    Cron entry: `*/5 * * * * /home/tradingbot/scripts/check-bot.py`


    For more sophisticated monitoring, look at Healthchecks.io (free for one bot) or build a Telegram dashboard that reports P&L, positions, and recent trades every few hours.


    Operational discipline


    A few practices that distinguish bots that survive from those that don't:


    **SSH key rotation.** Rotate your SSH key annually. If you ever shared the server (paired programming, contractor access), rotate immediately.


    **Regular updates.** Set up unattended upgrades for security patches: `sudo apt install unattended-upgrades`. Manually update major versions during quiet trading periods (weekends, holidays).


    **Backups.** Back up your bot's state (open orders, recent trades, config) to a separate location at least weekly. Don't rely on the VPS being recoverable.


    **Test changes locally first.** Changing code on the live server is asking for trouble. Develop locally, test in a paper environment, then deploy.


    **Monitor what matters.** Bot uptime is one metric. Also track: deviation from expected position size, drawdown vs limit, fill rate vs expected. Anomalies in these often indicate the bot is technically running but actually misbehaving.


    Costs


    For a 1-bot retail setup:

  • VPS: \$5-7/month
  • Domain (optional, if you want a dashboard): \$10/year
  • Alerts (Telegram is free): \$0
  • Monitoring (basic): \$0

  • Total: ~\$70-100/year. Less than a single bad trade.


    Frequently Asked Questions


    Q: Can I run this from a Raspberry Pi at home instead?

    Technically yes, but ISP outages, power outages, and home internet flakiness mean meaningfully less uptime. For a serious bot, a VPS is worth the \$5/month.


    Q: What if I want to deploy multiple bots?

    Same server is fine if they're small. Run each as its own systemd service. For 5+ bots or anything resource-intensive, scale up to a larger instance or run multiple smaller ones.


    Q: Do I need a static IP?

    VPS providers give you a static IP by default. If your exchange API key is IP-restricted (recommended), use this IP.


    Q: What about Docker?

    Docker is overkill for a single bot. The systemd setup above is simpler and more reliable. Docker becomes worthwhile when running multiple bots with different dependencies or when you need consistent deployment across environments.


    Related Articles


    → Building a Crypto Perpetuals Trading Bot in Python: Complete Guide
    → Why Most Trading Bots Fail (And What the Survivors Get Right)
    → WebSocket vs REST for Trading Bots: When Each One Wins
    ← All ArticlesBuild a Bot →