MetaTrader®, MT4® and MT5® are trademarks of MetaQuotes Ltd. This is an independent service and is not affiliated with, authorized by, or endorsed by MetaQuotes.

MT4 API: control MetaTrader 4 accounts over REST & WebSocket

MQL4 cannot open network sockets, so most MT4 integrations end up as fragile file or DLL bridges. MetaTrader API runs the MT4 connection for you and gives your code the same JSON endpoints it uses for MT5.

REST + WebSocketNo EA requiredPay per seatgRPC ready
# open orders of a connected MT4 account
curl -s -H "x-api-key: $MTAPI_KEY" \
  "https://api.metatraderapi.net/OpenedOrders?id=$MTAPI_ID"

# buy 0.01 lots with a stop loss, 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&stoploss=1.0500&clientOrderId=mt4-0001"
# on MT4 a refused order reports the MT4 error number in "state"
import os, requests

API = "https://api.metatraderapi.net"
s = requests.Session()
s.headers["x-api-key"] = os.environ["MTAPI_KEY"]
ACCOUNT = os.environ["MTAPI_ID"]

for o in s.get(f"{API}/OpenedOrders", params={"id": ACCOUNT}, timeout=75).json():
    print(o["ticket"], o["symbol"], o["lots"], o["profit"])
const API = "https://api.metatraderapi.net";
const headers = { "x-api-key": process.env.MTAPI_KEY };
const id = process.env.MTAPI_ID;

const history = await (await fetch(`${API}/OrderHistory?id=${id}`, { headers })).json();
console.log(history.length, "closed orders");
● 200 JSON over HTTPS EU-hosted

What is an MT4 API?

An MT4 API lets your own software read and control a MetaTrader 4 trading account over the network: account data, quotes, orders, positions and history. MetaTrader 4 itself has no public API for trading accounts, and MQL4 has no socket functions, which is why classic solutions need an Expert Advisor plus a DLL or file bridge on a Windows VPS. MetaTrader API is a hosted MT4 API: connect the account with its broker server, login and password, and call it over REST, WebSocket or gRPC, with the same endpoints as MT5.

Sameendpoints as MT5
NoMQL4, DLL or EA needed
8,000+broker servers
$14per account / month
// how it works

From account to first API call in minutes

  1. STEP 1Connect your MT4 accountBroker server name exactly as MetaTrader 4 shows it, login and the main password (not the investor password). Demo accounts work too.
  2. STEP 2Copy the account id and API keyThe same key format as MT5 (mt5api_…, sent as x-api-key); MT4 and MT5 accounts can share one key.
  3. STEP 3Call the same endpoints as MT5Your code does not change between platforms, apart from the few MT4 differences listed below.
// endpoints

What the MT4 API gives you

A selection of the 100+ endpoints. All of them, with parameters and responses: documentation and OpenAPI.

AreaEndpointWhat it does
Account/AccountSummarybalance, equity, margin, free margin, leverage, currency
Market data/SymbolListthe broker's exact symbol names (with suffixes)
Market data/GetQuotebid / ask for one symbol; /GetQuoteMany for several
Market data/PriceHistorycandles (OHLC) for a symbol and timeframe
Orders/OrderSendmarket and pending orders with SL / TP and clientOrderId
Orders/OrderModifymove stop loss, take profit or a pending price
Orders/OrderCloseclose an order, fully or partially
Orders/OrderDeletedelete a pending order
Positions/OpenedOrdersopen orders and pending orders
History/OrderHistoryclosed orders; /OrderHistoryPagination for large accounts
Connection/ConnectExconnect an account and wait until it is ACTIVE
Experts/EaUploadupload and run your own compiled Expert Advisor (.ex4)
// options

Ways to reach MetaTrader 4, compared

THE USUAL WAYS

  • Expert Advisor + DLL / ZeroMQ bridge: MQL4 has no sockets, so a DLL or file bridge inside a running MT4 app on a Windows VPS; breaks on MT4 updates.
  • Copy of the MT4 app per account on a VPS: one MetaTrader 4 desktop app per account to install, log in, update and monitor.
  • MetaQuotes MT4 Manager API: licensed to brokers for their own server; not available for an account at another broker.

METATRADER API

  • MetaTrader API: no MQL4, no DLL, no VPS; MT4 and MT5 through the same REST and WebSocket endpoints.
  • 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.

MT4 differences you should know

MT4 accounts use the same endpoints as MT5 with a few platform limits: MT4 has no stop-limit orders and no /BalanceHistory; a refused MT4 order reports the MT4 error number in state (MT5 reports a retcode such as 10009); a REST call waits up to 15 s for an MT4 account (30 s for MT5). Everything else, including the WebSocket stream, clientOrderId and Expert Advisor upload (.ex4), works the same.

Limits, in numbers

Rate limitbursts of 40 requests, refilled at 20 per second, per API key
WebSocket25 concurrent streams per account, quotes at most every 200 ms per symbol, heartbeat every 10 s
Timeoutsa REST call waits up to 30 s for the account (MT4: 15 s); set your client timeout to 75 s
Accountsup to 50 seats per customer, more on request
Retriesevery order can carry a clientOrderId: a resend with the same id never opens a second order
// pricing

One price per connected account

REST, WebSocket, gRPC, MT4 and MT5 included. Billed monthly; add or release seats anytime.

Seats 1–4

$14 /seat per month
Start with one account
Create account
VOLUME

Seats 5–19

$13 /seat per month
From your 5th seat, automatically
Create account

Seats 20+

$12 /seat per month
Platforms and fleets
Create account
// questions

MT4 API: frequently asked questions

Is there an official MT4 API?+
Not for trading accounts. MetaQuotes licenses the MT4 Manager and Server APIs to brokers only, and MQL4 has no network sockets. A hosted MT4 API such as MetaTrader API is the way to reach an account at any broker from your own code.
Does MT4 work with the same code as MT5?+
Yes. Each seat connects one MT4 or one MT5 account, the endpoints are the same, and one API key can serve both. Only the MT4 limits above differ.
Do I need the MetaTrader 4 app or a Windows VPS?+
No. The connection runs on our side; your code runs anywhere and only makes HTTPS and WebSocket requests.
Can I copy trades from MT4 to MT5 accounts?+
Yes, with your own code: read or stream the source account and send orders to the target accounts with clientOrderId so a retry never doubles an order.
What does it cost?+
$14 per seat (one connected MT4 or MT5 account) per month for seats 1–4, $13 for seats 5–19 and $12 from the 20th seat. REST, WebSocket, gRPC, MT4 and MT5 are all included. Billed monthly by card through Stripe. There is no free trial and no sandbox: test with a broker demo account on a paid seat.
Is this an official MetaQuotes API or a broker?+
Neither. MetaTrader API is an independent software service, not affiliated with MetaQuotes. MetaQuotes licenses its Manager and Server APIs to brokers only. We are not a broker either: orders execute at your own broker under that broker's rules, and we give no trading advice.