Skip to main content
POST
/
api
/
v1
/
trading
/
cancel_order
Cancel Order
curl --request POST \
  --url https://api.example.com/api/v1/trading/cancel_order \
  --header 'Content-Type: application/json' \
  --data '
{
  "order_id": "<string>"
}
'
{
  "status": "<string>",
  "data": {
    "order_id": "<string>",
    "position_id": "<string>",
    "exchange": "<string>",
    "symbol": "<string>",
    "side": "<string>",
    "type": "<string>",
    "amount": "<string>",
    "price": "<string>",
    "status": "<string>",
    "created_at": "<string>",
    "updated_at": "<string>"
  },
  "error": "<string>"
}
Cancel an open order by its order ID. This endpoint validates that the order exists and is in an OPEN state before cancellation. When an order is successfully canceled, the associated position is also closed.

Request Body

order_id
string
required
Unique identifier of the order to cancel. Must match an existing order in OPEN status.Format: ord-YYYYMMDDHHMMSS-sequenceExample: "ord-20260303120000-1"

Response

status
string
Response status: "success" or "error"
data
OrderRecord
Updated order details after cancellation

Error Responses

error
string
Error message describing the failure reason

Status Codes

  • 200 OK: Order successfully canceled
  • 400 Bad Request: Invalid request payload
  • 404 Not Found: Order with specified ID does not exist
  • 409 Conflict: Order is not in OPEN state (already canceled, filled, or closed)

Order State Validation

The endpoint enforces strict state validation:
  1. Order exists: The order_id must match an existing order in the database
  2. Order is open: Only orders with status OPEN can be canceled
  3. Position closure: When an order is canceled, the associated position status is updated to CLOSED
Orders that have already been filled, canceled, or closed cannot be canceled again. The endpoint will return a 409 Conflict error with message "order is not open".

Example Request

curl -X POST https://api.neuratrade.com/api/v1/trading/cancel_order \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "order_id": "ord-20260303120000-1"
  }'

Example Responses

200 Success
{
  "status": "success",
  "data": {
    "order_id": "ord-20260303120000-1",
    "position_id": "pos-20260303120000-1",
    "exchange": "binance",
    "symbol": "BTC/USDT",
    "side": "BUY",
    "type": "LIMIT",
    "amount": "0.01",
    "price": "50000.00",
    "status": "CANCELED",
    "created_at": "2026-03-03T12:00:00Z",
    "updated_at": "2026-03-03T12:05:00Z"
  }
}
404 Order Not Found
{
  "status": "error",
  "error": "order not found"
}
409 Order Not Open
{
  "status": "error",
  "error": "order is not open"
}
400 Invalid Payload
{
  "status": "error",
  "error": "invalid request payload"
}

Build docs developers (and LLMs) love