Skip to content

CloseTrade

Closes an existing open trade order.
Supports both full and partial closing of positions.

DELETE

https://{some_domain}/trade/close

Authorization

All requests must include a JWT token:

Authorization: <JWT_TOKEN>

The token is issued by the authentication method (/sign/in) and contains session info (login, type, expiration).

Request

Content-Type: application/json

Body Parameters

Field Type Required Description
order int Yes Trade order ID
volume int No Volume to close (in minimal lots, e.g. 100, 1000). If not set → full close
comment string No Optional user comment

⚠️ The client cannot set close_price — the server determines it automatically.

Response

Success (200)

{
  "data": "OK"
}

Error Responses

Code Error Description
400 INVALID_DATA Validation failed, missing or incorrect fields
401 PERMISSION_DENIED Access denied (wrong session type)
404 TRADE_ERROR Trade not found
500 TRADE_ERROR Failed to close trade (validation or execution)

Example

Request

DELETE https://{some_domain}/trade/close
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
{
  "order": 123456,
  "volume": 100,
  "comment": "Closing half position"
}

Examples

1
2
3
4
5
6
7
8
curl -X DELETE "https://{some_domain}/trade/close"       
-H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."       
-H "Content-Type: application/json"       
--data-raw '{
    "order": 123456,
    "volume": 100,
    "comment": "Closing half position"
  }'
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const url = "https://{some_domain}/trade/close";
const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";

async function closeTrade() {
  const resp = await fetch(url, {
    method: "DELETE",
    headers: {
      "Authorization": jwt,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      order: 123456,
      volume: 100,
      comment: "Closing half position"
    })
  });

  console.log("Status:", resp.status);
  const data = await resp.json().catch(() => ({}));
  console.log("Body:", data);
}

closeTrade().catch(console.error);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$url = "https://{some_domain}/trade/close";
$jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";

$payload = [
    "order" => 123456,
    "volume" => 100,
    "comment" => "Closing half position"
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: " . $jwt,
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($response === false) {
    $error = curl_error($ch);
    curl_close($ch);
    throw new RuntimeException("cURL error: " . $error);
}
curl_close($ch);

header("Content-Type: application/json");
echo json_encode([
    "status" => $httpCode,
    "body" => json_decode($response, true)
], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);

Response

{
  "data": "OK"
}