mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
feat: 优化平仓逻辑,确保正确处理订单数量并提示交易所关闭整个仓位
This commit is contained in:
@@ -338,12 +338,16 @@ export async function marketClose(
|
|||||||
if (isOperating(locks, type)) return;
|
if (isOperating(locks, type)) return;
|
||||||
if (!enforceMarkPriceGuard(side, guard?.expectedPrice ?? null, guard, log, "市价平仓")) return;
|
if (!enforceMarkPriceGuard(side, guard?.expectedPrice ?? null, guard, log, "市价平仓")) return;
|
||||||
const qtyStep = opts?.qtyStep ?? 0.001;
|
const qtyStep = opts?.qtyStep ?? 0.001;
|
||||||
|
const roundedQty = roundQtyDownToStep(quantity, qtyStep);
|
||||||
|
const safeQty = roundedQty > 0 ? roundedQty : quantity;
|
||||||
const params: CreateOrderParams = {
|
const params: CreateOrderParams = {
|
||||||
symbol,
|
symbol,
|
||||||
side,
|
side,
|
||||||
type,
|
type,
|
||||||
quantity: roundQtyDownToStep(quantity, qtyStep),
|
quantity: safeQty,
|
||||||
reduceOnly: "true",
|
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);
|
await deduplicateOrders(adapter, symbol, openOrders, locks, timers, pendings, type, side, log);
|
||||||
lockOperating(locks, timers, pendings, type, log);
|
lockOperating(locks, timers, pendings, type, log);
|
||||||
|
|||||||
Reference in New Issue
Block a user