A REST API and live stream for MetaTrader 5
Updated 2026-11-28 · HostMT5 guides
MetaTrader 5 has no REST API of its own: code talks to it through MQL5 inside the terminal, or through the Windows-only Python package. HostMT5 runs your MT5 in the cloud and puts a REST API and a WebSocket stream in front of it, so a Node.js service, a C# app or a Go bot can read prices and place orders on your own broker account.
What you can do
| Area | Calls |
|---|---|
| Account | Accounts, balance and equity, open positions, pending orders, deal history |
| Market data | Candles on every timeframe from M1 to MN1, ticks, live quotes, the broker's symbol list and full symbol specs |
| Trading | Market, limit and stop orders with SL/TP as prices, pips or points; modify; close all or part; close many; cancel |
| Kill switch | Stop all trading on an account (Algo Trading off, webhook and copy trading paused), with optional close-all; resume restores it |
| Expert Advisors | Upload .mq5 (compiled on the server) or .ex5, read inputs, attach, change inputs, remove, read MT5's logs |
| Live stream | Quotes, forming and closed candles, account and position changes, and orders, on one WebSocket |
The full list is in the docs and in the API reference (built from the OpenAPI spec).
Authentication and keys
Create a key in the dashboard under AI & API and send it as Authorization: Bearer mc_... (or X-API-Key). A Trading key can do everything; a Read only key gets data, the stream and EA logs, and any change is refused with 403. The API never accepts browser cookies, so another website can't use your logged-in session.
First calls
curl https://hostmt5.com/api/v1/accounts -H "Authorization: Bearer mc_your_key"
curl "https://hostmt5.com/api/v1/accounts/1/bars?symbol=EURUSD&timeframe=H1&count=500" \
-H "Authorization: Bearer mc_your_key"
curl https://hostmt5.com/api/v1/accounts/1/orders -H "Authorization: Bearer mc_your_key" \
-H "Content-Type: application/json" \
-d '{"symbol":"EURUSD","side":"buy","volume":0.01,"sl_pips":20,"tp_pips":40,"client_id":"signal-123"}'
Node.js (18+)
import { HostMT5 } from './hostmt5.js'; // https://hostmt5.com/sdk/hostmt5.js
const acc = new HostMT5(process.env.HOSTMT5_KEY).account(1);
const bars = await acc.bars('EURUSD', 'H1', { count: 500 });
const t = await acc.buy('EURUSD', 0.01, { sl_pips: 20, tp_pips: 40, client_id: 'signal-123' });
for await (const ev of acc.stream({ symbols: ['EURUSD'], candles: [['EURUSD', 'M5']] })) {
if (ev.type === 'candle' && ev.closed) console.log('bar closed', ev.bar);
}
C#
var http = new HttpClient { BaseAddress = new Uri("https://hostmt5.com") };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "mc_your_key");
var json = await http.GetStringAsync("/api/v1/accounts/1/bars?symbol=EURUSD&timeframe=H1&count=500");
Java, Go and PHP examples are in the docs. For anything else (Rust, Kotlin, Swift, R), import the OpenAPI spec into Postman or generate a client with openapi-generator. Python has its own guide: MT5 Python API on Mac and Linux.
The WebSocket stream
Connect to wss://hostmt5.com/api/v1/stream?account=1 with the same header, or send {"op":"auth","key":"mc_...","account":1} first from a browser. Then:
{"op":"subscribe","symbols":["EURUSD","XAUUSD"]}gives a quote on every price change, for up to 100 symbols.{"op":"candles","symbol":"EURUSD","timeframe":"M1"}sends the bar as it forms, then the finished bar once with"closed":true: the moment to run bar-close logic. Up to 20 per stream.- Account, position and order changes arrive by themselves.
{"op":"order",...}places an order on the same connection.
Built for real money
- Safe retries: the same
client_idwithin 10 minutes returns the first result instead of trading twice. - Clear errors: JSON with the broker's own reason, e.g.
Broker refused: Invalid stops. 409 means the account isn't online; 429 comes withRetry-After. A malformed request names the field, e.g.side: Input should be 'buy' or 'sell' (got 'SELL'). - Activity log: every trade call sent with a key (REST, stream or MCP) is kept with its result: filled with ticket and price, or the reason it was refused. See it under AI & API in the dashboard or with
GET /api/v1/accounts/1/activity; the last 200 per account are kept. - Limits per key: 1,200 data requests and 120 trading requests a minute, up to 10 streams per user.
- Kill switch:
POST /api/v1/accounts/1/tradingwith{"enabled": false, "close_positions": true}stops every EA, pauses the webhook and copy trading, and flattens. It survives restarts until you resume.
Honest limits
- MetaTrader 5 only. The API reaches accounts you host on HostMT5, not terminals running elsewhere.
- Requests go over the internet to your terminal, so expect network latency, not co-located speed.
- Up to 50,000 candles or 100,000 ticks per call. History goes back to the newest 500,000 bars per symbol and timeframe, as far as your broker serves them.
HostMT5 is free during its launch, API included. Create an account, or compare it with a developer platform: MetaApi alternative.
FAQ
Does MetaTrader 5 have a REST API?
Not built in. HostMT5 hosts your MT5 terminal and adds a REST API at https://hostmt5.com/api/v1 and a WebSocket stream in front of it.
Which languages are supported?
Any language that speaks HTTPS. There are clients for Python and JavaScript (Node 18+, Deno, Bun), examples for cURL, C#, Java, Go and PHP, and an OpenAPI 3 spec to generate others.
What are the rate limits?
1,200 data requests and 120 trading requests a minute per key, and up to 10 streams per user. Over the limit you get 429 with Retry-After.
Is it safe to retry an order?
Yes when you send a client_id: the same id within 10 minutes returns the first result instead of trading twice.
Can I stop all trading from the API?
Yes. POST /api/v1/accounts/{id}/trading with {"enabled": false} turns off Algo Trading for every EA and pauses the webhook and copy trading, optionally closing positions; {"enabled": true} restores it.
Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.
Start free →- A free MT5 VPS alternative: hosted MetaTrader 5, free during launch
- Do you still need an MT5 VPS?
- How to run an MT5 Expert Advisor 24/7 without your PC
- TradingView alerts to MT5 orders with a webhook
- Copy trades between MT5 accounts at different brokers
- A MetaApi alternative for traders, not only developers
- A free PineConnector alternative with MT5 hosting included
- The full MT5 terminal in your browser
- Let an AI assistant work with your MT5 account
- Use MT5 from Python on Mac, Linux or a notebook
- Let Claude or ChatGPT build and run your MT5 EA
- Download years of MT5 price history to CSV
- Moving Skynet MT5 alerts to HostMT5