Errors
What the API returns when something is wrong, and which failures are worth retrying.
Both halves of v2 — the Account API and each account's Trading API — answer errors in the same shape, so one handler covers both:
{
"error": "NO_SLOT_AVAILABLE",
"message": "Account limit reached — 5 of 5 in use. Upgrade your plan or contact support."
}error is a stable code worth branching on. message is written for a human and
may change; do not match on it. Trading API errors also carry a command_id —
quote it when you report a problem.
Status codes
| Status | When | Retry? |
|---|---|---|
400 | The request was malformed — a missing field, an unknown platform, a symbol the broker does not offer, a ticket that does not exist | No, fix the request |
401 | No API key, or one that is not valid | No, check the key |
403 | Authenticated, but not allowed — no free account slot | No, free a slot or upgrade |
404 | No such account, or no access to it | No |
409 | The clientOrderId was already used for a different order | No, use a new id |
429 | Too many different accounts connected on your slots recently | Yes, once the window frees up |
500 | The account could not answer this one — see the Trading API codes | Depends on the code |
503 | The connection is not answering or is still starting, or v2 is not available for your account yet | Yes, with backoff |
504 | The connection did not answer in time | On orders, depends on the code — see Timeouts on orders |
404 also means “no access”
An account you have no access to answers 404, the same as one that does not
exist.
Codes
Account API
| Code | Meaning |
|---|---|
UNAUTHORIZED | Missing or invalid API key |
INVALID_REQUEST | The body failed validation; message names the field |
NO_SLOT_AVAILABLE | Your plan's account slots are all in use |
NOT_FOUND | No such account, or no access to it |
TOO_MANY_NEW_ACCOUNTS | Connection limit reached — see below |
UNAVAILABLE | v2 cannot serve this request right now |
TIMEOUT | The connection did not answer in time |
Trading API
| Code | Status | Meaning | Retry? |
|---|---|---|---|
UNAUTHORIZED | 401 | Missing or invalid API key | No |
MRPC_VALIDATION | 400 | A parameter is missing or invalid; message names it | No |
MRPC_UNKNOWN_SYMBOL | 400 | The broker has no such symbol | No |
MRPC_UNKNOWN_TICKET | 400 | No such order or position | No |
MRPC_BAD_TIMEFRAME | 400 | The timeframe is not recognised | No |
MRPC_UNSUPPORTED | 400 | The platform cannot do this — stop-limit orders on MT4 | No |
MRPC_CLIENT_ORDER_ID_REUSED | 409 | The clientOrderId was already used for a different order | No |
MRPC_SYMBOL_NOT_QUOTING | 500 | The symbol has no price yet — prepare it with POST /SymbolSelect | Yes |
MRPC_TICKET_BUSY | 500 | Another request for this ticket is still running; nothing was sent | Yes |
MRPC_TRADE_EA_STOPPED | 500 | Trading stopped on the connection before the order was sent; nothing was executed | Yes, with backoff |
MRPC_HISTORY_UNAVAILABLE, MRPC_PRICE_HISTORY_UNAVAILABLE, MRPC_CALC_FAILED | 500 | The broker did not deliver the data | Yes, with backoff |
MRPC_INTERNAL, MRPC_UNKNOWN_COMMAND | 500 | An internal fault — report it with the command_id | No |
MRPC_TRADE_EA_NOT_READY | 503 | The connection is still starting up and does not take orders yet | Yes, with backoff |
MRPC_ABANDONED | 504 | The order never reached the broker — not executed | Yes |
MRPC_TIMEOUT | 504 | No answer in time; the request was not executed | Yes |
MRPC_TRADE_OUTCOME_UNKNOWN | 504 | The order reached the broker and no verdict came back — it may have executed | Only with the same clientOrderId |
Timeouts on orders
Order calls (/OrderSend, /OrderModify, /OrderClose) wait up to 60 seconds
for the broker. When that runs out, three 504s mean different things, so
branch on the code, never on the status alone:
MRPC_ABANDONEDandMRPC_TIMEOUT— nothing was executed. Sending the order again is safe.MRPC_TRADE_OUTCOME_UNKNOWN— the order was handed to the broker, so it may be live. Do not simply send it again. Either repeat it with the sameclientOrderId(below) — that answers with the order's real result once it is known, and never places it twice — or checkGET /OpenedOrdersandGET /OrderHistoryfirst, matching on your ownexpertId(magicin the rows) andcomment.
Retrying an order safely
Give every POST /OrderSend a clientOrderId of your own, 1–64 characters.
Within 10 minutes, a request with the same id places nothing new: it is answered
with the first request's result — waiting for it if it is still running — and
carries the header Idempotent-Replayed: true. The same id with a different
order is refused with 409 MRPC_CLIENT_ORDER_ID_REUSED. After MRPC_ABANDONED
the id is free again.
import { randomUUID } from 'node:crypto'
const ACCOUNT = 'your-account-uuid'
const BASE = `https://api.api2trade.com/v2/${ACCOUNT}`
async function placeOrder(order) {
// The body — and with it the id — stays the same on every attempt.
const body = JSON.stringify({ ...order, clientOrderId: randomUUID() })
for (let attempt = 0; attempt < 4; attempt++) {
const res = await fetch(`${BASE}/OrderSend`, {
method: 'POST',
headers: { 'X-API-Key': process.env.API2TRADE_API_KEY, 'Content-Type': 'application/json' },
body,
})
if (res.status !== 503 && res.status !== 504) return res.json()
await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt))
}
throw new Error('no answer — check /OpenedOrders before sending this order again')
}Ids are kept for 10 minutes, in the connection
A retry later than that — or after the connection itself restarted — is
treated as a new order. If you cannot retry within a few minutes, check
/OpenedOrders and /OrderHistory instead.
Check the version first
clientOrderId works from version 0.17.0 on MT5 and 0.15.0 on MT4 —
GET /status reports it as bridge.version. An older version ignores the
field, so a retry there places a second order. Connections move to the new
version when they restart; until then, reconcile before you resend.
The connection limit
Your slots cap how many accounts run at once. Separately, there is a limit on how many different accounts you may connect within a window — ten per slot per hour — so a single slot cannot be used to serve an endless series of accounts.
{
"error": "TOO_MANY_NEW_ACCOUNTS",
"message": "You have connected 10 different accounts in the last 1 hours, which is the limit for your plan. …"
}Reconnecting an account you already used is free
The limit counts distinct account numbers, not attempts. If you disconnect and reconnect the same account — after fixing a password, say — it does not count against the limit, however many times you do it.
Failures that are not HTTP errors
A connected account can be unhealthy while every request still returns 200.
This is the one thing worth building for deliberately.
A connection that has not logged in to the broker answers GET /AccountSummary
with 200 and all zeros — a balance of 0 is indistinguishable from a real
empty account unless you look at the session:
{
"status": "degraded",
"broker": { "connected": false, "server": "VTMarkets-Demo" },
"account": { "loggedIn": false, "login": 1082118 }
}So before trusting any figure, check that broker.connected and
account.loggedIn are both true. GET /status always returns 200; the
state is in the body.
An order the broker rejects is a 200 too: the call worked, the broker said no.
Check success and retcode in the body of every order call.
While an account is still starting
Connecting an account returns straight away, but the connection needs a few
minutes to start and log in. Poll the account on the Account API until
terminalStatus settles:
terminalStatus | Meaning |
|---|---|
provisioning | Starting up or logging in. Wait. |
ready | Logged in and serving |
error | It will not come up on its own — terminalLastError says why |
A rejected login is reported as soon as the broker rejects it, with the broker's own wording:
{
"terminalStatus": "error",
"terminalLastError": "VTMarkets-Demo rejected this login: Invalid account. Check account number, password and server."
}That is not worth retrying — the account number, password or server name is wrong. Fix it and connect again.