The MT5 API: trade MetaTrader 5 from your own code.
MetaQuotes does not publish a REST API for trading accounts. This page explains what an “MT5 API” really is, the four ways to get one, what separates a good one from a risky one — and how fxapis does it.
# 1. Connect an account (once). The password is encrypted on arrival.
curl -X POST https://api.fxapis.com/v1/accounts \
-H "Authorization: Bearer $FXAPIS_KEY" \
-H "Content-Type: application/json" \
-d '{
"login": "81234567",
"server": "VantageMarkets-Demo",
"password": "trading-password",
"mode": "warm_on_demand"
}'
# 2. Place a market order on it.
curl -X POST https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/orders/market \
-H "Authorization: Bearer $FXAPIS_KEY" \
-H "Idempotency-Key: 7f3e0c9a-order-1" \
-H "Content-Type: application/json" \
-d '{ "symbol": "EURUSD", "side": "buy", "volume": "0.10" }'What is an MT5 API?
MetaTrader 5 is a client–server platform. A broker runs the MetaTrader 5 trade server; traders reach it through the MetaTrader 5 terminal — on the desktop, on a phone or in a browser — signed in with three things: an account number, a password and the name of the broker's server. Every order a trader places travels from a terminal to that trade server.
MetaQuotes gives developers two official ways in from the trader's side. MQL5 is the language for programs that run inside the terminal — Expert Advisors, indicators and scripts. The MetaTrader5 Python package lets a Python program on the same Windows computer drive a running terminal. Brokers get separate interfaces for their own servers. What does not exist is an official web API: a URL your backend can call to trade an account from anywhere.
So when developers search for an MT5 API or a MetaTrader 5 REST API, they mean something that sits between their code and a terminal. It accepts requests — place this order, list these positions, show this history — and turns each one into the matching action in a terminal signed in to the account. The practical questions are who runs those terminals, how many of them, and how carefully the layer in between treats your money when something goes wrong.
Four ways to get an MT5 API
Each of these is a real option, and the right one depends on how many accounts you trade, whose accounts they are, and how much infrastructure you want to run.
1. The official MetaTrader5 Python package
MetaQuotes publishes a free, MIT-licensed MetaTrader5 package on PyPI. It talks to a MetaTrader 5 terminal through inter-process communication (documentation): initialize() connects to a terminal and starts one if needed, login() signs in to an account, and order_send() trades.
It is the right tool for a personal strategy or research on one account. The limits show up as soon as you build a product: the package is published for Windows only, the terminal must run on the same machine as your code, and a terminal works with one signed-in account at a time — so ten accounts means ten terminal installations. HTTP access, retries, monitoring and credential storage are yours to build.
2. The Manager and Server APIs, for brokers
Brokers that run their own MetaTrader 5 server can use MetaQuotes' broker interfaces — the Manager API for administration tools, the Server API for extending the trade server, and others (MetaQuotes' broker page). They manage users, groups and balances on that broker's server. If you are building a product for traders whose accounts sit at many different brokers, these are not available to you — and they are not what you need.
3. Bridges and Expert Advisors
The do-it-yourself route: an Expert Advisor inside a terminal opens a socket, a ZeroMQ channel or an HTTP poll, and your code talks to it. It works with any broker and gives you complete control. It also means running the terminals yourself, usually on Windows virtual servers, one per account; keeping them signed in, updated and online; and deciding what your system believes when the bridge drops halfway through an order.
4. Hosted MT5 APIs
A provider runs the terminals for you and exposes an API — usually REST, sometimes with streaming. You connect an account with its login, password and server, and trade it over HTTPS from any language. MetaApi, API2Trade, mtapi.io and fxapis are examples; they differ in platform support, pricing model and how they handle failures. Our guide to MetaApi alternatives compares several, with sources.
The trade-off is trust: you hand the provider account credentials, and your product depends on their uptime. In exchange you run no terminals at all.
| Aspect | Python package | Manager / Server API | Bridge or EA | Hosted API |
|---|---|---|---|---|
| Built for | One trader's own scripts | Brokers, on their own server | Developers who want full control | Products that trade many accounts |
| What you run | Windows + a terminal | The broker's MT5 server | Terminals + bridge, usually on VPSs | Nothing |
| Accounts | One per terminal at a time | All of that broker's | One per terminal | Many, at brokers that allow password sign-in |
| Languages | Python | C++ / .NET (broker tooling) | Whatever your bridge speaks | Any, over HTTPS |
| Cost shape | Free, plus your servers | Broker licensing | Your servers and time | Subscription or per-account usage |
What to look for in an MT5 API
Placing an order when everything works is the easy part; every option above can do it. The differences are in what happens at the edges — and in trading, the edges are where money is lost.
- A recorded outcome for every order. When a request times out, did the order reach the broker? An API should distinguish “never sent” (safe to retry) from “we don't know yet” (never retry) and then find out — not report a guess.
- Idempotency keys. Networks fail. A retried request must return the first result, not open a second position.
- Credential handling you can explain to your users. How passwords are encrypted, whether they are ever returned or logged, and whether they are erased when an account is disconnected.
- Many accounts at once. If you copy trades or run a signal service, ask how one order reaches fifty accounts and how far apart the first and last fill are.
- History that matches the broker. Orders are what you asked for; deals are what the broker did — including stop-outs and swaps no request of yours caused. You need both.
- Honest numbers. Measured latency with the method stated, and where the servers are. Your broker's location matters as much as the provider's code.
- A pricing model that fits your usage. Per-hour pricing suits accounts that are online occasionally; flat plans suit accounts that trade all month. Model your own numbers.
- Access control. Scoped keys, so a monitoring tool can read, and a risk tool can close positions without being able to open any.
How the fxapis MT5 API works
fxapis is a hosted MetaTrader 5 REST API. MetaTrader 5 runs on our side, hosted in the EU; you call https://api.fxapis.com with an API key and JSON. There is no terminal, VPS or Expert Advisor for you or your users to run.
You connect an account with its login, trading password and server, and choose how it stays online: always connected for accounts that must act instantly, on demand — online when you trade, offline again after 15 idle minutes — or manual, where you decide. In our measurements an account is online about 9.6 seconds after connecting, and an order's round trip from our servers to a London broker's trade server is 96–110 ms. The benchmarks page explains how each number was measured.
Every order type you need
One order, many accounts
Outcomes never guessed
Scoped API keys
Credentials handled properly
import os, uuid, requests
API = "https://api.fxapis.com"
fx = requests.Session()
fx.headers["Authorization"] = f"Bearer {os.environ['FXAPIS_KEY']}"
order = fx.post(
f"{API}/v1/accounts/{account_id}/orders/market",
headers={"Idempotency-Key": str(uuid.uuid4())}, # safe to retry
json={
"symbol": "EURUSD",
"side": "buy",
"volume": "0.10", # decimals are strings
"stopLoss": "1.0890", # absolute prices
"takeProfit": "1.1010",
},
).json()["data"]
print(order["state"], order["filledPrice"]) # filled 1.09472
positions = fx.get(f"{API}/v1/accounts/{account_id}/positions").json()["data"]Built to be retried
Market orders, pending orders, closes and multi-account orders take an Idempotency-Key; stop changes and cancels are safe to repeat. Send the same request twice with the same key and you get the first answer back, with nothing placed a second time. Failures carry stable codes that say what to do: SEND_FAILED means nothing reached the broker and a retry is safe; ORDER_REJECTED carries the broker's own return code; ORDER_UNRESOLVED means do not resend — we are confirming it with the broker.
The API reference shows every endpoint in 13 languages, and the OpenAPI specification generates a client for any other. Start with the five-minute quickstart, then read Trading and history.
Endpoints at a glance
The main endpoints, grouped by what they do. Full request and response shapes are in the API reference.
| Method | Path | What it does |
|---|---|---|
| Accounts | ||
| POST | /v1/accounts | Connect an MT5 account by login, password and server |
| GET | /v1/accounts | List connected accounts and their states |
| GET | /v1/accounts/{id}/status | Cheap status, made for polling |
| POST | /v1/accounts/prepare | Bring up to 200 accounts online in one call |
| POST | /v1/accounts/{id}/warm · cool · restart | Bring online, take offline, or restart one account |
| POST | /v1/accounts/{id}/mode | Always connected, on demand, or manual |
| POST | /v1/accounts/{id}/disconnect | Take offline and erase the stored password |
| Trading | ||
| POST | /v1/accounts/{id}/orders/market | Market order, with optional stop loss and take profit |
| POST | /v1/accounts/{id}/orders/pending | Limit, stop and stop-limit orders |
| POST | /v1/orders/{id}/modify · cancel | Change or cancel a pending order |
| POST | /v1/accounts/{id}/positions/{positionId}/close | Close a position in full or in part (positionId = ticket) |
| POST | /v1/accounts/{id}/positions/{positionId}/modify | Move a position's stop loss or take profit |
| POST | /v1/accounts/{id}/calculate | Margin or profit for a trade, before placing it |
| Many accounts | ||
| POST | /v1/execution-waves | One trade on many accounts, sized per account |
| GET | /v1/execution-waves/{id} | The result for every account, and the spread |
| POST | /v1/execution-waves/{id}/cancel | Call one off before any order has gone out |
| History | ||
| GET | /v1/orders | Every order you placed, filterable by account, state, symbol and time |
| GET | /v1/accounts/{id}/deals | What the broker did, including stop-outs and swaps |
| GET | /v1/accounts/{id}/positions | Open positions, with when they were last seen |
| POST | /v1/accounts/{id}/reconcile | Check against the broker's records now |
What fxapis does not do
- MT4. MetaTrader 5 only, today.
- Market data feeds. No streaming prices, ticks or candles — fxapis is for trading and account data.
- Event webhooks. Not yet: poll order and account status, which is cheap and made for it.
- An uptime guarantee without a contract. Service levels are arranged on Enterprise.
- Signals or advice. fxapis executes what your code sends. It has no opinion on the market.
See also TradingView alerts to MT5, with no EA or VPS, and the hosted MCP server that lets AI assistants use fxapis.
MT5 API questions
Is there an official MetaTrader 5 REST API?
No. MetaQuotes offers MQL5 for programs that run inside the terminal, a Python package that talks to a terminal on the same Windows computer, and separate APIs for brokers' own servers. A REST API for trading an account over the internet comes from a third party that runs the terminals for you — fxapis is one.
Can I use an MT5 API from Linux, macOS or a serverless function?
With a hosted API, yes: it is HTTPS and JSON, so any language on any platform can call it. The official MetaTrader5 Python package only ships for Windows and needs a terminal running on the same machine.
Can I use the fxapis MT5 API from Python?
Yes. It is a REST API, so the requests or httpx libraries are all you need, and the API reference shows every endpoint in Python and 12 other languages. You can also generate a client from the OpenAPI specification.
What is the difference between an MT5 API and the MT5 Manager API?
An MT5 API in the usual sense trades an account the way a trader would, signed in with that account's own login. The Manager API is for brokers: it administers their own MT5 server — users, groups, balances — and is licensed to the broker running it. fxapis is a trader-side API; it works with accounts at MT5 brokers that allow password sign-in, and does not need the broker's involvement.
Does fxapis support MT4?
Not yet. fxapis is MetaTrader 5 only today.
Does fxapis stream prices or candles?
No. fxapis is built for trading and account data — orders, positions, deals and margin calculations. It does not offer a market data feed today; use your broker's feed or a data provider for charts and ticks.
How many accounts can I connect?
It depends on the plan: 1 on Free (when offered), 5 on Starter, 50 on Scale, and up to 500 on Enterprise, with 2,000,000 orders a month, priced by contract. Accounts can stay online all the time, come online only when you trade, or be controlled by you.
Is there a sandbox?
Keys come labelled live or test, but both reach real brokers. Use your broker's free demo accounts to build and test, then connect real-money accounts.
Place your first MT5 trade over HTTPS.
Create a workspace, issue an API key, connect a demo account and send an order — in about five minutes.