MetaTrader 5 Python Package vs REST API: Which Should You Use?
The official MetaTrader5 package needs Windows and a running terminal; a hosted REST API needs neither. Setup, hosting, languages and upkeep compared.
In short
- The official MetaTrader5 package is a bridge to a terminal on the same Windows machine. It is not a network client for your broker.
- That makes it a good fit for research and personal trading on a Windows PC, and an awkward one for servers, Linux, macOS and many accounts.
- A hosted REST API runs the terminals for you: any language, any operating system, many accounts, and a recorded result for every order.
- The package also gives you prices, bars and ticks. fxapis does not stream market data, so a strategy built on MT5 data needs another source for it.
On this page
Both get an order from Python to MetaTrader 5. They differ in where MetaTrader runs, and therefore in where your code can run. Use the official package for research and personal trading on a Windows PC. Use a hosted REST API for anything that runs on a server, outside Windows, or across many accounts.
What the official package is
MetaTrader5 on PyPI is MetaQuotes' own package. Its documentation describes it as getting data "via interprocessor communication directly from the MetaTrader 5 terminal" — it is a bridge to a terminal process on the same computer. initialize() connects to that terminal (and launches it if needed), and every call after it goes through the terminal.
Two consequences follow: you need a running terminal next to your script, and you need Windows — the files published for the package are Windows builds.
What a hosted REST API is
A hosted API runs the MetaTrader 5 terminals on its own servers and accepts HTTPS requests. Your script does not talk to a terminal; it talks to the API, from any machine:
import os, uuid, requests
API = "https://api.fxapis.com"
s = requests.Session()
s.headers["Authorization"] = f"Bearer {os.environ['FXAPIS_KEY']}"
order = s.post(
f"{API}/v1/accounts/{os.environ['ACCOUNT_ID']}/orders/market",
headers={"Idempotency-Key": str(uuid.uuid4())},
json={"symbol": "EURUSD", "side": "buy", "volume": "0.01"},
timeout=90,
).json()["data"]
print(order["state"], order["filledPrice"])
The account was connected once beforehand with its login, password and server. There is no initialize(), no terminal path, and no Windows.
Side by side
| Aspect | MetaTrader5 package | Hosted REST API (fxapis) |
|---|---|---|
| Operating system | Windows (or Wine) | Any |
| Needs a terminal running | Yes, on the same machine | No — run by the provider |
| Languages | Python | Any language with HTTPS |
| Accounts at once | One per terminal | Many per workspace, one request for many |
| Where your code runs | Next to the terminal | Anywhere: server, container, function |
| Market data (ticks, bars) | Yes | No |
| Retry safety | Yours to build | Idempotency keys; unclear results confirmed with the broker |
| Upkeep | Terminal, machine, logins | Your code |
| Cost | Free, plus the machine | A monthly plan |
When the package is the better choice
- You are researching a strategy and need MT5's historical bars and ticks.
- You trade your own account from a Windows machine you already keep running.
- You want no third party between you and your broker.
When a REST API is the better choice
- Your backend runs on Linux, macOS or in containers — which is most backends.
- You trade other people's accounts, or many accounts at once.
- You want results you can retry safely and audit: every order has a recorded state, and an order whose outcome is unclear is confirmed against the broker's records instead of guessed.
Many teams use both: the package, or another data source, for research; the API for placing and tracking trades in production.
Next steps
- Use the MT5 API on Linux and macOS — the workarounds people use for the package, and a table mapping each of its calls to the API.
- Place MT5 orders from Python — a complete program with correct retries.
- The MT5 API — everything the API covers.