Broker API HubMenu

TradeLocker API DELETE /trade/positions/{positionId}

DELETE/trade/positions/{positionId}Trading

Place an order that closes one open position, in full or in part. The page says closure is not guaranteed and may not be immediate.

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 unofficialpublic-api.tradelocker.comchecked

Read on 12 Oct 2026 on TradeLocker's own reference page for this call, in the Markdown version the documentation site serves at the same address with .md on the end. That page carries the call's OpenAPI definition, headed Trading API version 2.11.0: the method, path, parameters and required marks here are that definition's. The reference names the optional header developer-api-key, while TradeLocker's getting started page calls the Developer Program key tl-developer-api-key and says it unlocks less restrictive rate limits. This record keeps the name on the reference page. The definition requires a request body and does not mark qty as required. The page says the platform first tries an immediate or cancel closing order and then a good till cancelled one, and that the positionId for a known orderId can be found through the orders history call. No mock reply is recorded.

Parameters

NameInTypeDescription
positionIdrequiredpathintegerThe identifier of the position. It is not the orderId of the order that opened it.
accNumrequiredheaderintegerThe account number that selects which of the login's accounts the call acts on. It is the accNum from GET /auth/jwt/all-accounts, not the accountId.
strategyIdquerystringA strategy label. The reference gives it no further description.
qtynot marked by the vendorbodynumberHow many lots to close. The page says 0 closes the whole position.

One field is tagged not marked by the vendor: qty. The vendor's page lists it and marks it neither required nor optional. That describes the page, not a test of what the host accepts, so the samples send it with a placeholder.

Authentication headers

NameTypeDescription
AuthorizationrequiredstringSend Bearer followed by the accessToken from POST /auth/jwt/token. The reference marks the call as secured by a bearer JWT. Placeholder only: never paste a real token into this site.
developer-api-keystringA key issued through the TradeLocker Developer Program. Optional.

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 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 vendor's page marks neither required nor optional, named in the sample's own comment. Each placeholder has to be replaced with a real value before the request can succeed.

Python
# Set TRADELOCKER_ACCESS_TOKEN, TRADELOCKER_ACC_NUM as environment variables first. Never paste real values into code.
# TRADELOCKER_ACCESS_TOKEN holds the Authorization header that POST /auth/jwt/token returns.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Not marked required or optional on the vendor's page, so sent here with a placeholder: qty. Leave out any the call does not need.
# Optional and not shown: headers developer-api-key; query parameters strategyId.
import os
import requests

BASE_URL = "https://demo.tradelocker.com/backend-api"  # the demo host
headers = {
    "Authorization": "Bearer " + os.environ["TRADELOCKER_ACCESS_TOKEN"],
    "accNum": os.environ["TRADELOCKER_ACC_NUM"],
}
body = {"qty": 0}
resp = requests.delete(BASE_URL + "/trade/positions/{positionId}", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())
JavaScript
// Set TRADELOCKER_ACCESS_TOKEN, TRADELOCKER_ACC_NUM as environment variables first. Never paste real values into code.
// TRADELOCKER_ACCESS_TOKEN holds the Authorization header that POST /auth/jwt/token returns.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Not marked required or optional on the vendor's page, so sent here with a placeholder: qty. Leave out any the call does not need.
// Optional and not shown: headers developer-api-key; query parameters strategyId.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = "https://demo.tradelocker.com/backend-api"; // the demo host
const res = await fetch(BASE_URL + "/trade/positions/{positionId}", {
  method: "DELETE",
  headers: {
    "Authorization": "Bearer " + process.env.TRADELOCKER_ACCESS_TOKEN,
    "accNum": process.env.TRADELOCKER_ACC_NUM,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"qty": 0}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
curl
# Set TRADELOCKER_ACCESS_TOKEN, TRADELOCKER_ACC_NUM as environment variables first. Never paste real values into code.
# TRADELOCKER_ACCESS_TOKEN holds the Authorization header that POST /auth/jwt/token returns.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Not marked required or optional on the vendor's page, so sent here with a placeholder: qty. Leave out any the call does not need.
# Optional and not shown: headers developer-api-key; query parameters strategyId.
curl -X DELETE "https://demo.tradelocker.com/backend-api/trade/positions/{positionId}" \
  -H "Authorization: Bearer $TRADELOCKER_ACCESS_TOKEN" \
  -H "accNum: $TRADELOCKER_ACC_NUM" \
  -H "Content-Type: application/json" \
  -d '{"qty": 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.

TradeLocker API errors you may meet

All TradeLocker API error codes.