Bridge Session
Open a single MT4 bridge session, then reuse it for account reads, trade tasks, and market subscriptions.
Automate MetaTrader 4 terminals with low-latency order routing, account monitoring, and real-time streaming.
Open a single MT4 bridge session, then reuse it for account reads, trade tasks, and market subscriptions.
Cover market orders, pending orders, close operations, and on-the-fly SL/TP adjustments from one API surface.
Pair REST reads with WebSocket updates for equity, margin, open orders, and quote telemetry.
Create an API key in the client area, open a terminal bridge, and exchange a short-lived session token before placing any request.
The MT4 client flow is designed around predictable task-based execution so your integrations can queue and reconcile orders deterministically.
curl -X POST https://api.metatraderapi.xyz/mt4/client/session/open \
-H "Authorization: Bearer <api-key>" \
-H "Content-Type: application/json" \
-d '{
"accountId": "demo-mt4-01",
"server": "Broker-Demo",
"login": 120045,
"password": "<terminal-password>"
}'Every MT4 bridge session exposes broker state, margin data, positions, open orders, and trade history in a single channel.
For resilient infrastructure, pair periodic REST polling with WebSocket subscriptions for balance, equity, and order status updates.
The MT4 Client API supports market execution, pending orders, position closure, stop-loss and take-profit updates, and task cancellation.
Each call returns a task identifier so you can reconcile asynchronous broker execution in your own control plane.
{
"symbol": "EURUSD",
"type": "BUY",
"volume": 0.2,
"sl": 1.0735,
"tp": 1.0790,
"comment": "alpha-engine"
}Use quote, depth, account, order, and on-profit channels to drive dashboards, risk monitors, and alerting pipelines.
For high-throughput strategies, batch your subscription sets by symbol universe and only retain the channels you actually consume.
Use your workspace API key to open a bridge session, then propagate the returned session id on every trading or read request.
For retry-safe workflows, send your own request id so order tasks and reconciliation jobs stay idempotent under network failures.
| Header | Value | Use | Description |
|---|---|---|---|
| Authorization | Bearer <api-key> | Required | Workspace credential created in the client area. |
| x-session-id | sess_mt4_demo_01 | Required | Bridge session returned by the session bootstrap flow. |
| x-request-id | req_order_0192 | Recommended | Stable id used for retries and external reconciliation. |
| Content-Type | application/json | Write calls | JSON payload content type for create / update requests. |
| Method | Path | Purpose |
|---|---|---|
| POST | /session/open | Start a broker-connected MT4 bridge session. |
| GET | /session/{sessionId} | Inspect session health, account state, and broker metadata. |
| POST | /session/{sessionId}/heartbeat | Keep long-running bridge sessions alive. |
| DELETE | /session/{sessionId} | Release server resources and revoke the session. |
| Method | Path | Purpose |
|---|---|---|
| GET | /account | Read balance, equity, free margin, and currency data. |
| GET | /positions | List open positions and pending orders. |
| GET | /symbols | Return enabled trading symbols for the account. |
| GET | /quotes/history | Fetch OHLC bars for analytics or charting. |
| Method | Path | Purpose |
|---|---|---|
| POST | /orders | Create market or pending trade tasks. |
| PATCH | /orders/{taskId} | Modify open task parameters before execution. |
| POST | /positions/{ticket}/close | Close an open position or reduce exposure. |
| WS | /events | Receive quotes, profit, and order execution events in real time. |
Write-side requests should be treated as task submissions. A queued response does not guarantee broker execution, so always reconcile by task id or execution event.
Production workloads should combine request ids, adaptive retry backoff, and circuit breaking around broker connectivity incidents.
| Code | Name | Meaning |
|---|---|---|
| 400 | ValidationError | Payload, symbol, or trade parameters failed validation. |
| 401 | Unauthorized | API key or session token is missing, expired, or revoked. |
| 409 | TaskConflict | The same external request id was replayed with different payload data. |
| 429 | RateLimited | Workspace or account throughput limits were exceeded. |
| 502 | BridgeUnavailable | The bridge lost connectivity to the terminal or broker server. |
Run the bridge close to your trading infrastructure to reduce round-trip time between order creation and broker execution.
Split quote streaming, trading, and reporting jobs into separate workers so a burst in one pipeline does not delay another.