Skip to content

MT5 API: a MetaTrader 5 REST API for your account

Updated 2026-11-24

The MT5 API from FiveSocket is a MetaTrader 5 REST API for your own account. A standard MT5 terminal does not accept HTTP requests, so reading or trading an account from your own code needs a service that keeps a logged-in MT5 session and exposes it over HTTP. FiveSocket is that service. You link a login once, then call https://api.fivesocket.com/v1 with an API key from any language that can make a web request. You can read balances, positions, orders, deals and history. You can place, change and close orders after you turn trading on for that account.

7-day free trial. Paid plans start at $9.99 a month. See pricing

How it works

Your request reaches the FiveSocket gateway, which checks the API key and its permissions. FiveSocket then answers from an MT5 terminal session it hosts for that account, logged in with the credentials you linked.

Every successful read comes from MT5 at the time you ask. Responses include observedAt, latencyMs and a request ID, so you can see when the data was read. Money, prices and volumes are decimal strings, and timestamps are UTC.

Main endpoints
RequestWhat it does
GET /v1/accountsList linked accounts
GET /v1/accounts/{accountId}/balanceBalance, equity, margin and related fields
GET /v1/accounts/{accountId}/positionsOpen positions
GET /v1/accounts/{accountId}/tradesClosed trades for a time window
GET /v1/accounts/{accountId}/dealsRaw deal history for a time window
GET /v1/accounts/{accountId}/ordersHistorical orders for a time window
GET /v1/accounts/{accountId}/history/exportLong deal or order history, one page at a time
GET /v1/accounts/{accountId}/candlesCompleted broker candles for a symbol and timeframe
GET /v1/accounts/{accountId}/symbolsContract specifications for symbols you name
GET /v1/accounts/{accountId}/snapshotBalance, positions and recent trades in one call
GET /v1/accounts/{accountId}/prop-statusDaily-loss and maximum-loss room under the prop-firm program you set
POST /v1/accounts/{accountId}/backtestsReplay a rule over your broker's candles. Read-only, no order is placed
PUT /v1/accounts/{accountId}/executionTurn on trading with a symbol and size policy
GET /v1/accounts/{accountId}/execution/ordersWorking orders on the live account
POST /v1/accounts/{accountId}/execution/ordersPlace a market or pending order
PATCH /v1/accounts/{accountId}/execution/orders/{orderId}Change a working order
DELETE /v1/accounts/{accountId}/execution/orders/{orderId}Cancel a working order
POST /v1/accounts/{accountId}/execution/positions/{positionId}/closeClose a position in full or in part

The full list is in the OpenAPI document at https://api.fivesocket.com/v1/openapi.json. The MT5 API documentation covers setup, scopes and error codes. MT5 API quickstart

Every error code and the rate limits are listed in the errors and limits page. Errors and limits

Which MT5 API do you need?

People search for an MT5 API and mean three different things. Pick by who runs the terminal and whose account you want to reach.

MT5 API options
OptionWhat it isFits when
MetaTrader5 Python packageMetaQuotes publishes it on PyPI. It is Windows only and talks to a logged-in terminal on the same machine.You already run a Windows machine all day and write Python.
MetaQuotes server APIs (Manager and Web APIs)Interfaces to the MT5 trade server itself, for the broker that runs it.You are a broker. An individual trader does not get these for their own account.
FiveSocket REST APIA hosted MT5 terminal per linked account, called over HTTPS with an API key.You want your own account from any language or operating system, with no terminal to run.

If you want to read or trade your own broker account from code, the first and third rows are your choices. The Windows requirement is explained in the guide on using the MT5 API without Windows. Use the MT5 API without Windows

Getting an MT5 API key

You create a FiveSocket API key in the control panel after you start a trial. The key is shown once, so store it in a secret manager. If you lose it, revoke it and create another.

Scopes a key can carry
ScopeGrants
accounts:readList linked accounts
data:readLive reads: balance, positions, trades, deals, orders, candles, symbols, snapshot
trading:executeSet the execution policy and place, change and close orders

Give each program its own key with only the scopes it needs. A dashboard that only shows data needs data:read and accounts:read, and nothing else. Authentication and scopes

Examples and language guides

Any language that can send HTTPS requests works. This reads recent candles with curl.

curl -G -H "Authorization: Bearer $FIVESOCKET_KEY" \
  --data-urlencode "symbol=EURUSD" \
  --data-urlencode "timeframe=H1" \
  --data-urlencode "count=200" \
  https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/candles

For full examples in your language, see the Python and Node.js guides. MT5 API in Python

Node.js, Bun and Deno call the API with plain fetch. MT5 API in Node.js

Candles, deals and orders in more depth are in the historical data guide. MT5 historical data API

To send TradingView alerts to MT5 through n8n, or to use the same account from an AI assistant, use these guides. TradingView and n8n to MT5

Claude, ChatGPT and Cursor connect to the same account over MCP instead of an API key. MT5 MCP server

What you need

  • An MT5 login, its password, and the exact server name shown in your MT5 terminal. The name must match exactly.
  • A FiveSocket API key. You create it in the control panel and see it once. Give each program its own key with the fewest scopes it needs.
  • Any language or tool that can send HTTPS requests. You do not need an SDK.

