Broker API HubMenu

MetaApi POST /users/current/accounts/{accountId}/calculate-margin

POST/users/current/accounts/{accountId}/calculate-marginTrade

Work out the margin that opening a given trade on the account would need, without placing it.

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.

Independent and unofficialmetaapi.cloudchecked

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 MarginOrder model, read the same day on its own page. Documented replies: 200 with the Margin model, 400 when the body is not valid, 401 and 404. No mock reply is recorded.

Parameters

NameInTypeDescription
accountIdrequiredpathstringThe 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.
symbolrequiredbodystringThe order's symbol. Marked required.
typerequiredbodystringThe order type. One of: ORDER_TYPE_BUY, ORDER_TYPE_SELL. Marked required.
volumerequiredbodynumberThe order volume, greater than 0. Marked required.
openPricerequiredbodynumberThe order's open price, greater than 0. Marked required.

Authentication headers

NameTypeDescription
auth-tokenrequiredstringThe 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 4 body fields 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.
import os
import requests

BASE_URL = os.environ["METAAPI_BASE_URL"]
headers = {
    "auth-token": os.environ["METAAPI_TOKEN"],
}
body = {"symbol": "...", "type": "...", "volume": 0, "openPrice": 0}
resp = requests.post(BASE_URL + "/users/current/accounts/" + os.environ["METAAPI_ACCOUNT_ID"] + "/calculate-margin", 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.
// 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 + "/calculate-margin", {
  method: "POST",
  headers: {
    "auth-token": process.env.METAAPI_TOKEN,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"symbol": "...", "type": "...", "volume": 0, "openPrice": 0}),
});
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.
curl -X POST "$METAAPI_BASE_URL/users/current/accounts/$METAAPI_ACCOUNT_ID/calculate-margin" \
  -H "auth-token: $METAAPI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"symbol": "...", "type": "...", "volume": 0, "openPrice": 0}'

Response

No mock response is recorded for this endpoint. Where the record says why, or names the fields of the reply, it does so in the note at the top of this page. That is a statement about this record, not about what the API returns: read the shape of the reply in the official reference.

Limits that apply at MetaApi

LimitValueScopeSource
CPU credits per account5,000 CPU credits per 10 secondsPer MetaTrader account. REST and RPC calls onlymetaapi.cloudchecked
CPU credits an hour, per application18,000Per application, multiplied by the number of accounts deployed to MetaApi. REST and RPC calls only, counted in CPU credits and not in requestsmetaapi.cloudchecked
CPU credits a minute, per application6,000Per application, multiplied by the number of accounts deployed to MetaApi. REST and RPC calls only, counted in CPU credits and not in requestsmetaapi.cloudchecked
CPU credits a second, per application1,000Per application, multiplied by the number of accounts deployed to MetaApi. REST and RPC calls only, counted in CPU credits and not in requestsmetaapi.cloudchecked
Concurrent historical market data requests5Per MetaTrader account, historical market data API onlymetaapi.cloudchecked
CPU credits a second, per server2,000Per shared front end server. REST and RPC calls only, counted in CPU credits and not in requestsmetaapi.cloudchecked