Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/exchange/_methods/twapOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const TwapOrderRequest = /* @__PURE__ */ (() => {
/** Whether the order is reduce-only. */
r: v.boolean(),
/** TWAP duration in minutes. */
m: v.pipe(UnsignedInteger, v.minValue(5), v.maxValue(1440)),
m: v.pipe(UnsignedInteger, v.minValue(5), v.maxValue(10080)), // 5 minutes to 7 days
/** Enable random order timing. */
t: v.boolean(),
}),
Expand Down
12 changes: 12 additions & 0 deletions tests/api/exchange/twapOrder.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assertEquals } from "jsr:@std/assert@1";
import { type TwapOrderParameters, TwapOrderRequest } from "@nktkas/hyperliquid/api/exchange";
import { formatPrice, formatSize } from "@nktkas/hyperliquid/utils";
import * as v from "@valibot/valibot";
Expand Down Expand Up @@ -44,3 +45,14 @@ runTest({
schemaCoverage(responseSchema, data);
},
});

Deno.test("twapOrder: duration bounds (5 minutes to 7 days)", () => {
const twapSchema = TwapOrderRequest.entries.action.entries.twap;
const twap = { a: 0, b: true, s: "1", r: false, t: false };
for (const m of [5, 1440, 1441, 10080]) {
assertEquals(v.safeParse(twapSchema, { ...twap, m }).success, true, `m=${m} should be accepted`);
}
for (const m of [4, 10081]) {
assertEquals(v.safeParse(twapSchema, { ...twap, m }).success, false, `m=${m} should be rejected`);
}
});