@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
306 lines • 17.6 kB
TypeScript
import * as v from "valibot";
/**
* Place a TWAP order.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order
*/
export declare const TwapOrderRequest: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Action to perform. */
readonly action: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Type of action. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"twapOrder", undefined>, v.DescriptionAction<"twapOrder", "Type of action.">]>;
/** Twap parameters. */
readonly twap: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Asset ID. */
readonly a: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "Asset ID.">]>;
/** Position side (`true` for long, `false` for short). */
readonly b: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Position side (`true` for long, `false` for short).">]>;
/** Size (in base currency units). */
readonly s: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, string>, v.StringSchema<undefined>, v.TransformAction<string, string>, v.RegexAction<string, undefined>]>, v.DescriptionAction<string, "Size (in base currency units).">]>;
/** Is reduce-only? */
readonly r: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Is reduce-only?">]>;
/** TWAP duration in minutes. */
readonly m: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "TWAP duration in minutes.">]>;
/** Enable random order timing. */
readonly t: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Enable random order timing.">]>;
}, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
}, "Twap parameters.">]>;
}, undefined>, v.DescriptionAction<{
type: "twapOrder";
twap: {
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
};
}, "Action to perform.">]>;
/** Nonce (timestamp in ms) used to prevent replay attacks. */
readonly nonce: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "Nonce (timestamp in ms) used to prevent replay attacks.">]>;
/** ECDSA signature components. */
readonly signature: v.SchemaWithPipe<readonly [v.ObjectSchema<{
readonly r: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, `0x${string}`>]>, v.LengthAction<`0x${string}`, 66, undefined>]>, v.DescriptionAction<`0x${string}`, "First 32-byte component.">]>;
readonly s: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, `0x${string}`>]>, v.LengthAction<`0x${string}`, 66, undefined>]>, v.DescriptionAction<`0x${string}`, "Second 32-byte component.">]>;
readonly v: v.SchemaWithPipe<readonly [v.PicklistSchema<[27, 28], undefined>, v.DescriptionAction<27 | 28, "Recovery identifier.">]>;
}, undefined>, v.DescriptionAction<{
r: `0x${string}`;
s: `0x${string}`;
v: 27 | 28;
}, "ECDSA signature components.">]>;
/** Vault address (for vault trading). */
readonly vaultAddress: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, `0x${string}`>]>, v.LengthAction<`0x${string}`, 42, undefined>]>, undefined>, v.DescriptionAction<`0x${string}` | undefined, "Vault address (for vault trading).">]>;
/** Expiration time of the action. */
readonly expiresAfter: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>, v.DescriptionAction<number | undefined, "Expiration time of the action.">]>;
}, undefined>, v.DescriptionAction<{
action: {
type: "twapOrder";
twap: {
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
};
};
nonce: number;
signature: {
r: `0x${string}`;
s: `0x${string}`;
v: 27 | 28;
};
vaultAddress?: `0x${string}` | undefined;
expiresAfter?: number | undefined;
}, "Place a TWAP order.">]>;
export type TwapOrderRequest = v.InferOutput<typeof TwapOrderRequest>;
/**
* Response for creating a TWAP order.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order
*/
export declare const TwapOrderResponse: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Successful status. */
readonly status: v.SchemaWithPipe<readonly [v.LiteralSchema<"ok", undefined>, v.DescriptionAction<"ok", "Successful status.">]>;
/** Response details. */
readonly response: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Type of response. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"twapOrder", undefined>, v.DescriptionAction<"twapOrder", "Type of response.">]>;
/** Specific data. */
readonly data: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Status of the operation or error message. */
readonly status: v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
/** Running order status. */
readonly running: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** TWAP ID. */
readonly twapId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "TWAP ID.">]>;
}, undefined>, v.DescriptionAction<{
twapId: number;
}, "Running order status.">]>;
}, undefined>, v.ObjectSchema<{
/** Error message. */
readonly error: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Error message.">]>;
}, undefined>], undefined>, v.DescriptionAction<{
running: {
twapId: number;
};
} | {
error: string;
}, "Status of the operation or error message.">]>;
}, undefined>, v.DescriptionAction<{
status: {
running: {
twapId: number;
};
} | {
error: string;
};
}, "Specific data.">]>;
}, undefined>, v.DescriptionAction<{
type: "twapOrder";
data: {
status: {
running: {
twapId: number;
};
} | {
error: string;
};
};
}, "Response details.">]>;
}, undefined>, v.DescriptionAction<{
status: "ok";
response: {
type: "twapOrder";
data: {
status: {
running: {
twapId: number;
};
} | {
error: string;
};
};
};
}, "Response for creating a TWAP order.">]>;
export type TwapOrderResponse = v.InferOutput<typeof TwapOrderResponse>;
import { type ExchangeConfig, type ExtractRequestOptions } from "./_base/execute.js";
import type { ExcludeErrorResponse } from "./_base/errors.js";
/** Schema for user-provided action parameters (excludes system fields). */
declare const TwapOrderParameters: Omit<v.ObjectSchema<{
/** Type of action. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"twapOrder", undefined>, v.DescriptionAction<"twapOrder", "Type of action.">]>;
/** Twap parameters. */
readonly twap: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Asset ID. */
readonly a: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "Asset ID.">]>;
/** Position side (`true` for long, `false` for short). */
readonly b: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Position side (`true` for long, `false` for short).">]>;
/** Size (in base currency units). */
readonly s: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, string>, v.StringSchema<undefined>, v.TransformAction<string, string>, v.RegexAction<string, undefined>]>, v.DescriptionAction<string, "Size (in base currency units).">]>;
/** Is reduce-only? */
readonly r: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Is reduce-only?">]>;
/** TWAP duration in minutes. */
readonly m: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "TWAP duration in minutes.">]>;
/** Enable random order timing. */
readonly t: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Enable random order timing.">]>;
}, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
}, "Twap parameters.">]>;
}, undefined>, "entries" | "~types" | "~run" | "~standard"> & {
readonly entries: Omit<{
/** Type of action. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"twapOrder", undefined>, v.DescriptionAction<"twapOrder", "Type of action.">]>;
/** Twap parameters. */
readonly twap: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Asset ID. */
readonly a: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "Asset ID.">]>;
/** Position side (`true` for long, `false` for short). */
readonly b: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Position side (`true` for long, `false` for short).">]>;
/** Size (in base currency units). */
readonly s: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, string>, v.StringSchema<undefined>, v.TransformAction<string, string>, v.RegexAction<string, undefined>]>, v.DescriptionAction<string, "Size (in base currency units).">]>;
/** Is reduce-only? */
readonly r: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Is reduce-only?">]>;
/** TWAP duration in minutes. */
readonly m: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, v.DescriptionAction<number, "TWAP duration in minutes.">]>;
/** Enable random order timing. */
readonly t: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Enable random order timing.">]>;
}, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
}, "Twap parameters.">]>;
}, "type">;
readonly "~standard": v.StandardProps<{
twap: {
a: string | number;
b: boolean;
s: string | number;
r: boolean;
m: string | number;
t: boolean;
};
}, {
twap: {
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
};
}>;
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
twap: {
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
};
}, v.StringIssue | v.ObjectIssue | v.NumberIssue | v.UnionIssue<v.StringIssue | v.NumberIssue> | v.RegexIssue<string> | v.IntegerIssue<number> | v.SafeIntegerIssue<number> | v.MinValueIssue<number, 0> | v.BooleanIssue>;
readonly "~types"?: {
readonly input: {
twap: {
a: string | number;
b: boolean;
s: string | number;
r: boolean;
m: string | number;
t: boolean;
};
};
readonly output: {
twap: {
a: number;
b: boolean;
s: string;
r: boolean;
m: number;
t: boolean;
};
};
readonly issue: v.StringIssue | v.ObjectIssue | v.NumberIssue | v.UnionIssue<v.StringIssue | v.NumberIssue> | v.RegexIssue<string> | v.IntegerIssue<number> | v.SafeIntegerIssue<number> | v.MinValueIssue<number, 0> | v.BooleanIssue;
} | undefined;
};
/** Action parameters for the {@linkcode twapOrder} function. */
export type TwapOrderParameters = v.InferInput<typeof TwapOrderParameters>;
/** Request options for the {@linkcode twapOrder} function. */
export type TwapOrderOptions = ExtractRequestOptions<v.InferInput<typeof TwapOrderRequest>>;
/** Successful variant of {@linkcode TwapOrderResponse} without errors. */
export type TwapOrderSuccessResponse = ExcludeErrorResponse<TwapOrderResponse>;
/**
* Place a TWAP order.
*
* @param config - General configuration for Exchange API requests.
* @param params - Parameters specific to the API request.
* @param opts - Request execution options.
*
* @returns Successful variant of {@link TwapOrderResponse} without error status.
*
* @throws {ValiError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import { HttpTransport } from "@nktkas/hyperliquid";
* import { twapOrder } from "@nktkas/hyperliquid/api/exchange";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new HttpTransport(); // or `WebSocketTransport`
*
* const data = await twapOrder(
* { transport, wallet },
* {
* twap: {
* a: 0,
* b: true,
* s: "1",
* r: false,
* m: 10,
* t: true,
* },
* },
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order
*/
export declare function twapOrder(config: ExchangeConfig, params: TwapOrderParameters, opts?: TwapOrderOptions): Promise<TwapOrderSuccessResponse>;
export {};
//# sourceMappingURL=twapOrder.d.ts.map