MT5 Trading API Guide
Complete reference for placing orders, managing positions, and reading live market data from MetaTrader 5 — securely accessible from your VPS via Cloudflare Tunnel.
Architecture
Your VPS / Script
HTTP client · cURL · Python
↓ HTTPS
Cloudflare Edge
Trading API
mt5.zeroonedotsai.consulting
Orders · Positions · Account
·
Dashboard API
mt5.dotsai.cloud/api/*
Ticks · Symbols · Charts
↓ Cloudflare Tunnel
Windows Machine (MT5)
FastAPI :8000 · MetaTrader 5 · XMGlobal
Authentication
All Trading API endpoints (except
/health) require the X-API-Key header. The Dashboard API at mt5.dotsai.cloud/api/* is public (read-only).Add this header to every Trading API request:
ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M
HTTP Header
X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M
Keep your API key secret. Do not expose it in client-side code. Rotate it by updating
API_KEYS in the .env file and restarting the agent.Quick Start
Two API surfaces — use the right one for your use case:
🔒 Trading API (Authenticated)
https://mt5.zeroonedotsai.consulting
Place & cancel orders, manage positions, account info, trade history. Requires
X-API-Key.🌐 Dashboard API (Public)
http://mt5.dotsai.cloud
Live tick data, symbols, charts, tick rates from PostgreSQL. No auth required.
1
Verify connectivity from VPS
Check both APIs are reachable from your VPS:
bash
# Trading API health (no auth needed) curl https://mt5.zeroonedotsai.consulting/health # Dashboard API status curl http://mt5.dotsai.cloud/api/status
2
Check account info
Verify your API key and see your account details:
bash
curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \
https://mt5.zeroonedotsai.consulting/account
3
Place your first order
Buy 0.01 lots of EURUSD at market price:
bash
curl -X POST https://mt5.zeroonedotsai.consulting/order \
-H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \
-H "Content-Type: application/json" \
-d '{"symbol":"EURUSD","order_type":"BUY","volume":0.01}'
Trading API Endpoints
Base URL: https://mt5.zeroonedotsai.consulting · Runs on your Windows machine via Cloudflare Tunnel · All endpoints except
/health require X-API-Key
GET
/health
System health check · No auth
200 OK
json
{
"status": "ok",
"mt5_connected": true,
"uptime_seconds": 3612.4,
"version": "2.0.0"
}
bash
curl https://mt5.zeroonedotsai.consulting/health
GET
/account
Account info & balance
🔒 Auth
200 OK401 Unauthorized
json
{
"login": 400879526,
"name": "Meet Deshani",
"balance": 10250.00,
"equity": 10180.50,
"margin": 120.00,
"free_margin": 10060.50,
"margin_level": 8483.75,
"currency": "USD",
"leverage": 500,
"server": "XMGlobal-MT5 15",
"profit": -69.50,
"trade_mode": "real"
}
bash
curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \
https://mt5.zeroonedotsai.consulting/account
GET
/positions
All open positions
🔒 Auth
200 OK
json
[{
"ticket": 123456789,
"symbol": "EURUSD",
"type": "BUY",
"volume": 0.10,
"price_open": 1.08450,
"price_current": 1.08520,
"sl": 1.08200,
"tp": 1.09000,
"profit": 7.00,
"swap": -0.12,
"magic": 42,
"comment": "vps bot"
}]
bash
# All positions curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ https://mt5.zeroonedotsai.consulting/positions # Single position by ticket curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ https://mt5.zeroonedotsai.consulting/position/123456789
POST
/order
Place market or pending order
🔒 Auth
| Field | Type | Required | Description |
|---|---|---|---|
| symbol | string | required | e.g. EURUSD, BTCUSD#, GOLD.i#, OILCash# |
| order_type | enum | required | BUY · SELL · BUY_LIMIT · SELL_LIMIT · BUY_STOP · SELL_STOP |
| volume | float | required | Lot size, e.g. 0.01 |
| price | float | optional* | Required for pending orders. Auto-filled for market orders. |
| sl | float | optional | Stop loss price |
| tp | float | optional | Take profit price |
| deviation | int | optional | Max slippage in points (default: 20) |
| magic | int | optional | Magic number to tag your bot's orders (default: 0) |
| comment | string | optional | Order comment (max 31 chars) |
bash – market buy
curl -X POST https://mt5.zeroonedotsai.consulting/order \ -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ -H "Content-Type: application/json" \ -d '{ "symbol": "EURUSD", "order_type": "BUY", "volume": 0.01, "sl": 1.07500, "tp": 1.09500, "magic": 42, "comment": "vps-bot" }'
bash – buy limit
curl -X POST https://mt5.zeroonedotsai.consulting/order \ -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ -H "Content-Type: application/json" \ -d '{ "symbol": "EURUSD", "order_type": "BUY_LIMIT", "volume": 0.05, "price": 1.08100, "sl": 1.07800, "tp": 1.09000, "magic": 42 }'
200 OK
401 Unauthorized
json
{
"success": true,
"retcode": 10009,
"retcode_description": "Request completed",
"order": 987654321,
"deal": 111222333,
"volume": 0.01,
"price": 1.08462,
"comment": "vps-bot"
}
PUT
/order/{ticket}
Modify SL/TP or pending price
🔒 Auth
Works for both pending orders (modify price/SL/TP) and open positions (modify SL/TP only). Pass only the fields you want to change.
bash
# Move stop loss on open position curl -X PUT https://mt5.zeroonedotsai.consulting/order/123456789 \ -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ -H "Content-Type: application/json" \ -d '{"sl": 1.08000, "tp": 1.09500}'
DEL
/order/{ticket}
Cancel pending order
🔒 Auth
bash
curl -X DELETE \
-H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \
https://mt5.zeroonedotsai.consulting/order/987654321
DEL
/position/{ticket}
Close full position at market
🔒 Auth
bash
curl -X DELETE \
-H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \
https://mt5.zeroonedotsai.consulting/position/123456789
POST
/position/{ticket}/close_partial
Close part of a position
🔒 Auth
bash
# Close 0.05 lots of a 0.10 lot position curl -X POST https://mt5.zeroonedotsai.consulting/position/123456789/close_partial \ -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ -H "Content-Type: application/json" \ -d '{"volume": 0.05}'
GET
/history/deals
Closed deal history
🔒 Auth
| Param | Type | Default | Description |
|---|---|---|---|
| days | int | 7 | Lookback window (max 365) |
| from_date | datetime | - | UTC ISO8601, e.g. 2026-01-01T00:00:00 |
| to_date | datetime | now | UTC ISO8601 |
| symbol | string | - | Filter by symbol |
bash
# Last 30 days of EURUSD deals curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/history/deals?days=30&symbol=EURUSD" # Order history curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/history/orders?days=7"
OHLCV Candles & Raw Ticks
Supported timeframes: M1 M2 M3 M4 M5 M6 M10 M12 M15 M20 M30 H1 H2 H3 H4 H6 H8 H12 D1 W1 MN1 · All datetimes are UTC
GET
/candles/{symbol}/{timeframe}
Last N OHLCV candles
🔒 Auth
| Param | Type | Default | Description |
|---|---|---|---|
| symbol | path | — | Symbol name, e.g. EURUSD |
| timeframe | path | — | e.g. H1, M5, D1 |
| count | int | 500 | Number of candles (1–50 000) |
| start_pos | int | 0 | Offset from latest bar (0 = most recent) |
bash
# Last 3 H1 candles for EURUSD curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/candles/EURUSD/H1?count=3" # Last 200 M5 candles starting 50 bars back curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/candles/XAUUSD/M5?count=200&start_pos=50"
json – response
[
{
"time": 1773144000,
"open": 1.16504,
"high": 1.16507,
"low": 1.16192,
"close": 1.16386,
"tick_volume": 5319,
"spread": 19,
"real_volume": 0
}
]
GET
/candles/{symbol}/{timeframe}/range
OHLCV candles in date range
🔒 Auth
| Param | Type | Default | Description |
|---|---|---|---|
| from_date | datetime | — | Start (UTC ISO8601), e.g. 2026-01-01T00:00:00 |
| to_date | datetime | now | End (UTC ISO8601) |
bash
# All M5 candles for EURUSD on 2026-03-18 06:00–07:00 UTC curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/candles/EURUSD/M5/range?from_date=2026-03-18T06:00:00&to_date=2026-03-18T07:00:00"
GET
/rawticks/{symbol}
Raw ticks from a start time
🔒 Auth
| Param | Type | Default | Description |
|---|---|---|---|
| from_date | datetime | — | Start datetime (UTC) |
| count | int | 1000 | Max ticks to return (1–100 000) |
| flags | int | 7 | 1=bid, 2=ask, 4=last, 7=all |
bash
# First 500 ticks for EURUSD starting 2026-03-18T08:00:00 UTC curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/rawticks/EURUSD?from_date=2026-03-18T08:00:00&count=500"
json – response
[
{
"time_msc": 1773792001234,
"bid": 1.15401,
"ask": 1.15424,
"last": 0.0,
"volume": 0,
"flags": 3
}
]
GET
/rawticks/{symbol}/range
Raw ticks in a date range
🔒 Auth
| Param | Type | Default | Description |
|---|---|---|---|
| from_date | datetime | — | Start (UTC ISO8601) |
| to_date | datetime | now | End (UTC ISO8601) |
| flags | int | 7 | 1=bid, 2=ask, 4=last, 7=all |
bash
# All ticks for EURUSD in a 1-minute window curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/rawticks/EURUSD/range?from_date=2026-03-18T08:00:00&to_date=2026-03-18T08:01:00"
GET
/timeframes
List all supported timeframes
🔒 Auth
bash
curl -H "X-API-Key: ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" \ "https://mt5.zeroonedotsai.consulting/timeframes"
json – response
{
"timeframes": ["M1","M2","M3","M4","M5","M6","M10","M12","M15","M20","M30",
"H1","H2","H3","H4","H6","H8","H12","D1","W1","MN1"],
"note": "Pass as path param, e.g. /candles/EURUSD/H1?count=200"
}
Dashboard API Endpoints
Base URL: http://mt5.dotsai.cloud · Runs on VPS · PostgreSQL backend · No authentication required
GET
/api/status
DB health & tick stats
bash
curl http://mt5.dotsai.cloud/api/status
json – response
{
"latest_tick_ms": 1773755400000,
"total_ticks": 765432,
"symbols_active": 4,
"first_tick_ms": 1773494400000,
"is_live": true,
"server_time_ms": 1773755401234
}
GET
/api/symbols
Live prices for all tracked symbols
bash
curl http://mt5.dotsai.cloud/api/symbols
json – response
[{
"symbol": "EURUSD",
"bid": 1.15299,
"ask": 1.15318,
"spread": 0.00019,
"total_ticks": 163100,
"ticks_per_min": 5408,
"time_msc": 1773755400000
}]
GET
/api/chart/{symbol}
Last 5 min of bid/ask tick data
bash
curl http://mt5.dotsai.cloud/api/chart/EURUSD curl http://mt5.dotsai.cloud/api/chart/BTCUSD%23 curl http://mt5.dotsai.cloud/api/chart/GOLD.i%23
GET
/api/tickrate
Per-minute tick counts, last 1 hour
bash
curl http://mt5.dotsai.cloud/api/tickrate
cURL Examples from VPS
Run these directly on your VPS terminal. Set the
API_KEY variable once and reuse it across all commands.bash – full workflow
#!/bin/bash # MT5 Trading API – VPS Quick Reference API="https://mt5.zeroonedotsai.consulting" KEY="ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" H="X-API-Key: $KEY" # ── 1. Health check ────────────────────────────────────── curl "$API/health" # ── 2. Account balance ─────────────────────────────────── curl -H "$H" "$API/account" | python3 -m json.tool # ── 3. Open positions ──────────────────────────────────── curl -H "$H" "$API/positions" | python3 -m json.tool # ── 4. Place market BUY ────────────────────────────────── curl -X POST "$API/order" \ -H "$H" -H "Content-Type: application/json" \ -d '{"symbol":"EURUSD","order_type":"BUY","volume":0.01,"magic":99}' # ── 5. Close position ──────────────────────────────────── TICKET=123456789 curl -X DELETE -H "$H" "$API/position/$TICKET" # ── 6. Get deal history (last 7 days) ──────────────────── curl -H "$H" "$API/history/deals?days=7" | python3 -m json.tool
Python Examples
python – mt5_client.py
import requests BASE = "https://mt5.zeroonedotsai.consulting" KEY = "ovQvBieWKaM8ihZSHSBGI62nh6TvptaHSW31M5iCW0M" HEADERS = {"X-API-Key": KEY} def get_account(): return requests.get(f"{BASE}/account", headers=HEADERS).json() def get_positions(): return requests.get(f"{BASE}/positions", headers=HEADERS).json() def place_order(symbol, order_type, volume, sl=None, tp=None, magic=0, comment=""): payload = { "symbol": symbol, "order_type": order_type, # "BUY" | "SELL" | "BUY_LIMIT" | etc. "volume": volume, "magic": magic, "comment": comment, } if sl: payload["sl"] = sl if tp: payload["tp"] = tp return requests.post(f"{BASE}/order", json=payload, headers=HEADERS).json() def close_position(ticket): return requests.delete(f"{BASE}/position/{ticket}", headers=HEADERS).json() def modify_sltp(ticket, sl=None, tp=None): payload = {} if sl: payload["sl"] = sl if tp: payload["tp"] = tp return requests.put(f"{BASE}/order/{ticket}", json=payload, headers=HEADERS).json() # ── Example usage ────────────────────────────────────── if __name__ == "__main__": acct = get_account() print(f"Balance: {acct['balance']} {acct['currency']}") print(f"Equity: {acct['equity']}") # Buy 0.01 EURUSD with SL and TP result = place_order( symbol="EURUSD", order_type="BUY", volume=0.01, sl=1.07500, tp=1.09500, magic=42, comment="vps-bot" ) print(f"Order: {result}")