From fc48584cca5b522a7a5aedbacf5aafa44bcd276f Mon Sep 17 00:00:00 2001 From: nktkas Date: Sat, 1 Aug 2026 22:32:11 +0300 Subject: [PATCH] feat(exchange/twapOrder): add `details` parameter Co-authored-by: Claude Opus 5 (1M context) --- src/api/exchange/_methods/twapOrder.ts | 12 ++++++++++++ tests/api/exchange/twapOrder.test.ts | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/api/exchange/_methods/twapOrder.ts b/src/api/exchange/_methods/twapOrder.ts index bae7f00d..695b9ed1 100644 --- a/src/api/exchange/_methods/twapOrder.ts +++ b/src/api/exchange/_methods/twapOrder.ts @@ -31,6 +31,18 @@ export const TwapOrderRequest = /* @__PURE__ */ (() => { /** Enable random order timing. */ t: v.boolean(), }), + /** Trigger and stop prices. */ + details: v.optional(v.object({ + /** Condition that activates the order. */ + t: v.nullable(v.object({ + /** Trigger price. */ + p: UnsignedDecimal, + /** Activate when the mark price is above (`true`) or below (`false`) the trigger price. */ + a: v.boolean(), + })), + /** Price at which the order is terminated. */ + s: v.nullable(UnsignedDecimal), + })), }), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: UnsignedInteger, diff --git a/tests/api/exchange/twapOrder.test.ts b/tests/api/exchange/twapOrder.test.ts index a881132e..d36831e1 100644 --- a/tests/api/exchange/twapOrder.test.ts +++ b/tests/api/exchange/twapOrder.test.ts @@ -1,5 +1,5 @@ import { type TwapOrderParameters, TwapOrderRequest } from "@nktkas/hyperliquid/api/exchange"; -import { formatSize } from "@nktkas/hyperliquid/utils"; +import { formatPrice, formatSize } from "@nktkas/hyperliquid/utils"; import * as v from "@valibot/valibot"; import { schemaCoverage } from "../_utils/schemaCoverage.ts"; import { typeToJsonSchema } from "../_utils/typeToJsonSchema.ts"; @@ -20,12 +20,20 @@ runTest({ const midPx = allMids["SOL"]; const sz = formatSize(110 / parseFloat(midPx), szDecimals); + const pxUp = formatPrice(parseFloat(midPx) * 1.5, szDecimals); + const pxDown = formatPrice(parseFloat(midPx) * 0.5, szDecimals); const params: TwapOrderParameters[] = [ // b=true | r=false | t=false { twap: { a: id, b: true, s: sz, r: false, m: 5, t: false } }, // b=false | t=true { twap: { a: id, b: false, s: sz, r: false, m: 5, t: true } }, + // details.t | a=true + { twap: { a: id, b: true, s: sz, r: false, m: 5, t: false }, details: { t: { p: pxUp, a: true }, s: null } }, + // details.t | a=false + { twap: { a: id, b: false, s: sz, r: false, m: 5, t: false }, details: { t: { p: pxDown, a: false }, s: null } }, + // details.s + { twap: { a: id, b: true, s: sz, r: false, m: 5, t: false }, details: { t: null, s: pxUp } }, ]; const data = await Promise.all(params.map((p) => exchClient.twapOrder(p)));