全部撤单
描述
撤销调用方所有当前挂单或部分成交订单,可选择范围限定于单一市场。仅影响调用方自身的订单——同一市场上其他用户的挂单不受影响。
HTTP 请求
DELETE /spot/orders(JWT 或 API Key)
权重
0——订单接口不受按 IP 权重限制约束。撮合引擎内部设有 mpsc 积压队列;若队列溢出,本接口响应为 200 且 canceled 为空数组(见下方注意事项)。
请求参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
symbol | STRING | 可选 | 市场 id(例如 DFUSDT)。若不传,则撤销调用方在所有市场上的当前挂单。区分大小写。 |
响应示例
200 OK
{
"canceled": [
{
"id": "9f2a1c4e-5b67-4d8a-bf93-2e1f4a6c8d10",
"symbol": "DFUSDT",
"side": "buy",
"type": "limit",
"tif": "gtc",
"price": "0.5000",
"quantity": "100",
"quote_quantity": null,
"filled_qty": "0",
"avg_fill_price": "0",
"status": "canceled",
"reject_reason": null,
"created_at": 1778400000,
"updated_at": 1778400300
},
{
"id": "a1b2c3d4-1234-5678-abcd-ef0123456789",
"symbol": "DFUSDT",
"side": "sell",
"type": "limit",
"tif": "gtc",
"price": "0.6000",
"quantity": "200",
"quote_quantity": null,
"filled_qty": "50",
"avg_fill_price": "0.6000",
"status": "canceled",
"reject_reason": null,
"created_at": 1778400060,
"updated_at": 1778400300
}
]
}
| 字段 | 说明 |
|---|---|
canceled | 本次请求中被转为 canceled 状态的所有订单数组。已处于终 态(filled / canceled / rejected)的订单将被静默跳过,不包含在返回结果中。 |
status | 数组中每条记录的值始终为 canceled。参见订单状态。 |
filled_qty | 撤单前已成交的数量;部分成交订单可能不为零。 |
created_at, updated_at | UNIX 秒。updated_at 反映撤单时间。 |
注意: 当调用方无当前挂单或部分成交订单(或在指定
symbol下无任何匹配订单)时,会返回空数组({"canceled": []})——同时,当引擎命令队列已满或引擎正在重启时也会如此。这两种情况无法从响应本身区分;若你预期本应有订单被撤销,请通过GET /spot/orders核实并重试。
错误响应
| HTTP | error | 触发条件 |
|---|---|---|
503 | spot trading disabled | 该服务器已关闭现货交易。引擎队列溢出在此接口不会产生 503——而是返回 200 与空数组(见上方注意事项)。 |
完整列表:错误码。
代码示例
cURL(JWT)
JWT="your_jwt_token"
# Cancel all open orders across all markets
curl -s -X DELETE "https://api.prex.world/api/v1/spot/orders" \
-H "Authorization: Bearer ${JWT}"
# Cancel only DFUSDT orders
curl -s -X DELETE "https://api.prex.world/api/v1/spot/orders?symbol=DFUSDT" \
-H "Authorization: Bearer ${JWT}"
cURL(HMAC API Key)
API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
QUERY="symbol=DFUSDT×tamp=${TIMESTAMP}"
SIGNATURE=$(echo -n "${QUERY}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')
curl -s -X DELETE \
-H "X-MBX-APIKEY: ${API_KEY}" \
"https://api.prex.world/api/v1/spot/orders?${QUERY}&signature=${SIGNATURE}"
Python
import time, hmac, hashlib, requests
from urllib.parse import urlencode
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL = "https://api.prex.world/api/v1"
def signed_delete(path: str, params: dict = None) -> dict:
ts = int(time.time() * 1000)
qs_params = {**(params or {}), "timestamp": ts}
qs = urlencode(qs_params)
sig = hmac.new(API_SECRET.encode(), qs.encode(), hashlib.sha256).hexdigest()
r = requests.delete(
f"{BASE_URL}{path}?{qs}&signature={sig}",
headers={"X-MBX-APIKEY": API_KEY},
timeout=10,
)
r.raise_for_status()
return r.json()
# Cancel all open orders scoped to DFUSDT
result = signed_delete("/spot/orders", {"symbol": "DFUSDT"})
print(f"Canceled {len(result['canceled'])} orders")
for o in result["canceled"]:
print(f" {o['id']} {o['side']:4} {o['quantity']} @ {o['price']} filled={o['filled_qty']}")