Author SHA1 Message Date
discountry 73d34434b0 fix size 2026-02-04 13:25:21 +08:00
2 changed files with 60 additions and 1 deletions
+4 -1
View File
@@ -602,7 +602,10 @@ export class ParadexGateway {
// Only omit amount for MARKET close-position orders; STOP requires explicit size // Only omit amount for MARKET close-position orders; STOP requires explicit size
const shouldOmitAmount = isClosePosition && type === "market"; const shouldOmitAmount = isClosePosition && type === "market";
const amountArg: any = shouldOmitAmount ? undefined : amount; const amountArg: any = shouldOmitAmount ? undefined : amount;
if (!shouldOmitAmount && amountArg != null && extraParams.size === undefined) { // Paradex/ccxt may require `size` even when amount is omitted for closePosition MARKET orders.
if (shouldOmitAmount && amount != null && extraParams.size === undefined) {
extraParams.size = amount.toString();
} else if (!shouldOmitAmount && amountArg != null && extraParams.size === undefined) {
extraParams.size = amountArg.toString(); extraParams.size = amountArg.toString();
} }
const order = (await this.exchange.createOrder( const order = (await this.exchange.createOrder(
+56
View File
@@ -0,0 +1,56 @@
import { describe, expect, it, vi } from "vitest";
import { ParadexGateway } from "../src/exchanges/paradex/gateway";
describe("ParadexGateway createOrder", () => {
it("sets `size` for closePosition MARKET orders even when amount is omitted", async () => {
const createOrder = vi.fn(async (symbol, type, side, amount, price, params) => ({
id: "1",
symbol,
type,
side,
status: "open",
price: price ?? 0,
amount: amount ?? Number(params?.size ?? 0),
filled: 0,
stopPrice: undefined,
timestamp: Date.now(),
lastUpdateTimestamp: Date.now(),
info: {
reduceOnly: params?.reduceOnly,
closePosition: params?.closePosition,
},
}));
const gateway = new ParadexGateway({
symbol: "BTC/USDC",
displaySymbol: "BTC/USDC",
privateKey: "test",
walletAddress: "test",
logger: () => {},
usePro: false,
}) as any;
gateway.exchange = { createOrder, markets: {}, symbols: [] };
gateway.initialized = true;
gateway.marketSymbol = "BTC/USDC";
await gateway.createOrder({
symbol: "BTC/USDC",
side: "SELL",
type: "MARKET",
quantity: 1.23,
reduceOnly: "true",
closePosition: "true",
});
expect(createOrder).toHaveBeenCalledTimes(1);
const [_symbol, _type, _side, amountArg, _price, extraParams] = createOrder.mock.calls[0]!;
expect(amountArg).toBeUndefined();
expect(extraParams).toMatchObject({
closePosition: true,
reduceOnly: true,
size: "1.23",
});
});
});