A VPS for a trading bot: CPU, reliability and API key protection
A trading bot that works through a broker's API doesn't need a graphical interface or powerful hardware. It needs something else: to process an incoming quote quickly, keep its connection, maintain a clear log and not hand its access keys to outsiders. This selection is built for those tasks: Linux servers with 2 or more cores at a high CPU clock speed and 2 GB of memory or more. It covers robots for the stock and derivatives markets and for currency brokers with an official API.
Why clock speed matters, not core count
A typical bot in Python or Node.js handles events in a single thread: it receives data over WebSocket or gRPC, recalculates indicators, makes a decision and sends an order. While the calculation runs, the next event waits in the queue. So reaction time is set by the speed of one core, and a CPU at 3.5–4 GHz speeds up a bot more than eight slow cores. How to tell an honest clock speed from a marketing one is covered on the VPS with high CPU clock speeds page.
A second core is still needed: it runs the system, the database, the log collector and a second bot if you have one. Memory is mostly used by historical data: if the bot holds several years of minute candles for dozens of instruments in pandas, 2 GB runs out quickly. Backtesting strategies on history is best done separately, on a temporary powerful server with hourly billing, so it doesn't take resources away from the live process.
Where to place the server
Latency is measured to the broker's API server, not to the exchange. Russian brokers keep their gateways in Moscow, and for them a VPS in Moscow is the right fit. If your broker is elsewhere, find out from its API documentation which region its servers are in. For strategies on hourly and daily candles a difference of 20–30 ms means nothing; for reacting to the order book it is noticeable.
If the broker only gives access through a desktop terminal rather than an API, the bot has to run on Windows next to the terminal. For QUIK there is a separate VPS for QUIK selection, and for MetaTrader there is Forex VPS.
Keeping the bot running
- Automatic restart. Run the bot as a systemd service with
Restart=alwaysor in Docker with a restart policy. After a crash or a server reboot it will come back up on its own. - Reconnection. Streaming API connections drop regularly: during broker maintenance, session changes and network failures. The bot should resubscribe to data and reconcile open positions and orders with the broker after every reconnection.
- Accurate time. Enable time synchronisation via chrony or systemd-timesyncd. A clock drift of a few seconds breaks candle calculation and scheduling, and some APIs reject requests with a wrong timestamp.
- External monitoring. Have the bot send an "I'm alive" signal once a minute to an external monitoring system or a messenger. Silence from the bot is also an event you need to know about immediately.
- Limiters. Build limits on orders per minute and on position size into the code. A bug in a loop without such a limit can send hundreds of orders in seconds and run into the broker's API limits.
Logs: what to record
When something goes wrong, the log is the only way to understand why. Record every decision the bot makes with its input data, every order sent with the broker's response, and every reconnection. Writing logs as JSON, one line per event, is convenient: they are easy to filter and load into analysis. Set up rotation with logrotate or a systemd journal size limit, otherwise the logs will fill the whole disk within a few months. Keep the trade history separately, in a database, and back it up.
Key security
An API token gives access to your brokerage account, so treat it like your online banking password:
- Issue the token with minimal permissions. Read-only access is enough for analytics; a bot needs trading rights on a single account.
- If the broker supports binding a token to an IP address, enter your VPS's address.
- Keep the token in an environment file with 600 permissions or in a secrets manager, not in the code and not in a Git repository.
- Log in to the server with an SSH key, disable password login and run the bot as a separate user without root rights.
The server is responsible only for the technical side. Neither a fast CPU nor a low ping makes a strategy profitable, and algorithmic trading carries the same market risks as manual trading. Connect only to brokers with a valid licence.