Skip to main content
POST
/
api
/
v1
/
trade
/
close
Close Order
curl --request POST \
  --url https://api.example.com/api/v1/trade/close \
  --header 'Content-Type: application/json' \
  --data '
{
  "orderId": "<string>"
}
'
{
  "message": "Order closed successfully",
  "order": {
    "orderId": "ord_1234567890abcdef",
    "status": "CLOSED",
    "closePrice": 42350.75,
    "profit": 125.50
  }
}
Closes an existing open order for the authenticated user. The order is closed at the current market price and the position is settled.

Authentication

This endpoint requires authentication via JWT token in the Authorization header.
Authorization: Bearer <your_jwt_token>

Request Body

orderId
string
required
The unique identifier of the order to close. This is the orderId returned when the order was created.

Response

message
string
Success message confirming the order was closed
order
object
The closed order details
order.orderId
string
The unique identifier of the closed order
order.status
string
The final status of the order (e.g., “CLOSED”)
order.closePrice
number
The price at which the order was closed
order.profit
number
The profit or loss from the closed order

Error Responses

error
string
Error message describing what went wrong

Status Codes

  • 200 - Order closed successfully
  • 400 - Missing orderId, order not found, or order already closed
  • 401 - Unauthorized - invalid or expired token
  • 500 - Internal server error

Examples

Close an Order

curl -X POST https://api.exness.com/api/v1/trade/close \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": "ord_1234567890abcdef"
  }'
{
  "message": "Order closed successfully",
  "order": {
    "orderId": "ord_1234567890abcdef",
    "status": "CLOSED",
    "closePrice": 42350.75,
    "profit": 125.50
  }
}

Error: Missing Order ID

curl -X POST https://api.exness.com/api/v1/trade/close \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{}'
{
  "error": "Missing required parameters: orderId"
}

Error: Order Not Found

curl -X POST https://api.exness.com/api/v1/trade/close \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": "ord_nonexistent"
  }'
{
  "error": "Order not found or already closed",
  "message": "Order not found or already closed"
}

Error: Order ID Mismatch

{
  "error": "Order ID mismatch"
}

Trading Workflow

  1. Get Open Orders - Use GET /api/v1/trade/orders to see all open positions
  2. Select Order - Choose the orderId of the position you want to close
  3. Close Order - Use this endpoint to close the position at market price
  4. View Closed Orders - Use GET /api/v1/trade/close to see your trading history

Notes

  • Only the user who created the order can close it (verified via JWT token)
  • Orders are closed at the current market price
  • The close operation is processed asynchronously through a Redis stream
  • The endpoint will timeout after 5 seconds if no response is received
  • Closing an order calculates the final profit/loss based on entry and exit prices
  • Once closed, an order cannot be reopened - you would need to create a new order

Build docs developers (and LLMs) love