Make your first calls

  1. Create an API key

    Start a trial, create a key in the control panel, and keep it in a secret manager.

    export FIVESOCKET_KEY="mt5_live_..."
  2. Link the MT5 account

    FiveSocket logs in to your broker once before the account becomes active. Use the investor password if this program should only read. The response gives you an account ID.

    curl -X POST https://api.fivesocket.com/v1/accounts \
      -H "Authorization: Bearer $FIVESOCKET_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: link-demo-1" \
      -d '{"login":"12345678","password":"your-investor-password","server":"YourBroker-Demo"}'
  3. Read live data

    Use the account ID in the path. The first read may take several seconds while MT5 logs in.

    curl -H "Authorization: Bearer $FIVESOCKET_KEY" \
      https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/positions
  4. Turn on trading, if you need it

    Trading stays off until you send a policy with exact symbols and the largest order size for each. The key needs the trading:execute scope. FiveSocket first checks that MT5 allows trading on the account.

    curl -X PUT https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/execution \
      -H "Authorization: Bearer $FIVESOCKET_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: enable-1" \
      -d '{"symbols":[{"symbol":"EURUSD","maxVolume":"0.10"}]}'
  5. Place an order

    Send an Idempotency-Key with every write. A retry with the same key and the same order does not send the order twice.

    curl -X POST https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/execution/orders \
      -H "Authorization: Bearer $FIVESOCKET_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: order-1" \
      -d '{"clientOrderId":"order-1","symbol":"EURUSD","side":"buy","type":"market","volume":"0.10"}'

Code that places real orders can lose real money when it misbehaves. Test against a demo account first, and keep the policy's symbols and sizes narrow.

Limits

Requests per minute by plan
PlanAccountsPer API keyPer workspacePer MT5 account
Starter16012030
Plus512030030
Scale203001,00060
  • The API answers requests. It has no price stream and no webhooks, so your code polls for changes.
  • The first read after a session has gone idle logs in to your broker and can take several seconds. If that runs long, you get a 202 response with the code account_warming. Repeat the same request after the delay it gives.
  • History reads cover at most 90 days per request and 1,000 rows per page. The first request needs an explicit to date.
  • A trading response can come back as commit_unknown when the broker's reply is lost. Do not send a new order. Poll the original command until it reaches a final state.

Frequently asked questions

Does MetaTrader 5 have a REST API?
A standard MT5 terminal does not accept HTTP requests. You need a bridge that runs a terminal and offers an API in front of it. FiveSocket is a hosted bridge, and you can also build your own on a Windows machine.
Which programming languages can I use?
Any language that can send an HTTPS request with a bearer token. The OpenAPI document describes every request and response if you want to generate a client.
Can I place trades through the API?
Yes, after you turn trading on for the account with a policy of exact symbols and maximum order sizes. Market, limit, stop and stop-limit orders are supported, along with changes to orders and full or partial closes.
Can I get live prices or ticks?
You can read a symbol's current price on request from the execution symbols endpoint, which needs the trading:execute scope. There is no streaming feed.
Is the data real time?
Each successful read comes from a live MT5 session at the moment you ask, and the observedAt field shows when. Responses with account data are sent with Cache-Control: no-store.
Where is my broker password kept?
FiveSocket encrypts it and keeps the encryption keys in a separate store. No endpoint returns it, and it never appears in logs.
How much does it cost?
Starter is $9.99 a month for one MT5 account. Plus is $29.99 a month for 5 MT5 accounts. Scale is $79.99 a month for 20 MT5 accounts. Link your MT5 account and try it free, no card: 24 hours or 100 calls, whichever comes first. Then a 7-day free trial, card required. Cancel anytime. The trial includes one connected MT5 account.
How do I get an MT5 API key?
Start a trial, then create an API key in the FiveSocket control panel and choose its scopes: accounts:read, data:read or trading:execute. The key is shown once, so store it in a secret manager. If you lose it, revoke it and create a new one.
Is there a free MT5 API?
FiveSocket has a free trial rather than a free plan. Link your MT5 account and try it free, no card: 24 hours or 100 calls, whichever comes first. Then a 7-day free trial, card required. Cancel anytime. The trial includes one connected MT5 account. The MetaTrader5 Python package from MetaQuotes is free, but it needs Windows and a running MT5 terminal.
Where is the MT5 API documentation?
The FiveSocket documentation is at https://docs.fivesocket.com, with a quickstart, authentication and scopes, and errors and limits. The OpenAPI document is at https://api.fivesocket.com/v1/openapi.json.
What is the MT5 Web API?
MetaQuotes offers server-side interfaces, the Manager and Web APIs, that connect to the MT5 trade server and are meant for the broker that runs it. They are not a way for a trader to reach their own account. FiveSocket is a hosted REST API for a single trading account, called with an API key.
Can I use the MT5 API without Windows?
Yes. FiveSocket hosts the MT5 terminal, so you call it over HTTPS from macOS, Linux, a serverless function or any other system. The official MetaTrader5 Python package, by contrast, ships for Windows only.
Does the MT5 API work with any broker?
Any broker that offers MT5 works, and demo accounts link the same way. You link the login with the exact server name shown in your MT5 terminal. The name must match exactly.

Try it on your own account.

Link your MT5 account and try it free, no card: 24 hours or 100 calls, whichever comes first. Then a 7-day free trial, card required. Cancel anytime. The trial includes one connected MT5 account. Cancel before the trial ends and you are not charged. A demo account is the safest place to start.

7-day free trial. Paid plans start at $9.99 a month. See pricing