Broker API HubMenu

OANDA API PUT /v3/accounts/{accountID}/trades/{tradeSpecifier}/orders

PUT/v3/accounts/{accountID}/trades/{tradeSpecifier}/ordersversion v3Trades

Create, replace or cancel the orders that hang off a trade: take profit, stop loss, trailing stop loss and guaranteed stop loss. This is how a stop or limit is moved on an open trade.

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 unofficialdeveloper.oanda.comchecked

Read on OANDA's own trade endpoints page on 12 Oct 2026: method, path, parameters and the top level response fields. Each kind of dependent order has its own set of transactions in the reply, for example takeProfitOrderTransaction, stopLossOrderCancelTransaction and trailingStopLossOrderTransaction. A field left out of one of the body objects takes a default on create and is carried over on change.

Parameters

NameInTypeDescription
Accept-Datetime-FormatheaderstringOptional. RFC3339 (default) or UNIX for epoch seconds in datetime fields.
Content-TyperequiredheaderstringSend application/json on every request with a body.
accountIDrequiredpathstringAccount ID from GET /v3/accounts. Mock value shown.
tradeSpecifierrequiredpathstringTrade ID, or @ followed by your client trade ID.
takeProfitbodyobjectThe take profit to create or change. Send null to cancel the existing one. Leave it out to keep it as it is.
stopLossbodyobjectThe stop loss to create or change. Send null to cancel the existing one. Leave it out to keep it as it is.
trailingStopLossbodyobjectThe trailing stop loss to create or change. Send null to cancel the existing one. Leave it out to keep it as it is.
guaranteedStopLossbodyobjectThe guaranteed stop loss to create or change. Send null to cancel the existing one. Leave it out to keep it as it is.

Authentication headers

NameTypeDescription
AuthorizationrequiredstringSend Bearer followed by your personal access token. Placeholder only: never paste a real token into this site.

Request

Written from the method, path and parameters recorded on this page, against the demo host. 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 record marks no body field as required, so the samples send an empty JSON object with a Content-Type of application/json (in Python, passing json= sets that header). Add the fields the call needs from the parameters above before the request can succeed.

Python
# Set OANDA_TOKEN, OANDA_ACCOUNT_ID as environment variables first. Never paste real values into code.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: headers Accept-Datetime-Format; body fields takeProfit, stopLoss, trailingStopLoss, guaranteedStopLoss.
import os
import requests

BASE_URL = "https://api-fxpractice.oanda.com"  # the demo host
headers = {
    "Authorization": "Bearer " + os.environ["OANDA_TOKEN"],
    "Content-Type": "application/json",
}
body = {}
resp = requests.put(BASE_URL + "/v3/accounts/" + os.environ["OANDA_ACCOUNT_ID"] + "/trades/{tradeSpecifier}/orders", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())
JavaScript
// Set OANDA_TOKEN, OANDA_ACCOUNT_ID as environment variables first. Never paste real values into code.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Optional and not shown: headers Accept-Datetime-Format; body fields takeProfit, stopLoss, trailingStopLoss, guaranteedStopLoss.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = "https://api-fxpractice.oanda.com"; // the demo host
const res = await fetch(BASE_URL + "/v3/accounts/" + process.env.OANDA_ACCOUNT_ID + "/trades/{tradeSpecifier}/orders", {
  method: "PUT",
  headers: {
    "Authorization": "Bearer " + process.env.OANDA_TOKEN,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
curl
# Set OANDA_TOKEN, OANDA_ACCOUNT_ID as environment variables first. Never paste real values into code.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: headers Accept-Datetime-Format; body fields takeProfit, stopLoss, trailingStopLoss, guaranteedStopLoss.
curl -X PUT "https://api-fxpractice.oanda.com/v3/accounts/$OANDA_ACCOUNT_ID/trades/{tradeSpecifier}/orders" \
  -H "Authorization: Bearer $OANDA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Response

A mock response. The values are invented, so check field names against the official reference.

{
  "_mock": true,
  "stopLossOrderTransaction": {
    "id": "9016",
    "tradeID": "MOCK-T-001",
    "price": "1.09500",
    "accountID": "101-004-MOCK-001"
  },
  "relatedTransactionIDs": [
    "9016"
  ],
  "lastTransactionID": "9016"
}

Limits that apply at OANDA

LimitValueScopeSource
Headline limit120/s per IP address, HTTP 429 above itipdeveloper.oanda.comchecked

OANDA API errors you may meet

All OANDA API error codes, including 236 more not listed here.