CLIENT API

MT5 Client API

Build richer account automation on MetaTrader 5 with expanded order semantics, history access, and streaming telemetry.

Auth model Bearer + bridge session
Primary use MT5 execution & analytics
Coverage Orders, positions, history, stats

MT5 Semantics

Handle hedging and netting accounts, richer symbol metadata, and more detailed history access than MT4.

Analytics Ready

Use history, deals, equity curves, and performance metrics to power scorecards and investor dashboards.

Realtime Control

Keep trade automation and account telemetry aligned through a shared bridge session and event stream.

Quick Start

MT5 follows the same session bootstrap pattern as MT4, but exposes a wider order model and richer account metadata once connected.

You can move from credential exchange to quote streaming and first trade placement in three calls.

  • Open a session with terminal credentials.
  • Fetch account metadata and trading permissions.
  • Submit a market or pending order task.
  • Track completion over WebSocket or polling.
BASH
curl https://api.metatraderapi.xyz/mt5/client/orders \
  -H "Authorization: Bearer <api-key>" \
  -H "x-session-id: sess_live_0191" \
  -d '{
    "symbol": "XAUUSD",
    "type": "SELL_LIMIT",
    "price": 2318.40,
    "volume": 0.10
  }'

Order Model

MT5 supports netting and hedging account modes, advanced pending orders, volume granularity, and extended trade metadata.

Use task receipts to correlate your internal strategy events with actual broker-side order lifecycle updates.

  • Market, limit, stop, and stop-limit orders
  • Partial close and position merge awareness
  • Symbol-specific tick size validation
  • Comment and external id propagation

Historical Data & Statements

Query orders, deals, balances, equity changes, and position history for reporting and audit pipelines.

History endpoints are optimized for windowed fetches, making them suitable for scheduled ETL tasks.

Trading Statistics

The MT5 client surface also exposes drawdown, Sharpe ratio, expectancy, win-rate, and profit-factor calculations so you can embed analytics directly into your product.

Use these endpoints for daily rollups, strategy scorecards, or investor dashboards.

Authentication & Headers

The MT5 client surface uses the same workspace API key and bridge session model as MT4, but exposes more account metadata once connected.

Prefer session warm-up, symbol prefetch, and explicit request ids before launching batch trade or reporting flows.

HeaderValueUseDescription
AuthorizationBearer <api-key>RequiredWorkspace API key created for the target environment.
x-session-idsess_mt5_live_07RequiredMT5 bridge session identifier.
x-request-idreq_stats_2101RecommendedIdempotency key for writes and batch fetches.
Accept-Languageen-USOptionalUse when normalizing locale-sensitive symbol metadata.

Endpoint Matrix

Session & Permissions

MethodPathPurpose
POST/session/openBootstrap an MT5 bridge session.
GET/accountInspect account metadata and trading permissions.
GET/symbolsList enabled instruments and contract settings.
GET/symbols/{symbol}Read detailed symbol parameters.

Orders & History

MethodPathPurpose
POST/ordersSubmit market, limit, stop, or stop-limit tasks.
GET/positionsRead current positions for hedging or netting accounts.
GET/history/dealsRead deal history for reconciliation.
GET/history/equityFetch equity timeline for charts or daily rollups.

Analytics & Streaming

MethodPathPurpose
GET/stats/performanceCompute drawdown, Sharpe, expectancy, and profit factor.
GET/orders/historyRetrieve historical orders and state transitions.
WS/eventsReceive quote, order, and position updates in real time.
GET/events/testerOpen a built-in browser tester for stream diagnostics.

Errors & Limits

MT5 writes return task receipts first and broker execution details later. Keep a durable mapping between your strategy event id and the API task id.

Historical endpoints are optimized for windowed reads. Paginate large backfills to avoid rate limiting or oversized responses.

CodeNameMeaning
400ValidationErrorPayload, symbol, or trade parameters failed validation.
401UnauthorizedAPI key or session token is missing, expired, or revoked.
409TaskConflictThe same external request id was replayed with different payload data.
429RateLimitedWorkspace or account throughput limits were exceeded.
502BridgeUnavailableThe bridge lost connectivity to the terminal or broker server.

Deployment & Runtime

For analytics-heavy workloads, isolate history reads from execution workers so reporting jobs do not compete with live order placement.

Use the built-in events tester and a dedicated stream health monitor to validate account subscriptions before routing live traffic.

  • Warm the session before opening trading windows.
  • Validate symbol precision and lot size locally before writes.
  • Persist deal and position snapshots for audit pipelines.
  • Track websocket disconnect rate separately from HTTP latency.