MetaTrader 4 APIOverview

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

MetaTrader 4 REST & WebSocket API

FxSocket exposes each connected MetaTrader 4 account through a REST API and a WebSocket stream. Every account gets its own dedicated MT4 terminal in our cloud. Requests to your account hit your own terminal, nobody shares it. All endpoints return JSON.

Per-account base URL: https://api.fxsocket.com/mt4/{account_id}

{account_id} is the UUID of your connected MT4 account. Copy it from the Accounts page or read it from GET https://api.fxsocket.com/v1/accounts. Your API key lives on the API Key page.

You can link, list, and remove accounts from the dashboard, or programmatically through the account-management API at https://api.fxsocket.com/v1. See Managing Accounts.

How MT4 Differs From MT5 in This API

The routes and JSON shapes are the same on both platforms, so one client serves MT4 and MT5 accounts alike. What differs is what MT4 itself can do, and the bridge in your terminal fills those gaps in a documented way:

MetaTrader 4MetaTrader 5
Order types6: market, limit, stop8: adds BuyStopLimit and SellStopLimit
Account modelAlways hedgingNetting or hedging (see marginMode)
Trade recordsOne ticket per order; deal is always 0Separate orders, deals and positions
Partial closeRemainder continues under a new ticketPosition keeps its ticket
Trade historyOne row per closed orderOne row per deal (In, Out, InOut, OutBy)
Error codesMT4 errors mapped to MT5 retcodesMT5's native retcodes
Request handlingOne at a time, reads includedReads answered while orders run
Live streamsPolled: trades every 250 msTrade events as they happen
Margin and profit calculatorsComputed by the bridgeMT5's built-in functions
Volume dataTick volume onlyReal volume where the broker provides it

Each topic page has a section on what this means in practice, for example the partial-close renumbering and the MT4 error to retcode table.

Looking for MetaQuotes' own MT4 Server API or Manager API? Those are toolkits for brokers that run their own MetaTrader 4 server, not something you can call with a trading account. Our guide MetaTrader Server, Manager and Web API explained covers what they do and who can get them.

Request Builder

Fill in your account ID and API key, pick an endpoint, and copy a ready-to-run command. The API serves no CORS headers, so requests run from your terminal or server, not from this page.

curl -H "X-API-Key: fxs_live_YOUR_API_KEY" \
  "https://api.fxsocket.com/mt4/YOUR_ACCOUNT_ID/AccountSummary"
Open in browserSwagger UI: needs account IDWS tester: needs account ID + API key

Both links carry your API key in the URL so they open ready to use. Swagger arrives pre-authorized (and scrubs the key from the address bar); the WS tester URL keeps it and will appear in your browser history.

SDKs & Generated Clients

The official FxSocket SDKs wrap this API (account management, trading, market data, and live WebSocket streams) with typed models for MT4 and MT5:

  • Python: pip install fxsocket, sync and async clients. PyPI · GitHub
  • Node.js / TypeScript: npm install @fxsocket/sdk, ESM and CommonJS. npm · GitHub

Using another language? The API is plain HTTP and JSON, and every account serves its own live OpenAPI 3 spec, so you can generate a typed client for any language instead:

  • Swagger UI: https://api.fxsocket.com/mt4/{account_id}/swagger-ui/: browsable, per-account interactive docs (keep the trailing slash). No API key needed. Open yours from the Request Builder above.
  • Raw spec: https://api.fxsocket.com/mt4/{account_id}/api-doc/openapi.json: point any OpenAPI generator (openapi-generator, openapi-typescript, oapi-codegen, …) at this URL.

These two routes (plus /) are the only ones served without an API key.