Skip to content
Merged
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
15 changes: 15 additions & 0 deletions src/api/info/_methods/_base/_schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,28 @@ export type TwapState = {
reduceOnly: boolean;
/** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */
side: "B" | "A";
/**
* Price at which the order is terminated; `null` when unset.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
stopPx: string | null;
/**
* Order size.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
sz: string;
/** Start time of the TWAP order (in ms since epoch). */
timestamp: number;
/** Condition that activates the order; `null` when unset. */
trigger: {
/**
* Trigger price.
* @pattern ^[0-9]+(\.[0-9]+)?$
*/
px: string;
/** Activates when the mark price is above (`true`) or below (`false`) the trigger price. */
above: boolean;
} | null;
/**
* User address.
* @pattern ^0x[a-fA-F0-9]{40}$
Expand Down
4 changes: 3 additions & 1 deletion src/api/info/_methods/twapHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export type TwapHistoryResponse = {
* - `"finished"`: Fully executed.
* - `"activated"`: Active and executing.
* - `"terminated"`: Terminated.
* - `"waitingForTrigger"`: Awaiting the trigger price.
* - `"stopped"`: Terminated by the stop price.
* - `"error"`: An error occurred.
*/
status: {
/** Status of the TWAP order. */
status: "finished" | "activated" | "terminated";
status: "finished" | "activated" | "terminated" | "waitingForTrigger" | "stopped";
} | {
/** Status of the TWAP order. */
status: "error";
Expand Down
2 changes: 1 addition & 1 deletion tests/api/exchange/_t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export async function createTWAP(
const midPx = allMids[symbol];

// Calculate order parameters
const sz = formatSize(55 / Number(midPx), szDecimals);
const sz = formatSize(110 / Number(midPx), szDecimals);

// Place TWAP order
const result = await client.twapOrder({
Expand Down
2 changes: 1 addition & 1 deletion tests/api/exchange/twapOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runTest({
const szDecimals = symbolConverter.getSzDecimals("SOL")!;
const midPx = allMids["SOL"];

const sz = formatSize(60 / parseFloat(midPx), szDecimals);
const sz = formatSize(110 / parseFloat(midPx), szDecimals);

const params: TwapOrderParameters[] = [
// b=true | r=false | t=false
Expand Down
4 changes: 3 additions & 1 deletion tests/api/info/twapHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const paramsSchema = valibotToJsonSchema(v.omit(TwapHistoryRequest, ["type"]));

runTest({
name: "twapHistory",
isTestnet: false,
codeTestFn: async (_t, client) => {
const params: TwapHistoryParameters[] = [
{ user: "0xe019d6167E7e324aEd003d94098496b6d986aB05" },
{ user: "0x03ce7863a2b62f4e227fd98605b79beb32618c76" },
{ user: "0x0132157369b0d073dd99011da1777920a025fd77" }, // trigger.above: false
];

const data = await Promise.all(params.map((p) => client.twapHistory(p)));
Expand Down
6 changes: 4 additions & 2 deletions tests/api/subscription/_t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ const OFFLINE = Deno.args.includes("--offline");
export function runTest(options: {
name: string;
mode: "api" | "rpc";
isTestnet?: boolean;
fn: (t: Deno.TestContext, client: SubscriptionClient) => Promise<void>;
}): void {
const { name, mode, fn } = options;
const { name, mode, isTestnet = true, fn } = options;

Deno.test(name, { ignore: OFFLINE }, async (t) => {
await new Promise((r) => setTimeout(r, WAIT)); // delay to avoid rate limits

// --- Preparation ------------------------------------------------

const transport = new WebSocketTransport({ url: `wss://${mode}.hyperliquid-testnet.xyz/ws`, isTestnet: true });
const domain = isTestnet ? "hyperliquid-testnet.xyz" : "hyperliquid.xyz";
const transport = new WebSocketTransport({ url: `wss://${mode}.${domain}/ws`, isTestnet });
await transport.ready();
const subsClient = new SubscriptionClient({ transport });

Expand Down
2 changes: 2 additions & 0 deletions tests/api/subscription/twapStates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ runTestWithExchange({
schemaCoverage(paramsSchema, params);
schemaCoverage(responseSchema, data, [
"#/properties/states/items/items/1/properties/side/enum/1",
"#/properties/states/items/items/1/properties/stopPx/defined",
"#/properties/states/items/items/1/properties/trigger/defined",
]);
},
});
4 changes: 4 additions & 0 deletions tests/api/subscription/userEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ runTestWithExchange({
"#/anyOf/2",
"#/anyOf/3",
"#/anyOf/4/properties/twapHistory/items/properties/state/properties/side/enum/1",
"#/anyOf/4/properties/twapHistory/items/properties/state/properties/stopPx/defined",
"#/anyOf/4/properties/twapHistory/items/properties/state/properties/trigger/defined",
"#/anyOf/4/properties/twapHistory/items/properties/status/anyOf/0/properties/status/enum/0",
"#/anyOf/4/properties/twapHistory/items/properties/status/anyOf/0/properties/status/enum/2",
"#/anyOf/4/properties/twapHistory/items/properties/status/anyOf/0/properties/status/enum/3",
"#/anyOf/4/properties/twapHistory/items/properties/status/anyOf/0/properties/status/enum/4",
"#/anyOf/4/properties/twapHistory/items/properties/status/anyOf/1",
"#/anyOf/4/properties/twapHistory/items/properties/twapId/missing",
"#/anyOf/5/properties/twapSliceFills/items/properties/fill/properties/side/enum/1",
Expand Down
8 changes: 6 additions & 2 deletions tests/api/subscription/userTwapHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ const paramsSchema = valibotToJsonSchema(v.omit(UserTwapHistoryRequest, ["type"]
runTest({
name: "userTwapHistory",
mode: "api",
isTestnet: false,
fn: async (_t, client) => {
const params: UserTwapHistoryParameters[] = [
{ user: "0x563C175E6f11582f65D6d9E360A618699DEe14a9" },
{ user: "0xe019d6167E7e324aEd003d94098496b6d986aB05" },
{ user: "0x03ce7863a2b62f4e227fd98605b79beb32618c76" }, // trigger.above: true
{ user: "0x0132157369b0d073dd99011da1777920a025fd77" }, // trigger.above: false
{ user: "0x051748895c6ed4fab50828bebe8e62e665134d23" }, // "stopped"
{ user: "0x06d5af06a3a7d29909e1cdc7a9deded2fb14ab57" }, // "error"
];

const data = await collectEventsOverTime<UserTwapHistoryEvent>(async (cb) => {
Expand All @@ -29,6 +32,7 @@ runTest({
schemaCoverage(paramsSchema, params);
schemaCoverage(responseSchema, data, [
"#/properties/isSnapshot/missing",
"#/properties/history/items/properties/twapId/missing",
]);
},
});