MetaTrader 4 APIAccount Data

For AI agents: this page is also available as Markdown at /docs/mt4/account-data.md. The index of every docs page is /docs/llms.txt.

MetaTrader 4 Account Data & Status API

Read live and static state for a connected MetaTrader 4 account: balance and equity, the static account configuration, open positions and pending orders, trade and position history, and a single connection-health endpoint to confirm the account is logged in and trading-ready.

How account data works on MT4

  • Always hedging. MT4 has no netting accounts, so /AccountInfo always reports marginMode "Hedging" and fifoClose false. Two opposite orders on the same symbol stay two open tickets.
  • Orders, not deals. MT4 keeps one record per order and no separate deal log. In /OrderHistory, ticket, order and position all carry the order's ticket and entry is always "out".
  • History includes more than trades. Deleted pending orders appear in /OrderHistory with their pending type, and deposits or withdrawals as type "Balance". /PositionHistory leaves both out.
  • Partial closes are separate rows. Closing part of an order renumbers it: the closed part keeps the old ticket, the remainder continues under a new one. History therefore shows them as separate positions instead of one.
  • No latency figure. MT4 does not report its ping to the broker, so pingMs in /status is always 0.
GET /mt4/{account_id}/AccountSummary

Snapshot of the connected trading account: balance, credit, floating profit, equity, margin, free margin, margin level, leverage, account currency, and account type. Reflects broker-side state at call time, no caching.

Example request
curl -H "X-API-Key: fxs_live_..." \
  https://api.fxsocket.com/mt4/{account_id}/AccountSummary
Response
{
  "balance": 9686.15,
  "credit": 0.0,
  "profit": 0.0,
  "equity": 9686.15,
  "margin": 0.0,
  "freeMargin": 9686.15,
  "marginLevel": 0.0,
  "leverage": 400,
  "currency": "USD",
  "type": "Demo"
}
GET /mt4/{account_id}/AccountInfo

Static identity and configuration of the account: the who-and-how that rarely changes, as opposed to the live financials in /AccountSummary. Includes the account holder name, login, broker company and server, currency, leverage, account type, margin mode, stop-out configuration, and trade permissions. On MT4, marginMode is always "Hedging" (the platform has no netting accounts) and fifoClose is always false; currencyDigits is derived from the currency (0 for JPY-class currencies, otherwise 2).

Example request
curl -H "X-API-Key: fxs_live_..." \
  https://api.fxsocket.com/mt4/{account_id}/AccountInfo
Response
{
  "name": "Lars Joeressen",
  "login": 2100152454,
  "server": "TegasFX-Demo",
  "company": "TegasFX Ltd",
  "currency": "USD",
  "currencyDigits": 2,
  "leverage": 200,
  "type": "Demo",
  "marginMode": "Hedging",
  "marginSoMode": "Percent",
  "marginCallLevel": 100.0,
  "stopOutLevel": 70.0,
  "tradeAllowed": true,
  "tradeExpert": true,
  "limitOrders": 200,
  "fifoClose": false
}
GET /mt4/{account_id}/OpenedOrders

All open positions and active pending orders: one row per position (already-filled trade) and one per pending order (limit or stop; MT4 has no stop-limit orders). kind discriminates the two; pending orders show their trigger price in openPrice and carry zero swap/profit. On MT4 an order and its position are the same thing, so ticket identifies both.

Example request
curl -H "X-API-Key: fxs_live_..." \
  https://api.fxsocket.com/mt4/{account_id}/OpenedOrders
Response
[{
  "ticket": 211438758,
  "symbol": "USDJPY",
  "type": "Sell",
  "kind": "position",
  "lots": 0.1,
  "openPrice": 160.505,
  "currentPrice": 160.547,
  "stopLoss": 160.576,
  "takeProfit": 160.458,
  "swap": 0.0,
  "profit": -2.62,
  "magic": 0,
  "comment": "",
  "openTime": "2026-06-11T11:02:04.000Z"
}, {
  "ticket": 211583734,
  "symbol": "GBPUSD",
  "type": "BuyStop",
  "kind": "pending",
  "lots": 0.01,
  "openPrice": 1.34958,
  "currentPrice": 1.33683,
  "stopLoss": 1.34611,
  "takeProfit": 1.35275,
  "swap": 0.0,
  "profit": 0.0,
  "magic": 0,
  "comment": "",
  "openTime": "2026-06-10T09:30:00.000Z"
}]
GET /mt4/{account_id}/OrderHistory

