mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 17:28:08 +00:00
feat: 优化Paradex网关的订单金额处理逻辑,确保平仓时正确传递金额参数
This commit is contained in:
@@ -574,24 +574,20 @@ export class ParadexGateway {
|
|||||||
: (this.exchange.markets ?? {})[symbol];
|
: (this.exchange.markets ?? {})[symbol];
|
||||||
const precisionDigits = Number((market?.precision?.amount ?? market?.amountPrecision));
|
const precisionDigits = Number((market?.precision?.amount ?? market?.amountPrecision));
|
||||||
const limitMin = Number(market?.limits?.amount?.min);
|
const limitMin = Number(market?.limits?.amount?.min);
|
||||||
const minByPrecision = Number.isFinite(precisionDigits) && precisionDigits > 0
|
// Only trust explicit exchange min limit; do NOT infer 1 from precision=0
|
||||||
? Number(Math.pow(10, -precisionDigits).toFixed(Math.max(0, precisionDigits)))
|
const minAmount = Number.isFinite(limitMin) && limitMin > 0 ? limitMin : undefined;
|
||||||
: undefined;
|
|
||||||
const minAmount = Number.isFinite(limitMin) && limitMin > 0
|
|
||||||
? limitMin
|
|
||||||
: (minByPrecision ?? undefined);
|
|
||||||
|
|
||||||
// If closePosition is requested and amount is missing or too small, bump to minimum allowed
|
// If closePosition is requested and amount is missing or too small, bump to minimum allowed
|
||||||
const isClosePosition = (extraParams as any).closePosition === true;
|
const isClosePosition = (extraParams as any).closePosition === true;
|
||||||
if (isClosePosition) {
|
if (isClosePosition) {
|
||||||
const current = Number(amount);
|
const current = Number(amount);
|
||||||
if (!Number.isFinite(current) || current <= 0 || (Number.isFinite(minAmount) && current < (minAmount as number))) {
|
if (!Number.isFinite(current) || current <= 0 || (minAmount !== undefined && current < minAmount)) {
|
||||||
amount = (minAmount as number) ?? 1e-5; // sensible fallback if market data is missing
|
amount = (minAmount as number) ?? 1e-5; // fallback if market data is missing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quantize to exchange precision if helper is available
|
// 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));
|
amount = Number((this.exchange as any).amountToPrecision(symbol, amount));
|
||||||
}
|
}
|
||||||
} catch (_normalizeError) {
|
} catch (_normalizeError) {
|
||||||
@@ -599,11 +595,15 @@ export class ParadexGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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(
|
const order = (await this.exchange.createOrder(
|
||||||
symbol,
|
symbol,
|
||||||
type,
|
type,
|
||||||
side,
|
side,
|
||||||
amount,
|
amountArg,
|
||||||
price,
|
price,
|
||||||
extraParams
|
extraParams
|
||||||
)) as CcxtOrder;
|
)) as CcxtOrder;
|
||||||
|
|||||||
Reference in New Issue
Block a user