UNPKG

@nktkas/hyperliquid

Version:

Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

119 lines 7.67 kB
import * as v from "valibot"; /** Subscription to spot state events for a specific user. */ export declare const SpotStateRequest: v.SchemaWithPipe<readonly [v.ObjectSchema<{ /** Type of subscription. */ readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"spotState", undefined>, v.DescriptionAction<"spotState", "Type of subscription.">]>; /** User address. */ readonly user: 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}`, "User address.">]>; /** Whether to ignore portfolio margin calculations. */ readonly ignorePortfolioMargin: v.SchemaWithPipe<readonly [v.OptionalSchema<v.BooleanSchema<undefined>, false>, v.DescriptionAction<boolean, "Whether to ignore portfolio margin calculations.">]>; }, undefined>, v.DescriptionAction<{ type: "spotState"; user: `0x${string}`; ignorePortfolioMargin: boolean; }, "Subscription to spot state events for a specific user.">]>; export type SpotStateRequest = v.InferOutput<typeof SpotStateRequest>; /** Event of user spot state. */ export declare const SpotStateEvent: v.SchemaWithPipe<readonly [v.ObjectSchema<{ /** User address. */ readonly user: 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}`, "User address.">]>; /** Account summary for spot trading. */ readonly spotState: v.SchemaWithPipe<readonly [v.ObjectSchema<{ readonly balances: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{ readonly coin: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Asset symbol.">]>; readonly token: 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, "Unique identifier for the token.">]>; readonly total: 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 balance.">]>; readonly hold: 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, "Amount on hold.">]>; readonly entryNtl: 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, "Entry notional value.">]>; }, undefined>, v.DescriptionAction<{ coin: string; token: number; total: string; hold: string; entryNtl: string; }, "Balance for a specific spot token.">]>, undefined>, v.DescriptionAction<{ coin: string; token: number; total: string; hold: string; entryNtl: string; }[], "Balance for each token.">]>; readonly evmEscrows: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{ readonly coin: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Asset symbol.">]>; readonly token: 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, "Unique identifier for the token.">]>; readonly total: 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 balance.">]>; }, undefined>, v.DescriptionAction<{ coin: string; token: number; total: string; }, "Escrowed balance for a specific asset.">]>, undefined>, undefined>, v.DescriptionAction<{ coin: string; token: number; total: string; }[] | undefined, "Escrowed balances.">]>; }, undefined>, v.DescriptionAction<{ balances: { coin: string; token: number; total: string; hold: string; entryNtl: string; }[]; evmEscrows?: { coin: string; token: number; total: string; }[] | undefined; }, "Account summary for spot trading.">]>; }, undefined>, v.DescriptionAction<{ user: `0x${string}`; spotState: { balances: { coin: string; token: number; total: string; hold: string; entryNtl: string; }[]; evmEscrows?: { coin: string; token: number; total: string; }[] | undefined; }; }, "Event of user spot state.">]>; export type SpotStateEvent = v.InferOutput<typeof SpotStateEvent>; import type { SubscriptionConfig } from "./_types.js"; import type { WebSocketSubscription } from "../../../transport/websocket/mod.js"; /** Request parameters for the {@linkcode spotState} function. */ export type SpotStateParameters = Omit<v.InferInput<typeof SpotStateRequest>, "type">; /** * Subscribe to spot state updates for a specific user. * * @param config - General configuration for Subscription API subscriptions. * @param params - Parameters specific to the API subscription. * @param listener - A callback function to be called when the event is received. * * @returns A request-promise that resolves with a {@link WebSocketSubscription} object to manage the subscription lifecycle. * * @throws {ValiError} When the request parameters fail validation (before sending). * @throws {TransportError} When the transport layer throws an error. * * @example * ```ts * import { WebSocketTransport } from "@nktkas/hyperliquid"; * import { spotState } from "@nktkas/hyperliquid/api/subscription"; * * const transport = new WebSocketTransport(); // only `WebSocketTransport` * * const sub = await spotState( * { transport }, * { user: "0x..." }, * (data) => console.log(data), * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions */ export declare function spotState(config: SubscriptionConfig, params: SpotStateParameters, listener: (data: SpotStateEvent) => void): Promise<WebSocketSubscription>; //# sourceMappingURL=spotState.d.ts.map