Skip to main content
The bot does not use the MetaTrader5 Python package. All broker communication goes through the custom HTTP API. Base URL: http://<VM_IP>:6542
Auth: Authorization: Bearer <API_TOKEN>

System

MethodEndpointDescription
GET/pingHeartbeat — returns {"status": "ok", "time": <epoch>}
GET/ping/brokerMT5→broker latency: {ping_ms, quality, connected}
GET/errorLast MT5 error code + message
GET/terminalFull terminal info (connection state, flags)
POST/terminal/initInitialize MT5 terminal connection
POST/terminal/restartForce restart MT5 terminal

Account

MethodEndpointDescription
GET/accountBalance, equity, margin, leverage, currency

Symbols

MethodEndpointDescription
GET/symbolsList all available symbols
GET/symbols/{sym}Symbol spec: digits, stops_level, contract_size
GET/symbols/{sym}/tickLatest tick: bid, ask, last, time
GET/symbols/{sym}/rates?timeframe=M15&count=250OHLCV bars (includes spread in raw points)
GET/symbols/{sym}/ticks?count=100Raw historical ticks

Positions

MethodEndpointDescription
GET/positionsAll open positions
GET/positions/{ticket}Single position by ticket
PUT/positions/{ticket}Modify SL/TP — body: {"sl": 84200.0, "tp": 85000.0}
DELETE/positions/{ticket}Close position (full or partial)

Orders

MethodEndpointDescription
GET/ordersAll active pending orders
GET/orders/{ticket}Single pending order
POST/ordersPlace order — see body below
PUT/orders/{ticket}Modify pending order price/SL/TP
DELETE/orders/{ticket}Cancel pending order

Place order — request body

{
  "symbol": "BTCUSD",
  "type": "BUY",
  "volume": 0.01,
  "sl": 84200.0,
  "tp": 85000.0,
  "comment": "NOVOSKY BUY conf=0.67"
}
type accepts "BUY" or "SELL". sl and tp are optional.

History

MethodEndpointDescription
GET/history/orders?from=&to=Historical closed/cancelled orders
GET/history/deals?from=&to=Historical deals (executions + P/L)
from and to are Unix timestamps.

Notes

Spread conversion

/rates returns spread in raw points. For BTCUSD, multiply by $0.01 to get dollar spread:
1695 raw points × $0.01 = $16.95 round-turn spread
trading.py handles this automatically — you never need to convert manually.

Response objects

HTTP helpers in trading/bot.py parse all responses into SimpleNamespace objects for attribute access:
account = api_get("/account")
print(account.balance, account.equity)

Error handling

Non-2xx responses or failed orders include a retcode field with the MT5 error code. The bot logs the error and sends a Telegram alert:
[BTCUSD ERROR] BUY order failed, retcode = 10014