API v2Trading API

Trading

Margin/profit calculation and placing, modifying and closing orders.

Close every open position — the panic button.

Optionally filtered by symbol and/or magic, and optionally also deleting pending orders. Runs as ONE pass; the reply carries a per-ticket result for every attempted close/delete, plus counts. Positions opened while the pass is running are not covered — check /OpenedOrders afterwards if that matters.

POST
/CloseAll
X-API-Key<token>

Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option).

In: header

deletePending?boolean | null

Also delete pending orders matching the filters (default false).

magic?integer | null

Only act on orders with this exact magic number — 0 matches manually-opened orders. Omit the field entirely for no filter.

Formatint64
symbol?string | null

Only act on this symbol (omit = all symbols).

Response Body

curl -X POST "https://api.api2trade.com/v2/{account_id}/CloseAll" \  -H "Content-Type: application/json" \  -d '{}'
{
  "closed": 0,
  "failed": 0,
  "requested": 0,
  "results": [
    {
      "kind": "string",
      "retcode": 0,
      "retcodeDescription": "string",
      "success": true,
      "ticket": 0
    }
  ]
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}

Required margin for a hypothetical order.

Asks MT5 to compute the broker-side margin needed to open volume lots of symbol at price in the given operation direction. Returns the margin in the account currency. Does not place an order — purely a sizing/risk query.

GET
/OrderCalcMargin
X-API-Key<token>

Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option).

In: header

Query Parameters

symbolstring

Symbol name as listed by /symbols (e.g. EURUSD).

operationstring

Order direction: Buy, Sell, BuyLimit, SellLimit, BuyStop, SellStop, BuyStopLimit, SellStopLimit (case- and separator-insensitive).

volumenumber

Volume in lots.

Formatdouble
pricenumber

Hypothetical entry price (account-quote currency).

Formatdouble

Response Body

curl -X GET "https://api.api2trade.com/v2/{account_id}/OrderCalcMargin?symbol=string&operation=string&volume=0.1&price=0.1"
{
  "currency": "string",
  "margin": 0.1,
  "operation": "string",
  "price": 0.1,
  "symbol": "string",
  "volume": 0.1
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}

Projected P&L for a hypothetical open→close move.

Asks MT5 to compute the profit/loss if volume lots of symbol were opened at priceOpen and closed at priceClose in the given direction. Returns profit in account currency. Does not place an order — useful for sizing and UI.

GET
/OrderCalcProfit
X-API-Key<token>

Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option).

In: header

Query Parameters

symbolstring

Symbol name as listed by /symbols (e.g. EURUSD).

operationstring

Order direction: Buy or Sell (case-insensitive). Pending variants are accepted but only the direction is used.

volumenumber

Volume in lots.

Formatdouble
priceOpennumber

Hypothetical open price.

Formatdouble
priceClosenumber

Hypothetical close price.

Formatdouble

Response Body

curl -X GET "https://api.api2trade.com/v2/{account_id}/OrderCalcProfit?symbol=string&operation=string&volume=0.1&priceOpen=0.1&priceClose=0.1"
{
  "currency": "string",
  "operation": "string",
  "priceClose": 0.1,
  "priceOpen": 0.1,
  "profit": 0.1,
  "symbol": "string",
  "volume": 0.1
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}

Close a position or delete a pending order.

One endpoint covers both — the action is inferred from the ticket type:

  • Position ticket → closes the position. Supply volume for a partial close (must respect the symbol's volumeStep); omit or pass 0 for a full close.
  • Pending-order ticket → deletes the order. volume is ignored.

With pendingOnly: true only the second applies, also to a partly filled order (the filled part stays open). A ticket that is only a position (its order filled a moment ago) is refused with 409 MRPC_NOT_PENDING and stays open.

Inspect success/retcode on the response.

POST
/OrderClose
X-API-Key<token>

Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option).

In: header

pendingOnly?boolean | null

Only delete a pending order. A ticket whose order has filled into a position by now is left open and refused with 409 MRPC_NOT_PENDING, so a cancel that crosses a fill keeps the fill.

slippage?integer | null
Formatint64
ticketinteger

Position ticket (closes it) or pending-order ticket (deletes it).

Formatint64
volume?number | null

Partial close volume; omit / 0 = full close. Ignored for pendings.

Formatdouble

Response Body

curl -X POST "https://api.api2trade.com/v2/{account_id}/OrderClose" \  -H "Content-Type: application/json" \  -d '{    "ticket": 0  }'
{
  "ask": 0.1,
  "bid": 0.1,
  "clientOrderId": "string",
  "comment": "string",
  "deal": 0,
  "order": 0,
  "outcome": "string",
  "position": 0,
  "price": 0.1,
  "remainderTicket": 0,
  "retcode": 0,
  "retcodeDescription": "string",
  "success": true,
  "time": "string",
  "timeUtc": "string",
  "volume": 0.1
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}

Modify an existing position or pending order.

The ticket type decides what's modifiable:

  • Position ticket → only stopLoss and takeProfit.
  • Pending-order ticket → price, stopLimitPrice, expiration, stopLoss, takeProfit.

