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. Trustpilot4.0
EN
ACCOUNT CONNECTION · MT4 & MT5

Connect any MetaTrader account — with one call.

Hand us a login, main password and server; get back an account id and an API key (mt5api_…). A new connection is usually ACTIVE within 1–2 minutes. Then watch its state, reconnect automatically if the broker drops it, and disconnect when you're done — the whole connection lifecycle over the API.

/ConnectEx · /ConnectState · /Reconnect · /Disconnect
Login + server → account id Auto-reconnect on drop Live connection state MT4 & MT5, any broker
// what it is

The front door to every other endpoint.

The Connection API turns a MetaTrader login into an addressable account you can trade and stream. You send the login, main password and broker server to /ConnectEx (a GET request); a dedicated connection starts, logs in, and syncs — and you get back an account id (a UUID) plus an API key (apiKey, mt5api_…), shown only in this response. From then on, every other endpoint targets that account with ?id=. If the broker ever drops the session, it is restored automatically and /Reconnect rebuilds it on demand, and /ConnectState tells you exactly where a connection stands at any moment.

// the lifecycle

Connect, watch, reconnect, disconnect.

1

Connect

/ConnectEx with login, password and server. Add wait=60 to wait up to 60 seconds for ACTIVE (usually 1–2 minutes; then poll /ConnectState), or use /ConnectStream to watch it come up.

2

Watch

/ConnectState reports one account or all of them; /OnConnectState streams every status change over WebSocket.

3

Recover

/Reconnect rebuilds a dropped session; /Disconnect tears it down cleanly when you're finished.

connect.sh
curl "https://api.metatraderapi.net/ConnectEx?user=1072…&password=…&server=Ava-Demo%201-MT5&platform=MT5&wait=60" \
  -H "Authorization: Bearer mt5mgmt_…"

{ "id": "7f123497-63b2-496d-864d-cf3657f73b1f", "status": "ACTIVE", "connected": true,
  "statusReason": null, "apiKey": "mt5api_…", "apiKeyId": "fd41e389-…",
  "platform": "MT5", "brokerServer": "Ava-Demo 1-MT5", "note": "…" }

# apiKey is shown only here: store it. Use the id everywhere else
curl "https://api.metatraderapi.net/AccountSummary?id=7f123497-63b2-496d-864d-cf3657f73b1f" -H "x-api-key: mt5api_…"
// questions

Frequently asked

How do I connect an MT4 or MT5 account via API?+
Send the login, password and broker server to /ConnectEx. A connection starts and logs in, and you receive an account id (UUID) and an API key (mt5api_…). Add wait=60 to wait up to 60 seconds for ACTIVE; a new connection is usually ACTIVE within 1–2 minutes, so poll /ConnectState if it isn't yet.
What do I do with the account id?+
Every other endpoint — quotes, trading, streaming, EAs — targets the account by passing ?id=. The id is how the API knows which connected account to talk to.
What happens if the broker drops the connection?+
Dropped connections are restored automatically. Call /Reconnect to rebuild the session on demand, or watch /ConnectState / stream /OnConnectState to detect drops as they happen and react automatically.
Do I pass a server name or a host and port?+
Either. Pass the broker's server name, or a host and port directly. /GetBrokerServersByBrokerName looks up a broker's servers and access points by name.
Does disconnecting stop my billing period?+
/Disconnect removes the live connection; its seat stays paid until the end of the billing month, and your next connection reuses it at no charge. An unused paid seat keeps renewing until you release it.
Create account

One call, and your account is on the API.

Connect an MT4 or MT5 login and get an id you can trade and stream against, usually within 1–2 minutes.