Running MetaTrader 5 from Python on Linux (No Terminal, No Wine)
The official MetaTrader5 Python package is Windows-only and needs a running terminal. Here's how to run MT5 from Python on Linux, macOS, or a headless server by putting the terminal behind an API.
If you write trading bots in Python and your broker is on MetaTrader 5, you have
probably hit this wall: the official MetaTrader5 Python package only runs on
Windows, and it needs a running MT5 terminal on the same machine. Your
strategy code and the terminal have to live together, on Windows, forever.
That's fine on a laptop. It's painful the moment you want to run on a Linux server, develop on a Mac, go headless, or manage several accounts without babysitting a terminal each.
The root of the problem is where the terminal has to run — and the fix is to move it somewhere else entirely:
Why it's hard in the first place
The MetaTrader5 package is a thin wrapper around the desktop terminal's IPC. It
talks to a terminal running on the same host, and inherits the terminal's
constraints:
- Windows only. There is no native Linux or macOS build.
- A terminal must be running. The package can't connect to a broker on its own; it drives an already-logged-in terminal.
- One terminal, one login (in practice). Running several accounts means several terminals, which means several desktop sessions to keep alive.
None of that is a bug. MT5 was built as a desktop platform. It just makes "headless bot on a Linux box" awkward.
The usual workarounds (and their costs)
- Wine. Run the Windows terminal under Wine on Linux. It can work, but it's fiddly to set up, fragile across updates, and usually needs a virtual display.
- A Windows VM or VPS. Reliable, but heavier: you now pay for and maintain a Windows box just to host a terminal, plus a bridge to your Linux code.
- Docker + Wine images. Nicer packaging of the Wine approach, same underlying fragility.
All three keep the terminal in your infrastructure. You own its uptime, its display, its updates, and one process per account. That's the cost you're actually trying to avoid.
A different approach: put the terminal behind an API
Instead of running a terminal next to your code, run it somewhere else and talk to it over the network. The broker session lives on hosted infrastructure; your strategy is a plain HTTP + WebSocket client that runs anywhere Python runs:
Concretely, a hosted MT5 API exposes REST for account info, symbols, historical candles, and trades, plus a WebSocket for live ticks, positions, and account updates. Your code never touches a terminal. There's no Wine, no display, no per-account desktop session.
A worked example
TickerAll is one such hosted MT5 API. Here's a minimal Python client that connects an account and streams live quotes from Linux.
Install the SDK:
pip install tickerall
Connect and stream ticks:
from tickerall import Tickerall
client = Tickerall(api_key="cf_...")
# Warm the broker session with the same details you use to log into MT5.
session = client.sessions.start(
broker="mt5",
server="Your-Broker-Server",
account=12345678,
password="...",
)
stream = client.stream.connect()
stream.on("tick", lambda e: print(e.symbol, e.bid, e.ask))
stream.subscribe_ticks(session.account_id, ["EURUSD"])
Run it on any OS:
python stream.py
You get live quotes printing to your terminal, from a Linux box, with no MT5 terminal running anywhere in your infrastructure. Fetching historical candles for a backtest, listing symbols, and placing trades are the same shape — plain method calls over the API.
When to use which
Be honest with yourself about the trade-off. Neither option is "correct" — they optimize for different things:
Local MetaTrader5 package |
Hosted MT5 API | |
|---|---|---|
| OS | Windows only | Linux, macOS, Windows |
| Terminal | You run and maintain it | Runs on the API's side |
| Headless / cloud / CI | Painful (Wine/VM) | Native |
| Multiple accounts | One terminal each | One client, many accounts |
| Cost | Free | Network dependency + subscription |
| Best for | A single account on a Windows box | Servers, Macs, scale |
Rule of thumb: if you're on Windows with one account and don't mind running a terminal, the local package is free and fine. If you're on Linux or a Mac, want headless deployment, or run several accounts, move the terminal behind an API.
Wrapping up
MT5's Windows-and-terminal requirement is what makes Python bots awkward to deploy off Windows. You can fight it with Wine or a Windows VM — or you can move the terminal off your machine and treat MT5 as a plain HTTP/WebSocket API. The second path is what lets a Python strategy stream live MT5 data from a Linux box in a dozen lines.
If you want to try the setup above, the TickerAll docs have the full REST + WebSocket reference and SDKs for Python and TypeScript.