feat: 优化平仓逻辑,确保正确处理订单数量并提示交易所关闭整个仓位

This commit is contained in:
discountry
2025-10-08 19:55:51 +08:00
parent 400c7ad4b7
commit dbe8df6934
+5 -1
View File
@@ -338,12 +338,16 @@ export async function marketClose(
if (isOperating(locks, type)) return;
if (!enforceMarkPriceGuard(side, guard?.expectedPrice ?? null, guard, log, "市价平仓")) return;
const qtyStep = opts?.qtyStep ?? 0.001;
const roundedQty = roundQtyDownToStep(quantity, qtyStep);
const safeQty = roundedQty > 0 ? roundedQty : quantity;
const params: CreateOrderParams = {
symbol,
side,
type,
quantity: roundQtyDownToStep(quantity, qtyStep),
quantity: safeQty,
reduceOnly: "true",
// Hint exchanges (like Paradex) to close the whole position and tolerate omitted size
closePosition: "true",
};
await deduplicateOrders(adapter, symbol, openOrders, locks, timers, pendings, type, side, log);
lockOperating(locks, timers, pendings, type, log);