Omit a field to keep its current value. Inspect success/retcode on the response — a 200 only proves a reply arrived, not that the broker accepted the change.

POST
/OrderModify
X-API-Key<token>

Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option).

In: header

expiration?string | null

New expiration (date string, broker server time) — pending orders only.

expirationUtc?string | null

New expiration in real UTC instead (ISO-8601, e.g. 2026-11-03T17:00:00Z). Not together with expiration.

price?number | null

New price — pending orders only.

Formatdouble
stopLimitPrice?number | null

New StopLimit price — *StopLimit pending orders only.

Formatdouble
stopLoss?number | null

New SL/TP (omit to keep current). For positions only SL/TP apply.

Formatdouble
takeProfit?number | null
Formatdouble
ticketinteger

Position or pending-order ticket.

Formatint64

Response Body

curl -X POST "https://api.api2trade.com/v2/{account_id}/OrderModify" \  -H "Content-Type: application/json" \  -d '{    "ticket": 0  }'
{
  "ask": 0.1,
  "bid": 0.1,
  "clientOrderId": "string",
  "comment": "string",
  "deal": 0,
  "order": 0,
  "outcome": "string",
  "position": 0,
  "price": 0.1,
  "remainderTicket": 0,
  "retcode": 0,
  "retcodeDescription": "string",
  "success": true,
  "time": "string",
  "timeUtc": "string",
  "volume": 0.1
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}

Submit a market or pending order.

A 200 response only means MT5 answered — always inspect success and retcode to confirm the broker accepted it.

Required fields by operation

  • Market (Buy/Sell): symbol, volume. price is ignored.
  • Pending (*Limit/*Stop): symbol, volume, price.
  • StopLimit (BuyStopLimit/SellStopLimit): additionally stopLimitPrice.

Optional fields

  • slippage (default 10 points), stopLoss, takeProfit, expiration (date string — absent ⇒ good-till-cancelled), comment, expertId (a.k.a. magic, also accepts magicNumber).
  • clientOrderId: makes the request safe to repeat after a timeout — see the field.
  • execution: EA (default) or Manual — see below.

execution: "Manual" — for brokers that block expert trading. The order is entered in MetaTrader's own New Order dialog and Buy/Sell pressed there, so the broker records a manual order (ORDER_REASON_CLIENT). Market orders only (Buy/Sell, with optional stopLoss, takeProfit, comment); magic is always 0, so expertId is refused. Before the click every value is read back from the dialog; if one does not match, nothing is sent and the reply is 500 MRPC_MANUAL_NOT_SENT. The reply otherwise has the usual shape: comment is the dialog's own result line, a rejection carries the matching retcode where the text names one (else 10006). Takes about 1–3 s, during which other trade commands wait.

Returns 503 while the trading engine is not ready yet.

POST
/OrderSend
X-API-Key<token>

Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option).

In: header

clientOrderId?string | null

Your id for this order (1–64 characters). Repeating a request with the same id within 10 minutes places nothing new: it is answered with the first request's outcome (header Idempotent-Replayed: true), waiting for it if it is still being executed. Reusing an id for a different order is a 409.

comment?string | null
execution?string | null

How the order is placed: EA (default) sends it as an expert order, the normal way; Manual places it through MetaTrader's own New Order dialog, for brokers that block expert trading (tradeExpert: false on /AccountInfo, expert orders fail with retcode 10026). A Manual order is a market order (Buy/Sell) and always has magic 0; slippage does not apply.

expertId?integer | null

Magic number. Accepts expertId, magic, expertID.

Formatint64
expiration?string | null

Date string in broker server time; absent → good-till-cancelled.

expirationUtc?string | null

The expiry in real UTC instead (ISO-8601, e.g. 2026-11-03T17:00:00Z), converted with the server's current offset. Not together with expiration.

operationstring

Buy, Sell, BuyLimit, SellLimit, BuyStop, SellStop, BuyStopLimit, SellStopLimit (case/separator-insensitive).

price?number | null

Required for pending orders; ignored for market orders.

Formatdouble
slippage?integer | null
Formatint64
stopLimitPrice?number | null

Required for *StopLimit operations.

Formatdouble
stopLoss?number | null
Formatdouble
symbolstring

Symbol to trade, e.g. EURUSD.

takeProfit?number | null
Formatdouble
volumenumber
Formatdouble

Response Body

curl -X POST "https://api.api2trade.com/v2/{account_id}/OrderSend" \  -H "Content-Type: application/json" \  -d '{    "operation": "string",    "symbol": "string",    "volume": 0.1  }'
{
  "ask": 0.1,
  "bid": 0.1,
  "clientOrderId": "string",
  "comment": "string",
  "deal": 0,
  "order": 0,
  "outcome": "string",
  "position": 0,
  "price": 0.1,
  "remainderTicket": 0,
  "retcode": 0,
  "retcodeDescription": "string",
  "success": true,
  "time": "string",
  "timeUtc": "string",
  "volume": 0.1
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}
{
  "command_id": 0,
  "error": "string",
  "message": "string"
}