跳到主要内容

修改订单

接口描述

修改一笔活跃订单的价格和数量。底层走 撤单 + 重新挂单: 原 resting 单从订单簿移除,按新数量重新计算保证金冻结,再以同一个 orderId 重新入队(对调用方无感知)。updateTime 会刷新。已成交的 部分会保留 —— 若 quantity < executedQty,返回 -1102New quantity ... cannot be smaller than already-filled ...)拒绝。

只能修改 resting 的 LIMIT 订单。 其他任何订单类型 —— 以及不再处于 NEW / PARTIALLY_FILLED 状态的订单 —— 都会返回 -2013Order does not exist or cannot be modified.)拒绝。

HTTP请求

PUT /fapi/v1/order (HMAC SHA256)

请求参数

名称类型是否必需描述
symbolSTRINGYES交易对
orderIdSTRINGNO系统订单 ID(UUID)
origClientOrderIdSTRINGNO用户自定义订单 ID
sideENUMNO买卖方向: BUY, SELL。可选 —— 订单方向不可变;如果传了,必须与原订单方向一致,否则返回 -1102
quantityDECIMALYES新的订单总数量(必须 ≥ 已成交数量)。
priceDECIMALYES新的限价。
recvWindowLONGNO接受但被忽略 —— 服务端固定执行 ±60 秒的时间戳窗口。
timestampLONGYES时间戳

quantityprice 均为必填。orderIdorigClientOrderId 必须二选一以定位目标订单。

响应示例

{
"orderId": "3fa42833-9508-4061-8d80-b68563dcd521",
"symbol": "BTCUSDT",
"status": "NEW",
"clientOrderId": "testOrderModify1",
"price": "60000",
"avgPrice": "0",
"origQty": "0.1",
"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
}

错误码

错误码原因
-1100quantity / price 非正数或无法解析
-1102quantity 低于已成交数量,或 side 与原订单不一致
-2011订单已离开撮合引擎(在途中被成交 / 撤销)—— 无法修改
-2013订单不存在、不是 LIMIT 订单、或不处于可修改状态
-2019增量部分保证金不足

代码示例

cURL

API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
BODY='{"symbol":"BTCUSDT","orderId":"3fa42833-9508-4061-8d80-b68563dcd521","side":"BUY","quantity":"0.1","price":"60000"}'
SIGNATURE=$(echo -n "timestamp=${TIMESTAMP}${BODY}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')

curl -s -X PUT \
-H "X-MBX-APIKEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d "${BODY}" \
"https://api.prex.world/fapi/v1/order?timestamp=${TIMESTAMP}&signature=${SIGNATURE}"

Python

import time, hmac, hashlib, requests, json

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

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

def signed_put(path, body={}):
ts = int(time.time() * 1000)
qs = f"timestamp={ts}"
body_str = json.dumps(body, separators=(',', ':'))
sig = sign(qs + body_str)
return requests.put(
f"{BASE_URL}{path}?timestamp={ts}&signature={sig}",
data=body_str,
headers={"X-MBX-APIKEY": API_KEY, "Content-Type": "application/json"},
)

# Modify an existing order's quantity and price
resp = signed_put("/fapi/v1/order", body={
"symbol": "BTCUSDT",
"orderId": "3fa42833-9508-4061-8d80-b68563dcd521",
"side": "BUY",
"quantity": "0.1",
"price": "60000",
})
print(resp.json())