Skip to content

Close Trade

Closes an existing open trade order for the authenticated client account.

DELETE

https://{some_domain}/trade/close

Authorization

All requests must include a JWT token:

Authorization: <JWT_TOKEN>

With runtime protocol v2, this close/cancellation endpoint remains available when the license lease is inactive, subject to its normal authorization and account/order checks. Risk-increasing opens and modifications are gated separately.

Copy-follower manual trading policy

For authenticated user/customer requests, an enabled copy follower's manual_trading_mode is enforced after account/order ownership checks:

  • 0 rejects all manual trade writes with HTTP 403, COPY_MANUAL_TRADING_DISABLED (Manual trading is disabled for this copy follower).
  • 1 permits writes to non-copied orders and rejects changes to copied orders with HTTP 403, COPY_COPIED_ORDER_MANUAL_FORBIDDEN (Manual changes to copied orders are disabled for this copy follower).
  • 2 permits manual writes to copied and non-copied orders.
HTTP Error Message
403 COPY_MANUAL_TRADING_DISABLED Manual trading is disabled for this copy follower
403 COPY_COPIED_ORDER_MANUAL_FORBIDDEN Manual changes to copied orders are disabled for this copy follower

This applies to opens, modifications, closes, pending-order changes, and group operations. A group operation that matches a protected copied order is rejected before any order is changed. Staff and internal requests bypass this follower policy.

Request

Content-Type: application/json

Body Parameters

Field Type Required Description
order int Yes Trade order ID
volume int No Partial close volume in minimal lots
comment string No Optional comment
expiration int64 No Optional expiration timestamp

The client cannot set close_price or close_time. They are determined by the server.

For local execution, full and partial close admission validates the live order and stores its request state atomically before acknowledging success. While that close is pending, a competing close is rejected with RET_TRADE_INCORRECT_STATE, without accepted: true. A full-close snapshot whose volume changed before admission is rejected with RET_TRADE_BAD_VOLUME. Read the remaining position and retry after the first operation settles. Acceptance is not final execution confirmation; observe trade events or queries. Dealer-routed requests retain their separate routing lifecycle.

Stop Out uses the same local order reservation. An admitted partial close is allowed to settle before Stop Out can close its remaining position; if Stop Out reserves the order first, a competing client close is rejected rather than accepted concurrently. A late partial-close result cannot reopen a finalized parent. Each realized partial closure has its own closed child record, and realized volume and P/L must not be counted twice. Response fields are unchanged.

Response

Success (200)

Field Type Description
accepted bool true when the request is accepted; not a terminal execution confirmation
order int Parent order ID
dealer_request_id uint64 Optional dealer-routing request ID, present when assigned
state int Requested state: 7 for full close, 19 for partial close
login int Target account login
symbol string Trade symbol
cmd int Trade command (0 BUY, 1 SELL)
close_volume int Requested close volume in minimal lots
{
  "accepted": true,
  "order": 123456,
  "state": 7,
  "login": 1001,
  "symbol": "EURUSD",
  "cmd": 0,
  "close_volume": 100
}

Error Responses

Code Error Description
400 INVALID_DATA Validation failed
401 PERMISSION_DENIED Missing or invalid authenticated session
403 PERMISSION_DENIED Order does not belong to the authenticated session
404 RET_* Trade was not found
4xx RET_TRADE_INCORRECT_STATE Another close is pending or the position is no longer closable
4xx RET_TRADE_BAD_VOLUME Requested volume is invalid or a full-close snapshot is stale
4xx/5xx RET_* Runtime validation or close error