1. [Home](https://fxapis.com/)
2. /
3. MT5 API

MT5 API · MetaTrader 5 REST API

# The MT5 API: trade MetaTrader 5 from your own code.

MetaQuotes does not publish a REST API for trading accounts. This page explains what an “MT5 API” really is, the four ways to get one, what separates a good one from a risky one — and how fxapis does it.

[Get API key ](https://fxapis.com/sign-up)[Quickstart](https://docs.fxapis.com/quickstart)

cURL

```
# 1. Connect an account (once). The password is encrypted on arrival.
curl -X POST https://api.fxapis.com/v1/accounts \
  -H "Authorization: Bearer $FXAPIS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "login": "81234567",
    "server": "Exness-MT5Trial7",
    "password": "trading-password",
    "mode": "warm_on_demand"
  }'

# 2. Place a market order on it.
curl -X POST https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/orders/market \
  -H "Authorization: Bearer $FXAPIS_KEY" \
  -H "Idempotency-Key: 7f3e0c9a-order-1" \
  -H "Content-Type: application/json" \
  -d '{ "symbol": "EURUSD", "side": "buy", "volume": "0.10" }'
```

On this page

1. [What an MT5 API is](#what-is)
2. [Four ways to get one](#four-ways)
3. [What to look for](#look-for)
4. [How fxapis works](#fxapis)
5. [Endpoints at a glance](#endpoints)
6. [What fxapis does not do](#not-yet)
7. [FAQ](#faq)

The basics

## What is an MT5 API?

MetaTrader 5 is a client–server platform. A broker runs the MetaTrader 5 trade server; traders reach it through the MetaTrader 5 terminal — on the desktop, on a phone or in a browser — signed in with three things: an account number, a password and the name of the broker's server. Every order a trader places travels from a terminal to that trade server.

MetaQuotes gives developers two official ways in from the trader's side. **MQL5** is the language for programs that run *inside* the terminal — Expert Advisors, indicators and scripts. The<!-- --> **MetaTrader5 Python package** lets a Python program on the same Windows computer drive a running terminal. Brokers get separate interfaces for their own servers. What does not exist is an official web API: a URL your backend can call to trade an account from anywhere.

So when developers search for an **MT5 API** or a **MetaTrader 5 REST API**, they mean something that sits between their code and a terminal. It accepts requests — place this order, list these positions, show this history — and turns each one into the matching action in a terminal signed in to the account. The practical questions are who runs those terminals, how many of them, and how carefully the layer in between treats your money when something goes wrong.

Your options

## Four ways to get an MT5 API

Each of these is a real option, and the right one depends on how many accounts you trade, whose accounts they are, and how much infrastructure you want to run.

### 1. The official MetaTrader5 Python package

MetaQuotes publishes a free, MIT-licensed [MetaTrader5 package](https://pypi.org/project/MetaTrader5/) on PyPI. It talks to a MetaTrader 5 terminal through inter-process communication ([documentation](https://www.mql5.com/en/docs/python_metatrader5)):<!-- --> `initialize()` connects to a terminal and<!-- --> [starts one if needed](https://www.mql5.com/en/docs/python_metatrader5/mt5initialize_py), `login()` signs in to an account, and<!-- --> `order_send()` trades.

It is the right tool for a personal strategy or research on one account. The limits show up as soon as you build a product: the package is published for Windows only, the terminal must run on the same machine as your code, and a terminal works with one signed-in account at a time — so ten accounts means ten terminal installations. HTTP access, retries, monitoring and credential storage are yours to build.

### 2. The Manager and Server APIs, for brokers

Brokers that run their own MetaTrader 5 server can use MetaQuotes' broker interfaces — the Manager API for administration tools, the Server API for extending the trade server, and others ([MetaQuotes' broker page](https://www.metatrader5.com/en/brokers)). They manage users, groups and balances on<!-- --> *that broker's* server. If you are building a product for traders whose accounts sit at many different brokers, these are not available to you — and they are not what you need.

### 3. Bridges and Expert Advisors

The do-it-yourself route: an Expert Advisor inside a terminal opens a socket, a ZeroMQ channel or an HTTP poll, and your code talks to it. It works with any broker and gives you complete control. It also means running the terminals yourself, usually on Windows virtual servers, one per account; keeping them signed in, updated and online; and deciding what your system believes when the bridge drops halfway through an order.

### 4. Hosted MT5 APIs

A provider runs the terminals for you and exposes an API — usually REST, sometimes with streaming. You connect an account with its login, password and server, and trade it over HTTPS from any language. MetaApi, API2Trade, mtapi.io and fxapis are examples; they differ in platform support, pricing model and how they handle failures. Our<!-- --> [guide to MetaApi alternatives](https://fxapis.com/alternatives/metaapi) compares several, with sources.

The trade-off is trust: you hand the provider account credentials, and your product depends on their uptime. In exchange you run no terminals at all.

| Aspect       | Python package             | Manager / Server API         | Bridge or EA                        | Hosted API                                   |
| ------------ | -------------------------- | ---------------------------- | ----------------------------------- | -------------------------------------------- |
| Built for    | One trader's own scripts   | Brokers, on their own server | Developers who want full control    | Products that trade many accounts            |
| What you run | Windows + a terminal       | The broker's MT5 server      | Terminals + bridge, usually on VPSs | Nothing                                      |
| Accounts     | One per terminal at a time | All of that broker's         | One per terminal                    | Many, at brokers that allow password sign-in |
| Languages    | Python                     | C++ / .NET (broker tooling)  | Whatever your bridge speaks         | Any, over HTTPS                              |
| Cost shape   | Free, plus your servers    | Broker licensing             | Your servers and time               | Subscription or per-account usage            |

A summary to orient you, not a verdict: the right choice depends on who owns the accounts and how many there are.

Choosing

## What to look for in an MT5 API

Placing an order when everything works is the easy part; every option above can do it. The differences are in what happens at the edges — and in trading, the edges are where money is lost.

- **A recorded outcome for every order.** When a request times out, did the order reach the broker? An API should distinguish “never sent” (safe to retry) from “we don't know yet” (never retry) and then find out — not report a guess.
- **Idempotency keys.** Networks fail. A retried request must return the first result, not open a second position.
- **Credential handling you can explain to your users.** How passwords are encrypted, whether they are ever returned or logged, and whether they are erased when an account is disconnected.
- **Many accounts at once.** If you copy trades or run a signal service, ask how one order reaches fifty accounts and how far apart the first and last fill are.
- **History that matches the broker.** Orders are what you asked for; deals are what the broker did — including stop-outs and swaps no request of yours caused. You need both.
- **Honest numbers.** Measured latency with the method stated, and where the servers are. Your broker's location matters as much as the provider's code.
- **A pricing model that fits your usage.** Per-hour pricing suits accounts that are online occasionally; flat plans suit accounts that trade all month. Model your own numbers.
- **Access control.** Scoped keys, so a monitoring tool can read, and a risk tool can close positions without being able to open any.

fxapis

## How the fxapis MT5 API works

fxapis is a hosted MetaTrader 5 REST API. MetaTrader 5 runs on our side, hosted in the EU; you call `https://api.fxapis.com` with an API key and JSON. There is no terminal, VPS or Expert Advisor for you or your users to run.

You connect an account with its login, trading password and server, and choose how it stays online:<!-- --> **always connected** for accounts that must act instantly, **on demand** — online when you trade, offline again after <!-- -->15<!-- --> idle minutes — or **manual**, where you decide. In our measurements an account is online about <!-- -->9.6<!-- --> seconds after connecting, and an order's round trip from our servers to a London broker's trade server is <!-- -->96–110<!-- --> ms. The<!-- --> [benchmarks page](https://fxapis.com/benchmarks) explains how each number was measured.

### Connect MT5 accounts by password

Login, trading password and server, at MT5 brokers that allow password sign-in. Always connected, on demand, or manual — and prepare up to 200 accounts in one call.

### Every order type you need

Market and pending orders, partial closes, stop-loss and take-profit changes, and a margin and profit calculator.

### One order, many accounts

Multi-account orders with a volume per account and your choice of what happens to accounts that are not ready. 30 ms from first to last across 100 accounts in our benchmark against an instant broker, and every multi-account order reports its own spread.

### Outcomes never guessed

An unclear outcome is reported as unresolved and confirmed against the broker's records. Market orders, pending orders, closes and multi-account orders take an Idempotency-Key; stop changes and cancels are safe to repeat.

### Scoped API keys

Read-only keys, close-only keys (trading:reduce) and full trading keys. Live and test labels to keep configurations apart.

### Credentials handled properly

Encrypted per account on arrival, never returned or logged, erased on disconnect. Closing a position is never blocked for billing.

Python · requests

```
import os, uuid, requests

API = "https://api.fxapis.com"
fx = requests.Session()
fx.headers["Authorization"] = f"Bearer {os.environ['FXAPIS_KEY']}"

order = fx.post(
    f"{API}/v1/accounts/{account_id}/orders/market",
    headers={"Idempotency-Key": str(uuid.uuid4())},   # safe to retry
    json={
        "symbol": "EURUSD",
        "side": "buy",
        "volume": "0.10",          # decimals are strings
        "stopLoss": "1.0890",      # absolute prices
        "takeProfit": "1.1010",
    },
).json()["data"]

print(order["state"], order["filledPrice"])   # filled 1.09472

positions = fx.get(f"{API}/v1/accounts/{account_id}/positions").json()["data"]
```

Volumes and prices are strings, so no size is ever rounded by a floating-point number on the way.

### Built to be retried

Market orders, pending orders, closes and multi-account orders take an `Idempotency-Key`; stop changes and cancels are safe to repeat. Send the same request twice with the same key and you get the first answer back, with nothing placed a second time. Failures carry stable codes that say what to do: `SEND_FAILED` means nothing reached the broker and a retry is safe; `ORDER_REJECTED` carries the broker's own return code;<!-- --> `ORDER_UNRESOLVED` means do not resend — we are confirming it with the broker.

The [API reference](https://docs.fxapis.com/api-reference) shows every endpoint in <!-- -->13<!-- --> <!-- -->languages, and the [OpenAPI specification](https://api.fxapis.com/docs/json) generates a client for any other. Start with the [five-minute quickstart](https://docs.fxapis.com/quickstart), then read<!-- --> [Trading and history](https://docs.fxapis.com/trading).

Test on demo accounts

Live and test keys are labels for your configuration, not a sandbox: both reach real brokers. Build against demo accounts.

Reference

## Endpoints at a glance

The main endpoints, grouped by what they do. Full request and response shapes are in the<!-- --> [API reference](https://docs.fxapis.com/api-reference).

| Method        | Path                                            | What it does                                                          |
| ------------- | ----------------------------------------------- | --------------------------------------------------------------------- |
| Accounts      |                                                 |                                                                       |
| POST          | /v1/accounts                                    | Connect an MT5 account by login, password and server                  |
| GET           | /v1/accounts                                    | List connected accounts and their states                              |
| GET           | /v1/accounts/{id}/status                        | Cheap status, made for polling                                        |
| POST          | /v1/accounts/prepare                            | Bring up to 200 accounts online in one call                           |
| POST          | /v1/accounts/{id}/warm · cool · restart         | Bring online, take offline, or restart one account                    |
| POST          | /v1/accounts/{id}/mode                          | Always connected, on demand, or manual                                |
| POST          | /v1/accounts/{id}/disconnect                    | Take offline and erase the stored password                            |
| Trading       |                                                 |                                                                       |
| POST          | /v1/accounts/{id}/orders/market                 | Market order, with optional stop loss and take profit                 |
| POST          | /v1/accounts/{id}/orders/pending                | Limit, stop and stop-limit orders                                     |
| POST          | /v1/orders/{id}/modify · cancel                 | Change or cancel a pending order                                      |
| POST          | /v1/accounts/{id}/positions/{positionId}/close  | Close a position in full or in part (positionId = ticket)             |
| POST          | /v1/accounts/{id}/positions/{positionId}/modify | Move a position's stop loss or take profit                            |
| POST          | /v1/accounts/{id}/calculate                     | Margin or profit for a trade, before placing it                       |
| Many accounts |                                                 |                                                                       |
| POST          | /v1/execution-waves                             | One trade on many accounts, sized per account                         |
| GET           | /v1/execution-waves/{id}                        | The result for every account, and the spread                          |
| POST          | /v1/execution-waves/{id}/cancel                 | Call one off before any order has gone out                            |
| History       |                                                 |                                                                       |
| GET           | /v1/orders                                      | Every order you placed, filterable by account, state, symbol and time |
| GET           | /v1/accounts/{id}/deals                         | What the broker did, including stop-outs and swaps                    |
| GET           | /v1/accounts/{id}/positions                     | Open positions, with when they were last seen                         |
| POST          | /v1/accounts/{id}/reconcile                     | Check against the broker's records now                                |

Plainly

## What fxapis does not do

- **MT4.** MetaTrader 5 only, today.
- **A market-data feed.** No streaming prices, no tick history, and no deep candle archive. Live quotes and up to 1,000 recent bars are reads from an online account, not a data product.
- **An uptime guarantee without a contract.** Service levels are arranged on
  <!-- -->
  [Enterprise](https://fxapis.com/enterprise).
- **Signals or advice.** fxapis executes what your code sends. It has no opinion on the market.

See also [TradingView alerts to MT5](https://fxapis.com/tradingview), with no EA or VPS, and the hosted<!-- --> [MCP server](https://fxapis.com/mcp) that lets AI assistants use fxapis.

Guides

## Start building, step by step.

- [Blog post](https://fxapis.com/blog/how-to-choose-an-mt5-api)
  ### [How to choose an MT5 API](https://fxapis.com/blog/how-to-choose-an-mt5-api)
  [Twelve questions to ask before you build on an MT5 API.](https://fxapis.com/blog/how-to-choose-an-mt5-api)

  [Read](https://fxapis.com/blog/how-to-choose-an-mt5-api)
- [Blog post](https://fxapis.com/blog/mt5-api-key-vs-broker-login)
  ### [MT5 API key vs broker login](https://fxapis.com/blog/mt5-api-key-vs-broker-login)
  [What an API key, an MT5 login, a password and a server name each do.](https://fxapis.com/blog/mt5-api-key-vs-broker-login)

  [Read](https://fxapis.com/blog/mt5-api-key-vs-broker-login)
- [Blog post](https://fxapis.com/blog/mt5-api-python-sdk)
  ### [Trade MT5 from Python with the fxapis SDK](https://fxapis.com/blog/mt5-api-python-sdk)
  [pip install fxapis, connect an account and place orders that never double-fill.](https://fxapis.com/blog/mt5-api-python-sdk)

  [Read](https://fxapis.com/blog/mt5-api-python-sdk)
- [Blog post](https://fxapis.com/blog/metatrader5-python-package-vs-rest-api)
  ### [MetaTrader5 Python package vs REST API](https://fxapis.com/blog/metatrader5-python-package-vs-rest-api)
  [Windows and a running terminal, or neither: the two compared.](https://fxapis.com/blog/metatrader5-python-package-vs-rest-api)

  [Read](https://fxapis.com/blog/metatrader5-python-package-vs-rest-api)
- [Docs guide](https://docs.fxapis.com/quickstart)
  ### [Quickstart](https://docs.fxapis.com/quickstart)
  [From an API key to a filled order, in about five minutes.](https://docs.fxapis.com/quickstart)

  [Read](https://docs.fxapis.com/quickstart)
- [Docs guide](https://docs.fxapis.com/guides/python)
  ### [Python](https://docs.fxapis.com/guides/python)
  [A complete Python program that trades MT5 with no MetaTrader installed.](https://docs.fxapis.com/guides/python)

  [Read](https://docs.fxapis.com/guides/python)

FAQ

## MT5 API questions

### Is there an official MetaTrader 5 REST API?

No. MetaQuotes offers MQL5 for programs that run inside the terminal, a Python package that talks to a terminal on the same Windows computer, and separate APIs for brokers' own servers. A REST API for trading an account over the internet comes from a third party that runs the terminals for you — fxapis is one.

### Can I use an MT5 API from Linux, macOS or a serverless function?

With a hosted API, yes: it is HTTPS and JSON, so any language on any platform can call it. The official MetaTrader5 Python package only ships for Windows and needs a terminal running on the same machine.

### Can I use the fxapis MT5 API from Python?

Yes. It is a REST API, so the requests or httpx libraries are all you need, and the API reference shows every endpoint in Python and 12 other languages. You can also generate a client from the OpenAPI specification.

### What is the difference between an MT5 API and the MT5 Manager API?

An MT5 API in the usual sense trades an account the way a trader would, signed in with that account's own login. The Manager API is for brokers: it administers their own MT5 server — users, groups, balances — and is licensed to the broker running it. fxapis is a trader-side API; it works with accounts at MT5 brokers that allow password sign-in, and does not need the broker's involvement.

### Does fxapis support MT4?

Not yet. fxapis is MetaTrader 5 only today.

### Does fxapis stream prices or candles?

No stream. Live quotes are a REST poll from the account's own broker, and recent candles are up to 1,000 bars from that same terminal. There is no tick history, no deep historical archive, and no WebSocket feed. Use a data provider for charts and backtests.

### How many accounts can I connect?

Plans are priced per account: each includes some accounts and charges a little for each one beyond, up to a thousand on the largest plan; Enterprise is priced with you for more. Accounts can stay online all the time (a small monthly add-on), come online only when you trade, or be controlled by you.

### Is there a sandbox?

Keys come labelled live or test, but both reach real brokers. Use your broker's free demo accounts to build and test, then connect real-money accounts.

\>

<!-- -->

Connect. Execute. Scale.

## Place your first MT5 trade over HTTPS.

Create a workspace, issue an API key, connect a demo account and send an order — in about five minutes.

[Get API key](https://fxapis.com/sign-up)

<!-- -->

[ ](https://fxapis.com/sign-up)

<!-- -->

[Quickstart](https://docs.fxapis.com/quickstart)
