fix: SL/TP挂单用Algo Order API降级

币安2025年底breaking change: STOP_MARKET/TAKE_PROFIT_MARKET
从/fapi/v1/order移到/fapi/v1/algo/order
- 先尝试传统endpoint
- 收到-4120错误码自动切换Algo Order API
- 实盘和测试网都兼容
This commit is contained in:
root 2026-03-02 10:38:30 +00:00
parent cc1b2c33c1
commit b1731f0f79

View File

@ -206,14 +206,21 @@ async def place_stop_order(session: aiohttp.ClientSession, symbol: str, side: st
"reduceOnly": "true",
}
# 测试网不支持STOP_MARKET/TAKE_PROFIT_MARKET降级为STOP/TAKE_PROFIT限价单
if TRADE_ENV == "testnet" and order_type in ("STOP_MARKET", "TAKE_PROFIT_MARKET"):
fallback_type = "STOP" if "STOP" in order_type else "TAKE_PROFIT"
params["type"] = fallback_type
params["price"] = price_str # 限价单需要price
params["timeInForce"] = "GTC"
# 先尝试传统endpoint
data, status = await binance_request(session, "POST", "/fapi/v1/order", params)
# 如果不支持(-4120)降级到Algo Order API
if status == 400 and isinstance(data, dict) and data.get("code") == -4120:
logger.info(f"[{symbol}] 传统endpoint不支持{order_type}切换Algo Order API")
algo_params = {
"symbol": symbol,
"side": side,
"type": order_type,
"stopPrice": price_str,
"quantity": qty_str,
"reduceOnly": "true",
}
data, status = await binance_request(session, "POST", "/fapi/v1/algo/order", algo_params)
if status == 200:
logger.info(f"[{symbol}] 📌 挂{order_type} {side} @ {price_str} qty={qty_str} | orderId={data.get('orderId')}")
return data, status