Skip to main content

Cancel Order

Description

Cancel an active order.

HTTP Request

DELETE /fapi/v1/order (HMAC SHA256)

Request Parameters

NameTypeRequiredDescription
symbolSTRINGYESTrading pair
orderIdSTRINGNOSystem order ID (UUID)
origClientOrderIdSTRINGNOUser-defined order ID
timestampLONGYESTimestamp

Response Example

{
"orderId": "3fa42833-9508-4061-8d80-b68563dcd521",
"symbol": "BTCUSDT",
"status": "CANCELED",
"clientOrderId": "testOrder2",
"price": "60000",
"avgPrice": "0",
"origQty": "0.01",
"executedQty": "0",
"cumQuote": "0",
"timeInForce": "GTC",
"type": "LIMIT",
"reduceOnly": false,
"side": "BUY",
"positionSide": "BOTH",
"stopPrice": "0",
"workingType": "CONTRACT_PRICE",
"priceProtect": false,
"origType": "LIMIT",
"updateTime": 1774330265238,
"time": 1774330191022
}

Either orderId or origClientOrderId must be sent.

Notes

  • Any order that is not cancellable returns -2011. This covers every variant: the order is already in a terminal state (FILLED / CANCELED / REJECTED), the trigger has already fired or expired, or the order is no longer present in the matching engine (raced with a fill). An orderId / origClientOrderId that doesn't resolve to any order returns -2013.
  • If the order is itself a trigger order (STOP* / TAKE_PROFIT* placed via POST /fapi/v1/order), the cancel is forwarded to the trigger service. There is no cascade-cancel — cancelling a regular order never cancels any other order.
  • Cancellation is not a single transaction: the matching-engine removal, the order-status update, and the margin release are separate steps.
  • Frozen margin attributable to the cancelled order's unfilled remainder is released back to the available balance.

Code Examples

cURL

API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
QUERY_STRING="symbol=BTCUSDT&orderId=3fa42833-9508-4061-8d80-b68563dcd521&timestamp=${TIMESTAMP}"
SIGNATURE=$(echo -n "${QUERY_STRING}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')

curl -s -X DELETE \
-H "X-MBX-APIKEY: ${API_KEY}" \
"https://api.prex.world/fapi/v1/order?${QUERY_STRING}&signature=${SIGNATURE}"

Python

import time, hmac, hashlib, requests

API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL = "https://api.prex.world"

def sign(params: str) -> str:
return hmac.new(API_SECRET.encode(), params.encode(), hashlib.sha256).hexdigest()

def signed_delete(path, params={}):
params["timestamp"] = int(time.time() * 1000)
qs = "&".join(f"{k}={v}" for k, v in params.items())
params["signature"] = sign(qs)
return requests.delete(f"{BASE_URL}{path}", params=params, headers={"X-MBX-APIKEY": API_KEY})

# Cancel an order by orderId
resp = signed_delete("/fapi/v1/order", params={
"symbol": "BTCUSDT",
"orderId": "3fa42833-9508-4061-8d80-b68563dcd521"
})
print(resp.json())