From 7bc65c2a8f11671d90cd97c57211833614d38c58 Mon Sep 17 00:00:00 2001 From: Julien Kervarrec <114134889+JulienKervarrec@users.noreply.github.com> Date: Thu, 17 Sep 2026 19:03:35 +0200 Subject: [PATCH 1/2] fix(api/twapOrder): raise the max TWAP duration to 7 days twap.m was capped at 1440 minutes (24 hours), but Hyperliquid allows a TWAP running time of 5 minutes to 7 days, so any duration above 24 hours was rejected client-side before the request was sent. Part of #194 Signed-off-by: Julien Kervarrec <114134889+JulienKervarrec@users.noreply.github.com> --- src/api/exchange/_methods/twapOrder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/exchange/_methods/twapOrder.ts b/src/api/exchange/_methods/twapOrder.ts index 695b9ed1..f2ba28f2 100644 --- a/src/api/exchange/_methods/twapOrder.ts +++ b/src/api/exchange/_methods/twapOrder.ts @@ -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(), }), From 85913a16e4bacb7ff54f3d4f0eab0e3f9c8c46a0 Mon Sep 17 00:00:00 2001 From: Julien Kervarrec <114134889+JulienKervarrec@users.noreply.github.com> Date: Fri, 25 Sep 2026 15:49:45 +0200 Subject: [PATCH 2/2] test(api/twapOrder): check the 5 minute to 7 day duration bounds Offline schema test: m = 5, 1440, 1441 and 10080 are accepted, 4 and 10081 rejected. It fails on main (m=1441) and passes with the new bound. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Julien Kervarrec <114134889+JulienKervarrec@users.noreply.github.com> --- tests/api/exchange/twapOrder.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/api/exchange/twapOrder.test.ts b/tests/api/exchange/twapOrder.test.ts index d36831e1..39f1079b 100644 --- a/tests/api/exchange/twapOrder.test.ts +++ b/tests/api/exchange/twapOrder.test.ts @@ -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"; @@ -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`); + } +});