Docs
Trading

Close a position

POST
/v1/accounts/{id}/positions/{positionId}/close

Closes a position in whole, or partly if you send a volume.

Send an Idempotency-Key. It matters more here than on an opening order: a retried close does not close twice, it opens an opposing position, and the account ends up with exposure nobody chose.

The three failure modes are the same as for an opening order, and ORDER_UNRESOLVED means the same thing — do not resend, poll the order. An unresolved close is the case where you might believe you are flat and not be.

Authorization

apiKey
AuthorizationBearer <token>

Authorization: Bearer fx_live_<id>_<secret>.

A key is shown once, at creation. We cannot show it again or recover it for you. Keys carry an environment (live or test) in the key itself, so a test key pasted into a production config fails immediately instead of at the worst possible moment.

Scopes are per key. A key without accounts:write can read accounts and nothing else.

In: header

Path Parameters

id*string
Formatuuid
positionId*string

The broker's position ticket.

Header Parameters

idempotency-key?string

Any unique string, usually a UUID. A retry with the same key and body returns the first answer instead of placing a second order; the same key with a different body is refused.

Lengthlength <= 200

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/v1/accounts/497f6eca-6276-4993-bfeb-53cbbbba6f08/positions/string/close" \  -H "idempotency-key: 3f0c9a52-8a8e-4f7e-9b0e-6c1d2f5a7b10" \  -H "Content-Type: application/json" \  -d '{}'
{  "data": {    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",    "accountId": "3d07c219-0a88-45be-9cfc-91e9d095a1e9",    "clientOrderId": null,    "symbol": "string",    "side": "buy",    "type": "market",    "intent": "open",    "brokerPositionId": null,    "volume": null,    "stopLoss": null,    "takeProfit": null,    "state": "accepted",    "stateDetail": null,    "needsReconciliation": true,    "retcode": null,    "retcodeText": null,    "brokerOrderId": null,    "brokerDealId": null,    "filledVolume": null,    "filledPrice": null,    "sentAt": null,    "settledAt": null,    "reconciledAt": null,    "createdAt": "2019-08-24T14:15:22Z"  }}