Home › Guides

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

AreaCalls
AccountAccounts, balance and equity, open positions, pending orders, deal history
Market dataCandles on every timeframe from M1 to MN1, ticks, live quotes, the broker's symbol list and full symbol specs
TradingMarket, limit and stop orders with SL/TP as prices, pips or points; modify; close all or part; close many; cancel
Kill switchStop all trading on an account (Algo Trading off, webhook and copy trading paused), with optional close-all; resume restores it
Expert AdvisorsUpload .mq5 (compiled on the server) or .ex5, read inputs, attach, change inputs, remove, read MT5's logs
Live streamQuotes, 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:

Built for real money

Honest limits

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.

Host your MT5 in the cloud, free

Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.

Start free →
More guides

All guides · HostMT5 facts