mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-09 16:28:06 +00:00
Compare commits
1
Commits
dev
...
fix/paradex-size
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73d34434b0 |
@@ -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(
|
||||||
|
|||||||
@@ -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",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user