MetaTrader 4MetaTrader 5

MTsocketAPI EA

A lightweight Expert Advisor that turns your MetaTrader terminal into a REST API with WebSockets. Any language that speaks HTTP can read prices, send orders and manage your account.

Free with demo accounts. Works with any MT4 or MT5 broker.

REST API
curl "http://127.0.0.1:81/v1/quote?symbol=EURUSD"

{
  "MSG": "QUOTE",
  "SYMBOL": "EURUSD",
  "ASK": 1.03941,
  "BID": 1.03937,
  "FLAGS": 1030,
  "TIME": "2025.01.23 09:38:51.740",
  "VOLUME": 0,
  "ERROR_ID": 0,
  "ERROR_DESCRIPTION": "The operation completed successfully"
}
curl -X POST "http://127.0.0.1:81/v1/order?symbol=EURUSD&volume=0.01&type=ORDER_TYPE_BUY"

{
  "MSG": "ORDER_SEND",
  "TYPE": "ORDER_TYPE_BUY",
  "RETCODE": 10009,
  "DEAL": 3223069202,
  "ORDER": 3262274114,
  "VOLUME": 0.01,
  "PRICE": 1.04011,
  "BID": 1.04007,
  "ASK": 1.04011,
  "REQUEST_ID": 651348425,
  "RETCODE_EXTERNAL": 0,
  "ERROR_ID": 0,
  "ERROR_DESCRIPTION": "The operation completed successfully"
}
curl -X POST "http://127.0.0.1:81/v1/order/close?ticket=3267268442"

{
  "MSG": "ORDER_CLOSE",
  "TICKET": 3267268442,
  "TYPE": "FULLY_CLOSED",
  "RETCODE": 10009,
  "DEAL": 3228142867,
  "ORDER": 3267331998,
  "VOLUME": 0.01,
  "PRICE": 1.04886,
  "BID": 1.04886,
  "ASK": 1.0489,
  "REQUEST_ID": 651348438,
  "RETCODE_EXTERNAL": 0,
  "ERROR_ID": 0,
  "ERROR_DESCRIPTION": "The operation completed successfully"
}
What the EA gives you

Your terminal, as an API

Everything goes through plain HTTP requests and JSON replies, so there is nothing new to learn.

Prices

Real-time ticks and OHLC candles for your application. Build your own indicators in your preferred language.

Orders

Send market, limit and stop orders to your MT4 or MT5 account, then modify or close them, fully or partially.

Indicators

Read the values of SMA, ATR, Momentum or any custom indicator of your terminal, and use them to manage your orders.

History

Retrieve past trades and price history, apply filters, make calculations or export everything to CSV.

Economic calendar

Get the calendar events of MetaTrader 5 by date, currency or country, with actual and forecast values.

Streaming

Subscribe to ticks, candles, market depth and order events and receive them over WebSockets as they happen.

How it works

Three steps from install to first order

  1. Attach the EA to a chartInstall MTsocketAPI in your MetaTrader 4 or 5 terminal like any other Expert Advisor.
  2. It listens on TCP port 81The EA accepts HTTP requests and WebSocket connections, from the same computer or, with the Professional plan, from another one.
  3. Your program calls the APIAsk for prices, send orders or subscribe to streams. Several clients can be connected at the same time.
WITH THE EA Your programany language REST / WebSocketsTCP 81 MetaTrader terminal+ MTsocketAPI EA Broker serverMT4 / MT5

Ports 77 and 78 remain available for programs written for previous versions. Key features · Basic usage

The API at a glance

One small, predictable REST API

Every reply is JSON with an ERROR_ID and an ERROR_DESCRIPTION. The API is described with OpenAPI 3, so you can generate a client for your language.

Endpoints (MetaTrader 5)What you get
QuotesGET /v1/quoteBid, ask, volume and time of a symbol
OrdersPOST /v1/order /order/close /order/modify
GET /v1/order/list /order/info
Send, close, modify and list open and pending orders
AccountGET /v1/accountBalance, equity, margin, leverage and trading permissions
SymbolsGET /v1/symbol/list /symbol/infoThe broker's symbols and their full specification
HistoryGET /v1/history/prices /history/ticks /history/ordersCandles, ticks, deals, orders and positions between two dates
IndicatorsGET /v1/indicator/ma /indicator/atr /indicator/customMoving average, ATR and any custom indicator
CalendarGET /v1/calendarEconomic events by date, currency or country
StreamingPOST /v1/track/prices /track/ohlc /track/mbook /track/ordersStart or stop the WebSocket streams of ticks, candles, market depth and order events
TerminalGET /v1/terminalInformation about the MetaTrader terminal
Watch it

First steps in five minutes

A walk through the basic communication with the API: read data, open an order and close it.

NEW

No terminal? Use the SDK

The MTsocketAPI SDK is a native library for MetaTrader 4 and 5. Your program connects directly to your broker's MT4 or MT5 server, so there is no terminal to install, update or keep open. It is included in your subscription.

Try the EA on a demo account

Download it, attach it to a chart and make your first request in a few minutes.

Trading involves a high risk of loss. MTsocketAPI is a software tool, not investment advice: always test your programs on a demo account first. You are responsible for the orders your software sends. See the Terms of Service.

© 2020-2026 MTsocketAPI. All rights reserved.

Created with Mobirise ‌

Web Site Maker