From 400c7ad4b7e07e075733997a8091b4b1eb7e8921 Mon Sep 17 00:00:00 2001 From: discountry Date: Wed, 8 Oct 2025 19:53:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96Paradex=E7=BD=91?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E8=AE=A2=E5=8D=95=E9=87=91=E9=A2=9D=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E6=97=B6=E6=AD=A3=E7=A1=AE=E4=BC=A0=E9=80=92=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exchanges/paradex/gateway.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/exchanges/paradex/gateway.ts b/src/exchanges/paradex/gateway.ts index be3a644..5c63594 100644 --- a/src/exchanges/paradex/gateway.ts +++ b/src/exchanges/paradex/gateway.ts @@ -574,24 +574,20 @@ export class ParadexGateway { : (this.exchange.markets ?? {})[symbol]; const precisionDigits = Number((market?.precision?.amount ?? market?.amountPrecision)); const limitMin = Number(market?.limits?.amount?.min); - const minByPrecision = Number.isFinite(precisionDigits) && precisionDigits > 0 - ? Number(Math.pow(10, -precisionDigits).toFixed(Math.max(0, precisionDigits))) - : undefined; - const minAmount = Number.isFinite(limitMin) && limitMin > 0 - ? limitMin - : (minByPrecision ?? undefined); + // Only trust explicit exchange min limit; do NOT infer 1 from precision=0 + const minAmount = Number.isFinite(limitMin) && limitMin > 0 ? limitMin : undefined; // If closePosition is requested and amount is missing or too small, bump to minimum allowed const isClosePosition = (extraParams as any).closePosition === true; if (isClosePosition) { const current = Number(amount); - if (!Number.isFinite(current) || current <= 0 || (Number.isFinite(minAmount) && current < (minAmount as number))) { - amount = (minAmount as number) ?? 1e-5; // sensible fallback if market data is missing + if (!Number.isFinite(current) || current <= 0 || (minAmount !== undefined && current < minAmount)) { + amount = (minAmount as number) ?? 1e-5; // fallback if market data is missing } } // Quantize to exchange precision if helper is available - if (typeof (this.exchange as any).amountToPrecision === "function" && Number.isFinite(Number(amount))) { + if (!isClosePosition && typeof (this.exchange as any).amountToPrecision === "function" && Number.isFinite(Number(amount))) { amount = Number((this.exchange as any).amountToPrecision(symbol, amount)); } } catch (_normalizeError) { @@ -599,11 +595,15 @@ export class ParadexGateway { } try { + const isClosePosition = (extraParams as any).closePosition === true; + // When closePosition is true, many exchanges (incl. Paradex) accept omitting amount + // and will close the entire position. Passing a larger min amount may violate reduceOnly. + const amountArg: any = isClosePosition ? undefined : amount; const order = (await this.exchange.createOrder( symbol, type, side, - amount, + amountArg, price, extraParams )) as CcxtOrder;