Closed orders in a time range, one row per closed MT4 order: MT4 keeps no separate deal log. ticket, order and position all carry the order's ticket, entry is always "out", and price and time are the close price and close time. The list also holds deleted pending orders (with their pending type) and balance operations such as deposits (type "Balance"). Omit both bounds to fetch all-time history.

  • from: Inclusive lower bound (broker server time). ISO-8601 (2026-01-01T00:00:00Z) or YYYY-MM-DD. Absent → epoch.
  • to: Inclusive upper bound, same formats. Absent → now.
Example request
curl -H "X-API-Key: fxs_live_..." \
  "https://api.fxsocket.com/mt4/{account_id}/OrderHistory?from=2026-01-01&to=2026-12-31"
Response
[{
  "ticket": 211438758,
  "order": 211438758,
  "position": 211438758,
  "symbol": "EURUSD",
  "type": "Buy",
  "entry": "out",
  "volume": 0.1,
  "price": 1.15410,
  "commission": -0.80,
  "swap": 0.0,
  "profit": 20.90,
  "magic": 0,
  "comment": "",
  "time": "2026-06-10T15:42:11Z"
}]
GET /mt4/{account_id}/PositionHistory

Closed positions in a time range: one row per closed market order. On MT4 an order already is the whole round trip, so positionId is the order's ticket and the open and close prices are the order's own, with netProfit = profit + swap + commission. Deleted pending orders and balance operations are left out. A partial close shows up as separate rows (the part you closed, and later the remainder under its new ticket), not merged into one position as on MT5. Omit both bounds to fetch all-time history.

  • from: Inclusive lower bound (broker server time). ISO-8601 (2026-01-01T00:00:00Z) or YYYY-MM-DD. Absent → epoch.
  • to: Inclusive upper bound, same formats. Absent → now.
Example request
curl -H "X-API-Key: fxs_live_..." \
  "https://api.fxsocket.com/mt4/{account_id}/PositionHistory?from=2026-01-01&to=2026-12-31"
Response
[{
  "positionId": 211438758,
  "symbol": "EURUSD",
  "type": "Buy",
  "volume": 0.1,
  "openTime": "2026-06-10T09:12:04.000Z",
  "openPrice": 1.15201,
  "closeTime": "2026-06-10T15:42:11.000Z",
  "closePrice": 1.15410,
  "profit": 20.90,
  "swap": 0.0,
  "commission": -0.80,
  "netProfit": 20.10,
  "magic": 0,
  "comment": ""
}]
GET /mt4/{account_id}/status

Full connection health of the terminal, in one call: is the terminal alive, is it connected to the broker, and is the account logged in? Use this to confirm an account is live and trading-ready before sending orders. Always returns HTTP 200. Read the body to see the actual state. The top-level status is ready (everything healthy and the account logged in), starting (still booting / logging in), degraded (e.g. broker disconnected), or down. For lightweight probes there are also two unauthenticated routes that signal via HTTP status code: GET /healthz (200 once fully ready, 503 otherwise) and GET /livez (200 while the terminal is alive, regardless of broker connection). pingMs is always 0 on MT4, which does not report its latency to the broker.

Example request
curl -H "X-API-Key: fxs_live_..." \
  https://api.fxsocket.com/mt4/{account_id}/status
Response
{
  "status": "ready",
  "terminal": { "alive": true, "build": 1440, "pingMs": 0 },
  "broker": { "connected": true, "server": "TegasFX-Demo" },
  "account": {
    "loggedIn": true,
    "login": 2100152454,
    "currency": "USD",
    "type": "Demo",
    "tradeAllowed": true
  },
  "bridge": { "version": "0.2.0", "tradeEaReady": true, "symbolsSynced": true },
  "serverTime": "2026-06-11T08:55:57.000Z"
}