Skip to content

fix(api/twapOrder): raise the max TWAP duration to 7 days - #198

Open
JulienKervarrec wants to merge 2 commits into
nktkas:mainfrom
JulienKervarrec:fix/twap-max-duration
Open

JulienKervarrec wants to merge 2 commits into
nktkas:mainfrom
JulienKervarrec:fix/twap-max-duration

Conversation

@JulienKervarrec

@JulienKervarrec JulienKervarrec commented Sep 17, 2026 •

Copy link
Copy Markdown

Problem

TwapOrderRequest caps twap.m at 1440 minutes:

m: v.pipe(UnsignedInteger, v.minValue(5), v.maxValue(1440)),

That is 24 hours, but the venue allows a TWAP running time of 5 minutes to 7 days (Hyperliquid docs, Trading → Order types → TWAP). Every duration between 24 hours and 7 days is therefore rejected by valibot before the request leaves the client, even though the exchange would accept it.

#194 mentions patching this exact value locally for that reason.

Change

m: v.pipe(UnsignedInteger, v.minValue(5), v.maxValue(10080)), // 5 minutes to 7 days

10080 = 7 × 24 × 60. The minimum stays at 5, which already matched the documented range. One numeric literal and a trailing comment; no type or runtime behaviour changes beyond the widened bound.

Checks

  • Added an offline test in tests/api/exchange/twapOrder.test.ts ("twapOrder: duration bounds"): the twap schema accepts m = 5, 1440, 1441 and 10080 and rejects 4 and 10081. It fails on main (m=1441 should be accepted) and passes with this change.
  • deno test -A tests/api/exchange/twapOrder.test.ts -- --offline passes; deno fmt --check and deno lint pass on both files.
  • jsr.io is unreachable from my machine, so for that run the JSR imports were mapped to local equivalents; CI remains the reference.

Part of #194.

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 nktkas#194

Signed-off-by: Julien Kervarrec <114134889+JulienKervarrec@users.noreply.github.com>
@JulienKervarrec

Copy link
Copy Markdown
Author

I checked the new bounds against the schema itself: v.safeParse on the twap entry of TwapOrderRequest accepts m = 5, 1440, 1441 and 10080, and rejects 4 and 10081.

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 <noreply@anthropic.com>

Signed-off-by: Julien Kervarrec <114134889+JulienKervarrec@users.noreply.github.com>
@JulienKervarrec

Copy link
Copy Markdown
Author

Hi @nktkas, gentle ping on this one and #199: both merge cleanly into main, with offline tests that fail on main and pass with the fix. Happy to adjust anything. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant