diff --git a/src/exchanges/paradex/gateway.ts b/src/exchanges/paradex/gateway.ts index 236bfd0..81578e2 100644 --- a/src/exchanges/paradex/gateway.ts +++ b/src/exchanges/paradex/gateway.ts @@ -602,7 +602,10 @@ export class ParadexGateway { // Only omit amount for MARKET close-position orders; STOP requires explicit size const shouldOmitAmount = isClosePosition && type === "market"; 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(); } const order = (await this.exchange.createOrder( diff --git a/tests/paradex-gateway.test.ts b/tests/paradex-gateway.test.ts new file mode 100644 index 0000000..51afdbe --- /dev/null +++ b/tests/paradex-gateway.test.ts @@ -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", + }); + }); +}); +