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.
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
Also delete pending orders matching the filters (default false).
Only act on orders with this exact magic number — 0 matches manually-opened orders. Omit the field entirely for no filter.
int64Only 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.
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
Symbol name as listed by /symbols (e.g. EURUSD).
Order direction: Buy, Sell, BuyLimit, SellLimit,
BuyStop, SellStop, BuyStopLimit, SellStopLimit
(case- and separator-insensitive).
Volume in lots.
doubleHypothetical entry price (account-quote currency).
doubleResponse 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.
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
Symbol name as listed by /symbols (e.g. EURUSD).
Order direction: Buy or Sell (case-insensitive). Pending
variants are accepted but only the direction is used.
Volume in lots.
doubleHypothetical open price.
doubleHypothetical close price.
doubleResponse 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
volumefor a partial close (must respect the symbol'svolumeStep); omit or pass0for a full close. - Pending-order ticket → deletes the order.
volumeis 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.
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
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.
int64Position ticket (closes it) or pending-order ticket (deletes it).
int64Partial close volume; omit / 0 = full close. Ignored for pendings.
doubleResponse 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
stopLossandtakeProfit. - 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.
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
New expiration (date string, broker server time) — pending orders only.
New expiration in real UTC instead (ISO-8601, e.g.
2026-11-03T17:00:00Z). Not together with expiration.
New price — pending orders only.
doubleNew StopLimit price — *StopLimit pending orders only.
doubleNew SL/TP (omit to keep current). For positions only SL/TP apply.
doubledoublePosition or pending-order ticket.
int64Response 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.priceis ignored. - Pending (
*Limit/*Stop):symbol,volume,price. - StopLimit (
BuyStopLimit/SellStopLimit): additionallystopLimitPrice.
Optional fields
slippage(default 10 points),stopLoss,takeProfit,expiration(date string — absent ⇒ good-till-cancelled),comment,expertId(a.k.a.magic, also acceptsmagicNumber).clientOrderId: makes the request safe to repeat after a timeout — see the field.execution:EA(default) orManual— 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.
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
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.
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.
Magic number. Accepts expertId, magic, expertID.
int64Date string in broker server time; absent → good-till-cancelled.
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.
Buy, Sell, BuyLimit, SellLimit, BuyStop, SellStop, BuyStopLimit, SellStopLimit (case/separator-insensitive).
Required for pending orders; ignored for market orders.
doubleint64Required for *StopLimit operations.
doubledoubleSymbol to trade, e.g. EURUSD.
doubledoubleResponse 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"
}