@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
735 lines • 41.8 kB
TypeScript
import * as v from "valibot";
/**
* Place an order(s).
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
*/
export declare const OrderRequest: 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<"order", undefined>, v.DescriptionAction<"order", "Type of action.">]>;
/** Array of order parameters. */
readonly orders: v.SchemaWithPipe<readonly [v.ArraySchema<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).">]>;
/** Price. */
readonly p: 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, "Price.">]>;
/** 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?">]>;
/** Order type. */
readonly t: v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
/** Limit order parameters. */
readonly limit: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/**
* Time-in-force.
* - `"Gtc"`: Remains active until filled or canceled.
* - `"Ioc"`: Fills immediately or cancels any unfilled portion.
* - `"Alo"`: Adds liquidity only.
* - `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.
* - `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.
*/
readonly tif: v.SchemaWithPipe<readonly [v.PicklistSchema<["Gtc", "Ioc", "Alo", "FrontendMarket", "LiquidationMarket"], undefined>, v.DescriptionAction<"Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket", string>]>;
}, undefined>, v.DescriptionAction<{
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
}, "Limit order parameters.">]>;
}, undefined>, v.ObjectSchema<{
/** Trigger order parameters. */
readonly trigger: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Is market order? */
readonly isMarket: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Is market order?">]>;
/** Trigger price. */
readonly triggerPx: 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, "Trigger price.">]>;
/** Indicates whether it is take profit or stop loss. */
readonly tpsl: v.SchemaWithPipe<readonly [v.PicklistSchema<["tp", "sl"], undefined>, v.DescriptionAction<"tp" | "sl", "Indicates whether it is take profit or stop loss.">]>;
}, undefined>, v.DescriptionAction<{
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
}, "Trigger order parameters.">]>;
}, undefined>], undefined>, v.DescriptionAction<{
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
}, "Order type.">]>;
/** Client Order ID. */
readonly c: 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}`, 34, undefined>]>, undefined>, v.DescriptionAction<`0x${string}` | undefined, "Client Order ID.">]>;
}, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}, "Place order parameters.">]>, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[], "Array of order parameters.">]>;
/**
* Order grouping strategy:
* - `na`: Standard order without grouping (default).
* - `normalTpsl`: TP/SL order with fixed size that doesn't adjust with position changes.
* - `positionTpsl`: TP/SL order that adjusts proportionally with the position size.
*/
readonly grouping: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<["na", "normalTpsl", "positionTpsl"], undefined>, "na">, v.DescriptionAction<"na" | "normalTpsl" | "positionTpsl", string>]>;
/** Builder fee. */
readonly builder: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
/** Builder address. */
readonly b: 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}`, 42, undefined>]>, v.DescriptionAction<`0x${string}`, "Builder address.">]>;
/** Builder fee in 0.1bps (1 = 0.0001%). */
readonly f: 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, "Builder fee in 0.1bps (1 = 0.0001%).">]>;
}, undefined>, undefined>, v.DescriptionAction<{
b: `0x${string}`;
f: number;
} | undefined, "Builder fee.">]>;
}, undefined>, v.DescriptionAction<{
type: "order";
orders: {
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[];
grouping: "na" | "normalTpsl" | "positionTpsl";
builder?: {
b: `0x${string}`;
f: number;
} | undefined;
}, "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: "order";
orders: {
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[];
grouping: "na" | "normalTpsl" | "positionTpsl";
builder?: {
b: `0x${string}`;
f: number;
} | undefined;
};
nonce: number;
signature: {
r: `0x${string}`;
s: `0x${string}`;
v: 27 | 28;
};
vaultAddress?: `0x${string}` | undefined;
expiresAfter?: number | undefined;
}, "Place an order(s).">]>;
export type OrderRequest = v.InferOutput<typeof OrderRequest>;
/**
* Response for order placement.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
*/
export declare const OrderResponse: 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<"order", undefined>, v.DescriptionAction<"order", "Type of response.">]>;
/** Specific data. */
readonly data: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Array of statuses or error messages. */
readonly statuses: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
/** Resting order status. */
readonly resting: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Order ID. */
readonly oid: 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, "Order ID.">]>;
/** Client Order ID. */
readonly cloid: 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}`, 34, undefined>]>, undefined>, v.DescriptionAction<`0x${string}` | undefined, "Client Order ID.">]>;
}, undefined>, v.DescriptionAction<{
oid: number;
cloid?: `0x${string}` | undefined;
}, "Resting order status.">]>;
}, undefined>, v.ObjectSchema<{
/** Filled order status. */
readonly filled: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Total size filled. */
readonly totalSz: 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, "Total size filled.">]>;
/** Average price of fill. */
readonly avgPx: 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, "Average price of fill.">]>;
/** Order ID. */
readonly oid: 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, "Order ID.">]>;
/** Client Order ID. */
readonly cloid: 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}`, 34, undefined>]>, undefined>, v.DescriptionAction<`0x${string}` | undefined, "Client Order ID.">]>;
}, undefined>, v.DescriptionAction<{
totalSz: string;
avgPx: string;
oid: number;
cloid?: `0x${string}` | undefined;
}, "Filled order status.">]>;
}, undefined>, v.ObjectSchema<{
/** Error message. */
readonly error: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Error message.">]>;
}, undefined>], undefined>, undefined>, v.DescriptionAction<({
resting: {
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
filled: {
totalSz: string;
avgPx: string;
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
error: string;
})[], "Array of statuses or error messages.">]>;
}, undefined>, v.DescriptionAction<{
statuses: ({
resting: {
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
filled: {
totalSz: string;
avgPx: string;
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
error: string;
})[];
}, "Specific data.">]>;
}, undefined>, v.DescriptionAction<{
type: "order";
data: {
statuses: ({
resting: {
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
filled: {
totalSz: string;
avgPx: string;
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
error: string;
})[];
};
}, "Response details.">]>;
}, undefined>, v.DescriptionAction<{
status: "ok";
response: {
type: "order";
data: {
statuses: ({
resting: {
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
filled: {
totalSz: string;
avgPx: string;
oid: number;
cloid?: `0x${string}` | undefined;
};
} | {
error: string;
})[];
};
};
}, "Response for order placement.">]>;
export type OrderResponse = v.InferOutput<typeof OrderResponse>;
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 OrderParameters: Omit<v.ObjectSchema<{
/** Type of action. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"order", undefined>, v.DescriptionAction<"order", "Type of action.">]>;
/** Array of order parameters. */
readonly orders: v.SchemaWithPipe<readonly [v.ArraySchema<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).">]>;
/** Price. */
readonly p: 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, "Price.">]>;
/** 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?">]>;
/** Order type. */
readonly t: v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
/** Limit order parameters. */
readonly limit: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/**
* Time-in-force.
* - `"Gtc"`: Remains active until filled or canceled.
* - `"Ioc"`: Fills immediately or cancels any unfilled portion.
* - `"Alo"`: Adds liquidity only.
* - `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.
* - `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.
*/
readonly tif: v.SchemaWithPipe<readonly [v.PicklistSchema<["Gtc", "Ioc", "Alo", "FrontendMarket", "LiquidationMarket"], undefined>, v.DescriptionAction<"Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket", string>]>;
}, undefined>, v.DescriptionAction<{
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
}, "Limit order parameters.">]>;
}, undefined>, v.ObjectSchema<{
/** Trigger order parameters. */
readonly trigger: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Is market order? */
readonly isMarket: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Is market order?">]>;
/** Trigger price. */
readonly triggerPx: 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, "Trigger price.">]>;
/** Indicates whether it is take profit or stop loss. */
readonly tpsl: v.SchemaWithPipe<readonly [v.PicklistSchema<["tp", "sl"], undefined>, v.DescriptionAction<"tp" | "sl", "Indicates whether it is take profit or stop loss.">]>;
}, undefined>, v.DescriptionAction<{
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
}, "Trigger order parameters.">]>;
}, undefined>], undefined>, v.DescriptionAction<{
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
}, "Order type.">]>;
/** Client Order ID. */
readonly c: 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}`, 34, undefined>]>, undefined>, v.DescriptionAction<`0x${string}` | undefined, "Client Order ID.">]>;
}, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}, "Place order parameters.">]>, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[], "Array of order parameters.">]>;
/**
* Order grouping strategy:
* - `na`: Standard order without grouping (default).
* - `normalTpsl`: TP/SL order with fixed size that doesn't adjust with position changes.
* - `positionTpsl`: TP/SL order that adjusts proportionally with the position size.
*/
readonly grouping: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<["na", "normalTpsl", "positionTpsl"], undefined>, "na">, v.DescriptionAction<"na" | "normalTpsl" | "positionTpsl", string>]>;
/** Builder fee. */
readonly builder: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
/** Builder address. */
readonly b: 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}`, 42, undefined>]>, v.DescriptionAction<`0x${string}`, "Builder address.">]>;
/** Builder fee in 0.1bps (1 = 0.0001%). */
readonly f: 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, "Builder fee in 0.1bps (1 = 0.0001%).">]>;
}, undefined>, undefined>, v.DescriptionAction<{
b: `0x${string}`;
f: number;
} | undefined, "Builder fee.">]>;
}, undefined>, "entries" | "~types" | "~run" | "~standard"> & {
readonly entries: Omit<{
/** Type of action. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"order", undefined>, v.DescriptionAction<"order", "Type of action.">]>;
/** Array of order parameters. */
readonly orders: v.SchemaWithPipe<readonly [v.ArraySchema<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).">]>;
/** Price. */
readonly p: 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, "Price.">]>;
/** 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?">]>;
/** Order type. */
readonly t: v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
/** Limit order parameters. */
readonly limit: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/**
* Time-in-force.
* - `"Gtc"`: Remains active until filled or canceled.
* - `"Ioc"`: Fills immediately or cancels any unfilled portion.
* - `"Alo"`: Adds liquidity only.
* - `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.
* - `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.
*/
readonly tif: v.SchemaWithPipe<readonly [v.PicklistSchema<["Gtc", "Ioc", "Alo", "FrontendMarket", "LiquidationMarket"], undefined>, v.DescriptionAction<"Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket", string>]>;
}, undefined>, v.DescriptionAction<{
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
}, "Limit order parameters.">]>;
}, undefined>, v.ObjectSchema<{
/** Trigger order parameters. */
readonly trigger: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Is market order? */
readonly isMarket: v.SchemaWithPipe<readonly [v.BooleanSchema<undefined>, v.DescriptionAction<boolean, "Is market order?">]>;
/** Trigger price. */
readonly triggerPx: 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, "Trigger price.">]>;
/** Indicates whether it is take profit or stop loss. */
readonly tpsl: v.SchemaWithPipe<readonly [v.PicklistSchema<["tp", "sl"], undefined>, v.DescriptionAction<"tp" | "sl", "Indicates whether it is take profit or stop loss.">]>;
}, undefined>, v.DescriptionAction<{
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
}, "Trigger order parameters.">]>;
}, undefined>], undefined>, v.DescriptionAction<{
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
}, "Order type.">]>;
/** Client Order ID. */
readonly c: 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}`, 34, undefined>]>, undefined>, v.DescriptionAction<`0x${string}` | undefined, "Client Order ID.">]>;
}, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}, "Place order parameters.">]>, undefined>, v.DescriptionAction<{
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[], "Array of order parameters.">]>;
/**
* Order grouping strategy:
* - `na`: Standard order without grouping (default).
* - `normalTpsl`: TP/SL order with fixed size that doesn't adjust with position changes.
* - `positionTpsl`: TP/SL order that adjusts proportionally with the position size.
*/
readonly grouping: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<["na", "normalTpsl", "positionTpsl"], undefined>, "na">, v.DescriptionAction<"na" | "normalTpsl" | "positionTpsl", string>]>;
/** Builder fee. */
readonly builder: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
/** Builder address. */
readonly b: 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}`, 42, undefined>]>, v.DescriptionAction<`0x${string}`, "Builder address.">]>;
/** Builder fee in 0.1bps (1 = 0.0001%). */
readonly f: 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, "Builder fee in 0.1bps (1 = 0.0001%).">]>;
}, undefined>, undefined>, v.DescriptionAction<{
b: `0x${string}`;
f: number;
} | undefined, "Builder fee.">]>;
}, "type">;
readonly "~standard": v.StandardProps<{
builder?: {
b: string;
f: string | number;
} | undefined;
orders: {
a: string | number;
b: boolean;
p: string | number;
s: string | number;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string | number;
tpsl: "tp" | "sl";
};
};
c?: string | undefined;
}[];
grouping?: "na" | "normalTpsl" | "positionTpsl" | undefined;
}, {
builder?: {
b: `0x${string}`;
f: number;
} | undefined;
orders: {
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[];
grouping: "na" | "normalTpsl" | "positionTpsl";
}>;
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
builder?: {
b: `0x${string}`;
f: number;
} | undefined;
orders: {
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[];
grouping: "na" | "normalTpsl" | "positionTpsl";
}, v.StringIssue | v.ArrayIssue | v.ObjectIssue | v.NumberIssue | v.UnionIssue<v.StringIssue | v.NumberIssue> | v.RegexIssue<string> | v.IntegerIssue<number> | v.SafeIntegerIssue<number> | v.MinValueIssue<number, 0> | v.LengthIssue<`0x${string}`, 42> | v.PicklistIssue | v.BooleanIssue | v.UnionIssue<v.StringIssue | v.ObjectIssue | v.NumberIssue | v.UnionIssue<v.StringIssue | v.NumberIssue> | v.RegexIssue<string> | v.PicklistIssue | v.BooleanIssue> | v.LengthIssue<`0x${string}`, 34>>;
readonly "~types"?: {
readonly input: {
builder?: {
b: string;
f: string | number;
} | undefined;
orders: {
a: string | number;
b: boolean;
p: string | number;
s: string | number;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string | number;
tpsl: "tp" | "sl";
};
};
c?: string | undefined;
}[];
grouping?: "na" | "normalTpsl" | "positionTpsl" | undefined;
};
readonly output: {
builder?: {
b: `0x${string}`;
f: number;
} | undefined;
orders: {
a: number;
b: boolean;
p: string;
s: string;
r: boolean;
t: {
limit: {
tif: "Gtc" | "Ioc" | "Alo" | "FrontendMarket" | "LiquidationMarket";
};
} | {
trigger: {
isMarket: boolean;
triggerPx: string;
tpsl: "tp" | "sl";
};
};
c?: `0x${string}` | undefined;
}[];
grouping: "na" | "normalTpsl" | "positionTpsl";
};
readonly issue: v.StringIssue | v.ArrayIssue | v.ObjectIssue | v.NumberIssue | v.UnionIssue<v.StringIssue | v.NumberIssue> | v.RegexIssue<string> | v.IntegerIssue<number> | v.SafeIntegerIssue<number> | v.MinValueIssue<number, 0> | v.LengthIssue<`0x${string}`, 42> | v.PicklistIssue | v.BooleanIssue | v.UnionIssue<v.StringIssue | v.ObjectIssue | v.NumberIssue | v.UnionIssue<v.StringIssue | v.NumberIssue> | v.RegexIssue<string> | v.PicklistIssue | v.BooleanIssue> | v.LengthIssue<`0x${string}`, 34>;
} | undefined;
};
/** Action parameters for the {@linkcode order} function. */
export type OrderParameters = v.InferInput<typeof OrderParameters>;
/** Request options for the {@linkcode order} function. */
export type OrderOptions = ExtractRequestOptions<v.InferInput<typeof OrderRequest>>;
/** Successful variant of {@linkcode OrderResponse} without errors. */
export type OrderSuccessResponse = ExcludeErrorResponse<OrderResponse>;
/**
* Place an order(s).
*
* @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 OrderResponse} without error statuses.
*
* @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 { order } 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 order(
* { transport, wallet },
* {
* orders: [
* {
* a: 0,
* b: true,
* p: "30000",
* s: "0.1",
* r: false,
* t: { limit: { tif: "Gtc" } },
* c: "0x...",
* },
* ],
* grouping: "na",
* },
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
*/
export declare function order(config: ExchangeConfig, params: OrderParameters, opts?: OrderOptions): Promise<OrderSuccessResponse>;
export {};
//# sourceMappingURL=order.d.ts.map