How to deploy a trading bot that survives 24/7

A trading bot that works on your laptop is not a deployed bot. Markets run around the clock; your laptop sleeps, your Wi-Fi drops, and a crash at 3am can leave a position open with no stop. Deploying means putting the bot somewhere reliable, keeping it alive through crashes, protecting its secrets, and making sure that if it does die, it dies safely. This guide covers the VPS, Docker, process supervision and the dead-man's switch.

On this page
  1. Pick a VPS
  2. Containerize
  3. Keep it alive
  4. Secrets & logging
  5. The dead-man's switch
  6. Checklist

Step 1 — pick a VPS near your exchange

Run the bot on a small cloud VPS, not your laptop. Latency matters less for a daily-bar bot than for a scalper, but proximity to your exchange's servers still trims slippage. A 1–2 vCPU instance is plenty for most strategies.

Location tip

Many crypto exchanges host in AWS Tokyo or similar regions. Put the bot in the same region to cut round-trip time. For a slow strategy any reliable VPS is fine — uptime beats microseconds.

Step 2 — containerize with Docker

Docker makes the bot reproducible: the same image runs identically on your machine and the VPS, with pinned dependencies.

dockerfile · DockerfileFROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "bot.py"]

Step 3 — keep it alive through crashes

A bot will crash eventually — a network blip, an API hiccup, an unhandled edge case. The goal is automatic, safe restart. With Docker, a restart policy does it; on bare metal, use systemd.

supervisor bot process restart on crash exit / crash signal
A supervisor restarts the bot automatically — but a restart loop is only safe if the bot reconciles its real position on startup.
ini · trading-bot.service# /etc/systemd/system/trading-bot.service
[Service]
ExecStart=/usr/bin/docker start -a trading-bot
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Reconcile on startup

After a restart the bot must re-read its real position from the exchange, not assume it's flat. A bot that forgets an open position on restart can double up or leave a trade unmanaged. Always fetch open orders and positions on boot.

Step 4 — secrets and logging

Never bake API keys into the image. Inject them as environment variables at runtime and log every decision and order so you can audit what the bot did when something looks wrong.

bash · run.shdocker run -d --name trading-bot --restart=always \
  -e EXCHANGE_KEY="$EXCHANGE_KEY" \
  -e EXCHANGE_SECRET="$EXCHANGE_SECRET" \
  -v /var/log/bot:/app/logs trading-bot

Step 5 — the dead-man's switch

The most important deployment feature is graceful failure. If the bot loses connectivity, hits a max drawdown, or stops sending heartbeats, it should flatten positions and halt rather than trade blind. Wire a heartbeat to a monitor (or a Telegram alert) that pages you when the bot goes silent.

Deployment checklist

  1. Strategy proven on the backtester and in paper trading first.
  2. Dockerized with pinned dependencies.
  3. Auto-restart that reconciles position on boot.
  4. Secrets via env vars; see key security.
  5. Full order logging + heartbeat alert.
  6. Dead-man's switch: flatten and halt on failure or max drawdown.
Not financial advice. This content is educational. Automated and algorithmic trading carries a real risk of financial loss. Never trade money you cannot afford to lose. Review the SEC investor.gov and CFTC resources before trading.

Frequently asked questions

Where should I host a trading bot?

Run it on a small cloud VPS rather than your laptop so it stays online 24/7. A 1–2 vCPU instance handles most strategies. Placing it in the same cloud region as your exchange's servers trims latency, though for slow daily-bar bots uptime matters far more than microseconds.

Do I need Docker to deploy a trading bot?

No, but it helps. Docker pins dependencies and makes the bot run identically on your machine and the server, and its restart policy keeps the bot alive through crashes. The alternative on bare metal is a systemd service with Restart=always.

How do I keep a trading bot running 24/7?

Use a process supervisor — Docker's restart policy or systemd — to relaunch the bot automatically after a crash. Critically, the bot must reconcile its real position from the exchange on startup so a restart doesn't double a trade or abandon an open one.

What is a dead-man's switch for a trading bot?

It's a safety mechanism that flattens positions and halts trading if the bot loses connectivity, stops sending heartbeats, or breaches a max-drawdown limit. It ensures that when the bot fails, it fails safely instead of trading blind or leaving positions unmanaged.

MB

Mustafa Bilgic

Algorithmic trading practitioner · Founder, AITradingBot.us

Mustafa builds and backtests automated trading systems and writes about them without the hype. Every tool on this site is free and runs entirely in your browser.