Cancel Order
Description
Cancel an active order.
HTTP Request
DELETE /fapi/v1/order (HMAC SHA256)
Weight
1
Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | STRING | YES | Trading pair |
| orderId | LONG | NO | System order ID |
| origClientOrderId | STRING | NO | User-defined order ID |
| timestamp | LONG | YES | Timestamp |
Response Example
{
"clientOrderId": "testOrder2",
"cumQty": "0",
"cumQuote": "0",
"executedQty": "0",
"orderId": 2254222045,
"origQty": "10",
"origType": "TRAILING_STOP_MARKET",
"price": "0",
"reduceOnly": false,
"side": "SELL",
"positionSide": "BOTH",
"status": "CANCELED",
"stopPrice": "0",
"closePosition": false,
"symbol": "BTCUSDT",
"timeInForce": "GTC",
"type": "TRAILING_STOP_MARKET",
"activatePrice": "9020",
"priceRate": "0.3",
"updateTime": 1566818724722,
"workingType": "CONTRACT_PRICE",
"priceProtect": false
}
Either orderId or origClientOrderId must be sent.
Notes
- Cancelling a parent order cascade-cancels its TP/SL trigger orders
(
trigger_orders). The trigger orders' rows transition tocancelledin the same transaction. - Frozen margin attributable to the cancelled order is released to
available_balance. - Cancelling a
trigger_orderdirectly via this endpoint is also supported — pass the trigger order'sorderId. The four possible failure modes (already triggered, already cancelled, parent position closed, not owned by caller) are surfaced through distinct error codes so frontends can render appropriate messages.
Code Examples
cURL
API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
QUERY_STRING="symbol=BTCUSDT&orderId=2254222045×tamp=${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-sepolia.ztdx.io/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.ztdx.io"
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": "2254222045"
})
print(resp.json())