MT5 API: one REST & WebSocket API for MetaTrader 5
Read balances, positions and history, stream live quotes and send orders on any MetaTrader 5 account, from any language, over plain HTTPS. We run the MT5 connection; your code only makes requests.
# account summary of a connected MT5 account
curl -s -H "x-api-key: $MTAPI_KEY" \
"https://api.metatraderapi.net/AccountSummary?id=$MTAPI_ID"
# a market order that is safe to retry
curl -s -H "x-api-key: $MTAPI_KEY" \
"https://api.metatraderapi.net/OrderSend?id=$MTAPI_ID&symbol=EURUSD&operation=Buy&volume=0.01&clientOrderId=order-0001"
# "state": 10009 means filled; any other value is the broker's reasonimport os, requests
API = "https://api.metatraderapi.net"
s = requests.Session()
s.headers["x-api-key"] = os.environ["MTAPI_KEY"]
ACCOUNT = os.environ["MTAPI_ID"] # the account's UUID
summary = s.get(f"{API}/AccountSummary", params={"id": ACCOUNT}, timeout=75).json()
print(summary["balance"], summary["equity"], summary["currency"])
order = s.get(f"{API}/OrderSend", params={"id": ACCOUNT, "symbol": "EURUSD",
"operation": "Buy", "volume": 0.01, "clientOrderId": "order-0001"}, timeout=75).json()
print("filled" if order.get("state") == 10009 else f"refused: {order.get('state')}")const API = "https://api.metatraderapi.net";
const headers = { "x-api-key": process.env.MTAPI_KEY };
const id = process.env.MTAPI_ID;
const res = await fetch(`${API}/GetQuote?id=${id}&symbol=EURUSD`, { headers });
const quote = await res.json();
console.log(quote.bid, quote.ask);
// live quotes, positions and trades over one WebSocket
const ws = new WebSocket(`wss://api.metatraderapi.net/v1/stream?id=${id}`, { headers });
ws.onopen = () => ws.send(JSON.stringify({ action: "subscribe", symbol: "EURUSD" }));What is an MT5 API?
An MT5 API is an interface that lets your own software read and control a MetaTrader 5 trading account over the network. MetaQuotes does not offer a public API for MT5 trading accounts: its Manager and Server APIs are licensed to brokers, and its Python package only drives a MetaTrader 5 desktop app on the same Windows machine. MetaTrader API is a hosted MT5 API: you connect an account with its broker server, login and password, and get REST (JSON over HTTPS), WebSocket and gRPC access to it, without installing MetaTrader or an Expert Advisor.
From account to first API call in minutes
- STEP 1Connect your MT5 accountIn the dashboard (or with POST /v1/seats from your backend): broker server name, login and the account's main password. A demo account works the same way.
- STEP 2Copy the account id and API keyEach account gets a UUID (sent as ?id=) and an API key starting with mt5api_ (sent as the x-api-key header).
- STEP 3Call the APIREST for requests, one WebSocket for live quotes, positions, orders and trades, gRPC if you want typed clients.
What the MT5 API gives you
A selection of the 100+ endpoints. All of them, with parameters and responses: documentation and OpenAPI.
| Area | Endpoint | What it does |
|---|---|---|
| Account | /AccountSummary | balance, equity, margin, free margin, leverage, currency |
| Account | /AccountDetails | account and server details |
| Market data | /SymbolList | the broker's exact symbol names (with suffixes) |
| Market data | /GetQuote | bid / ask for one symbol; /GetQuoteMany for several |
| Market data | /PriceHistory | candles (OHLC) for a symbol and timeframe |
| Market data | /MarketBookGet | MT5 depth of market (Level 2), where the broker publishes it |
| Orders | /OrderSend | market and pending orders with SL / TP and clientOrderId |
| Orders | /OrderModify | move stop loss, take profit or a pending price |
| Orders | /OrderClose | close a position, fully or partially |
| Positions | /OpenedOrders | open positions and pending orders |
| History | /OrderHistory | closed trades; /OrderHistoryPagination for large accounts |
| History | /BalanceHistory | deposits, withdrawals and balance operations (MT5) |
| Connection | /ConnectEx | connect an account and wait until it is ACTIVE |
| Experts | /EaUpload | upload and run your own compiled Expert Advisor (.ex5) |
Ways to reach MetaTrader 5, compared
THE USUAL WAYS
- Official MetaTrader5 Python package: Windows only; drives a MetaTrader 5 desktop app that must run on the same machine; one account per running app.
- Expert Advisor + WebRequest / sockets: MQL5 code inside a running MetaTrader 5 app on a VPS you maintain; you build the bridge and keep it alive.
- MetaQuotes Manager / Server API: licensed to brokers for their own server; not available for a trading account at another broker.
METATRADER API
- MetaTrader API: any language, any OS, no desktop app, MT4 and MT5 through the same endpoints, many accounts per key.
- Works with your own account at any broker: no broker permission, Manager licence or server access needed.
- Each account runs on its own isolated connection; broker passwords are stored AES-256-GCM encrypted.
- Uptime measured live on the public status page.
Where do I get an MT5 API key?
MetaQuotes does not issue API keys for trading accounts, and there is no API key inside the MetaTrader 5 app. The key comes from the service that runs the connection. With MetaTrader API you connect the account in the dashboard and click “Generate key”: the key (mt5api_…) is shown once, so store it as a secret. One key works for every account of your login (choose it with ?id=); for an app that hands keys to end users, create keys limited to one account, and read-only keys if they must not trade.
Limits, in numbers
| Rate limit | bursts of 40 requests, refilled at 20 per second, per API key |
| WebSocket | 25 concurrent streams per account, quotes at most every 200 ms per symbol, heartbeat every 10 s |
| Timeouts | a REST call waits up to 30 s for the account (MT4: 15 s); set your client timeout to 75 s |
| Accounts | up to 50 seats per customer, more on request |
| Retries | every order can carry a clientOrderId: a resend with the same id never opens a second order |
One price per connected account
REST, WebSocket, gRPC, MT4 and MT5 included. Billed monthly; add or release seats anytime.