MT5 REST API: four ways to trade MetaTrader 5 from code

The official Python package, broker-side APIs, terminal-free cloud APIs and hosted terminals with a REST API, compared, so you can pick the one that fits your project.

MetaTrader 5 was built for code that runs inside the terminal: Expert Advisors and scripts written in MQL5. Traders who want to trade from their own application, in Python, Node or anything else that speaks HTTP, soon find that MT5 has no public REST API for a trading account.

There are four ways around that. They differ in where the terminal runs, whether your EAs can keep running next to your code, and who maintains the machine. This guide walks through each so you can pick the one that fits your project.

1. The official MetaTrader5 Python package

MetaQuotes publishes a Python package, MetaTrader5, that connects to an MT5 terminal running on the same computer. You call initialize(), then read rates and positions or send orders through the terminal.

import MetaTrader5 as mt5

mt5.initialize()
print(mt5.account_info())
mt5.shutdown()

Good for: research, backtests in pandas and scripts you run yourself.

Watch out for:

  • It is Windows only, and it talks to a terminal on the same machine. It is not a network API: your Python process and the terminal live together.
  • You run and maintain that Windows machine, and the terminal on it has to stay logged in.
  • One process works with one terminal at a time, so several accounts mean several terminals and some juggling.

2. Broker-side Web API and Manager API

MetaQuotes also licenses server-side APIs, the MT5 Manager API and the Web API, to the brokers that run MT5 servers. They create accounts, move balances and manage the platform.

Good for: brokers and prop firms building their own back office.

Not for: traders. A retail account holder does not get access to these. If a search for "MT5 API" lands you on broker documentation, this is usually what it describes.

3. Terminal-free cloud APIs

A group of services connects to your broker's MT5 servers on your behalf and gives you a REST or WebSocket API in return. Some emulate the terminal's connection, so no terminal is visible anywhere; others run connections in their own cloud. MetaApi is the best-known name in this group.

Good for: applications that need account data and order placement for many accounts without running terminals yourself.

Watch out for:

  • Ask where your Expert Advisors would run. A connection with no terminal behind it has nowhere to run an EA, so automated strategies have to move into your own code.
  • Check how symbols, order types and errors map to what MT5 itself does, because an emulated connection may not behave like the terminal in every case.

4. Hosted terminals with an API

The fourth option keeps a real MT5 terminal per account and puts an API in front of it. This is how Atlaas works: each account runs as a hosted MT5 terminal, and the REST and WebSocket API sends your requests to that terminal.

Good for: projects that want both: EAs running on the terminal, and code that trades, reads positions and streams prices from outside it.

The quick start is three requests. List your terminals, read an account, place an order:

export ATLAS_BASE_URL="https://api.atlaas.dev"
export ATLAS_API_KEY="atsk_..."

# 1. List your MT5 terminals
curl -s "$ATLAS_BASE_URL/api/external/instances" \
  -H "Authorization: Bearer $ATLAS_API_KEY"

# 2. Read balance and equity for one terminal (by MT5 login)
curl -s "$ATLAS_BASE_URL/api/external/instances/5012345/account" \
  -H "Authorization: Bearer $ATLAS_API_KEY"

# 3. Market buy 0.10 lots of EURUSD
curl -s -X POST "$ATLAS_BASE_URL/api/external/instances/5012345/orders" \
  -H "Authorization: Bearer $ATLAS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "symbol": "EURUSD", "type": "BUY", "volume": 0.10 }'

What the API covers:

  • Terminals: create one in a region, start, stop and delete.
  • Trading: market orders, pending limit, stop and stop-limit orders, stop loss and take profit changes, full and partial closes, close all by symbol.
  • Account state: balance, equity, margin, open positions and pending orders.
  • Market data: live bid and ask, symbol lists and specifications, historical candles and margin calculations.
  • Streams: ticks, candles, position updates and trade events over WebSocket.

API keys are scoped, so a key for a dashboard can read without being able to trade. Indian broker accounts (Zerodha and Dhan, by invitation) connect to the same platform.

Watch out for:

  • Calls need the terminal running and connected. A stopped terminal returns an error rather than queueing the order.
  • Some things stay inside the terminal: trailing stops, for example, belong in an EA rather than a REST call.

Side by side

ApproachA real MT5 terminalYour EAs run alongsideWho runs the machineBest for
MetaTrader5 Python packageYes, on your PCYesYouResearch and scripts
Manager API and Web APINot for tradersNot applicableThe brokerBrokers and prop firms
Terminal-free cloud APINot one you controlUsually notThe providerApps that only need account access
Hosted terminal with an APIYes, hostedYesThe providerEAs plus your own code

Which one to pick

  • Exploring an idea in Python on your own PC? Start with the official package. It is free and close to the metal.
  • Building a product for many users' accounts, with all logic in your code? A terminal-free cloud API is designed for that.
  • Running EAs and want to drive the same accounts from code, or control a fleet of terminals? A hosted terminal keeps both in one place. Atlaas hosts one terminal free with no card, and the API reference has a curl example for every endpoint.