MetaApi POST /users/current/accounts/{accountId}/trade
Send one trade command to the MetaTrader account. The actionType in the body decides what it does: open at market, place, change or cancel a pending order, or change or close a position.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
Read on 12 Oct 2026 on MetaApi's own reference page for this call. The method, path, parameters and required marks are that page's. The page writes each path parameter with a colon, as in :accountId, and this record writes it in braces. The page says the address in its example, on the host mt-client-api-v1.new-york.agiliumtrade.ai, is valid for the New York region only, and that the addresses for other regions are on MetaApi's API access page. MetaApi does not count requests against this call: its rate limiting page says REST calls draw on CPU credits, granted per application, per server and per account, and that going over is answered 429 with a recommended time to retry. The body is the MetatraderTrade model, read the same day on its own page (metaapi.cloud/docs/client/models/metatraderTrade/). The model's general table marks only actionType as required and then gives a table for each command with that command's own required fields, which the descriptions above repeat. Fields the general table leaves unmarked are recorded as not required. The mock reply uses the field names of the page's example, with its code and message for a completed request and an invented orderId. The page's examples for position commands also carry positionId.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| accountIdrequired | path | string | The MetaTrader account's id on MetaApi, shown in the web application once the account has been added, or read through the provisioning API. Marked required. |
| actionTyperequired | body | string | The command. Marked required. One of: ORDER_TYPE_SELL, ORDER_TYPE_BUY, ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP, ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT, POSITION_MODIFY, POSITION_PARTIAL, POSITION_CLOSE_ID, POSITIONS_CLOSE_SYMBOL, POSITION_CLOSE_BY, ORDER_MODIFY, ORDER_CANCEL. |
| symbol | body | string | The symbol to trade. The model marks it required for the order types and for POSITIONS_CLOSE_SYMBOL. |
| volume | body | number | The order volume. The model marks it required for the order types and for POSITION_PARTIAL. |
| openPrice | body | number | The limit or stop price. The model marks it required for pending orders and for ORDER_MODIFY. |
| stopLimitPrice | body | string | The price at which a stop limit order is placed. The model marks it required for the two stop limit types and types it as a string. |
| stopLoss | body | number | Stop loss, a price unless stopLossUnits says otherwise. |
| takeProfit | body | number | Take profit, a price unless takeProfitUnits says otherwise. |
| stopLossUnits | body | string | How stopLoss is read: an absolute price or a relative amount. Default ABSOLUTE_PRICE. One of: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_PIPS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE. |
| takeProfitUnits | body | string | How takeProfit is read, with the same kinds of value as stopLossUnits. Default ABSOLUTE_PRICE. |
| stopPriceBase | body | string | The price a relative stop loss or take profit is measured from. One of: CURRENT_PRICE, OPEN_PRICE, STOP_PRICE. |
| openPriceUnits | body | string | How openPrice is read: an absolute price or a relative amount. Default ABSOLUTE_PRICE. |
| openPriceBase | body | string | The price a relative open price is measured from. One of: CURRENT_PRICE, OPEN_PRICE, STOP_LIMIT_PRICE. |
| stopLimitPriceUnits | body | string | How stopLimitPrice is read: an absolute price or a relative amount. Default ABSOLUTE_PRICE. |
| stopLimitPriceBase | body | string | The price a relative stop limit price is measured from, for ORDER_MODIFY. One of: CURRENT_PRICE, STOP_LIMIT_PRICE. |
| trailingStopLoss | body | object | A distance trailing stop loss, in the TrailingStopLoss model. |
| orderId | body | string | The order's id. The model marks it required for ORDER_MODIFY and ORDER_CANCEL. |
| positionId | body | string | The position's id. The model marks it required for POSITION_MODIFY, POSITION_PARTIAL, POSITION_CLOSE_ID and POSITION_CLOSE_BY. |
| closeByPositionId | body | string | The opposite position used to close by. The model marks it required for POSITION_CLOSE_BY. |
| comment | body | string | A comment on the order. |
| clientId | body | string | An id of the client's own, carried onto the position, history orders and history deals that follow from the trade. |
| magic | body | number | The magic number, the id of an expert adviser. |
| slippage | body | number | Slippage in points, zero or more. Ignored when changing a position or an order and when cancelling. |
| fillingModes | body | array | The filling modes allowed, in order of preference. By default all are allowed. |
| expiration | body | object | When a pending order expires: a type, one of ORDER_TIME_GTC, ORDER_TIME_DAY, ORDER_TIME_SPECIFIED or ORDER_TIME_SPECIFIED_DAY, and a time for the types that need one. The model says MetaTrader 4 supports ORDER_TIME_SPECIFIED only. |
Authentication headers
| Name | Type | Description |
|---|---|---|
| auth-tokenrequired | string | The MetaApi authorisation token, from the MetaApi web application. Marked required. Placeholder only: never paste a real token into this site. |
Request
Written from the method, path and parameters recorded on this page. No demo host is recorded as a plain address for this API, so the samples read the base address from an environment variable. Not executed against a live or demo account. Credentials are read from environment variables on your own machine and are never entered on this site. The request builder writes these same snippets, from the same record.
This call takes a request body. The samples send it as JSON with a Content-Type of application/json (in Python, passing json= sets that header) and a placeholder for each of the 1 body field the record marks as required. Each placeholder has to be replaced with a real value before the request can succeed.
Python
# Set METAAPI_BASE_URL, METAAPI_TOKEN, METAAPI_ACCOUNT_ID as environment variables first. Never paste real values into code.
# No demo host is recorded as a plain address for this API, so the base address is read from METAAPI_BASE_URL.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: body fields symbol, volume, openPrice, stopLimitPrice, stopLoss, takeProfit, stopLossUnits, takeProfitUnits, stopPriceBase, openPriceUnits, openPriceBase, stopLimitPriceUnits, stopLimitPriceBase, trailingStopLoss, orderId, positionId, closeByPositionId, comment, clientId, magic, slippage, fillingModes, expiration.
import os
import requests
BASE_URL = os.environ["METAAPI_BASE_URL"]
headers = {
"auth-token": os.environ["METAAPI_TOKEN"],
}
body = {"actionType": "..."}
resp = requests.post(BASE_URL + "/users/current/accounts/" + os.environ["METAAPI_ACCOUNT_ID"] + "/trade", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())JavaScript
// Set METAAPI_BASE_URL, METAAPI_TOKEN, METAAPI_ACCOUNT_ID as environment variables first. Never paste real values into code.
// No demo host is recorded as a plain address for this API, so the base address is read from METAAPI_BASE_URL.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Optional and not shown: body fields symbol, volume, openPrice, stopLimitPrice, stopLoss, takeProfit, stopLossUnits, takeProfitUnits, stopPriceBase, openPriceUnits, openPriceBase, stopLimitPriceUnits, stopLimitPriceBase, trailingStopLoss, orderId, positionId, closeByPositionId, comment, clientId, magic, slippage, fillingModes, expiration.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = process.env.METAAPI_BASE_URL;
const res = await fetch(BASE_URL + "/users/current/accounts/" + process.env.METAAPI_ACCOUNT_ID + "/trade", {
method: "POST",
headers: {
"auth-token": process.env.METAAPI_TOKEN,
"Content-Type": "application/json",
},
body: JSON.stringify({"actionType": "..."}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());curl
# Set METAAPI_BASE_URL, METAAPI_TOKEN, METAAPI_ACCOUNT_ID as environment variables first. Never paste real values into code.
# No demo host is recorded as a plain address for this API, so the base address is read from METAAPI_BASE_URL.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: body fields symbol, volume, openPrice, stopLimitPrice, stopLoss, takeProfit, stopLossUnits, takeProfitUnits, stopPriceBase, openPriceUnits, openPriceBase, stopLimitPriceUnits, stopLimitPriceBase, trailingStopLoss, orderId, positionId, closeByPositionId, comment, clientId, magic, slippage, fillingModes, expiration.
curl -X POST "$METAAPI_BASE_URL/users/current/accounts/$METAAPI_ACCOUNT_ID/trade" \
-H "auth-token: $METAAPI_TOKEN" \
-H "Content-Type: application/json" \
-d '{"actionType": "..."}'Response
A mock response. The values are invented, so check field names against the official reference.
{
"_mock": true,
"numericCode": 10009,
"stringCode": "TRADE_RETCODE_DONE",
"message": "Request completed",
"orderId": "1"
}Limits that apply at MetaApi
| Limit | Value | Scope | Source |
|---|---|---|---|
| CPU credits per account | 5,000 CPU credits per 10 seconds | Per MetaTrader account. REST and RPC calls only | metaapi.cloudchecked |
| CPU credits an hour, per application | 18,000 | Per application, multiplied by the number of accounts deployed to MetaApi. REST and RPC calls only, counted in CPU credits and not in requests | metaapi.cloudchecked |
| CPU credits a minute, per application | 6,000 | Per application, multiplied by the number of accounts deployed to MetaApi. REST and RPC calls only, counted in CPU credits and not in requests | metaapi.cloudchecked |
| CPU credits a second, per application | 1,000 | Per application, multiplied by the number of accounts deployed to MetaApi. REST and RPC calls only, counted in CPU credits and not in requests | metaapi.cloudchecked |
| Concurrent historical market data requests | 5 | Per MetaTrader account, historical market data API only | metaapi.cloudchecked |
| CPU credits a second, per server | 2,000 | Per shared front end server. REST and RPC calls only, counted in CPU credits and not in requests | metaapi.cloudchecked |