@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
85 lines • 5.89 kB
TypeScript
import * as v from "valibot";
/** Subscription to trade events for a specific asset. */
export declare const TradesRequest: v.SchemaWithPipe<readonly [v.ObjectSchema<{
/** Type of subscription. */
readonly type: v.SchemaWithPipe<readonly [v.LiteralSchema<"trades", undefined>, v.DescriptionAction<"trades", "Type of subscription.">]>;
/** Asset symbol (e.g., BTC). */
readonly coin: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Asset symbol (e.g., BTC).">]>;
}, undefined>, v.DescriptionAction<{
type: "trades";
coin: string;
}, "Subscription to trade events for a specific asset.">]>;
export type TradesRequest = v.InferOutput<typeof TradesRequest>;
/** Event of array of trades for a specific asset. */
export declare const TradesEvent: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
readonly coin: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Asset symbol (e.g., BTC).">]>;
readonly side: v.SchemaWithPipe<readonly [v.PicklistSchema<["B", "A"], undefined>, v.DescriptionAction<"B" | "A", "Trade side (\"B\" = Bid/Buy, \"A\" = Ask/Sell).">]>;
readonly px: 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, "Trade price.">]>;
readonly sz: 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, "Trade size.">]>;
readonly time: 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, "Trade timestamp (in ms since epoch).">]>;
readonly hash: 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}`, "Transaction hash.">]>;
readonly tid: 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, "Trade ID.">]>;
readonly users: v.SchemaWithPipe<readonly [v.TupleSchema<[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.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}`, `0x${string}`], "Addresses of users involved in the trade [Maker, Taker].">]>;
}, undefined>, v.DescriptionAction<{
coin: string;
side: "B" | "A";
px: string;
sz: string;
time: number;
hash: `0x${string}`;
tid: number;
users: [`0x${string}`, `0x${string}`];
}, "Trade for a specific asset.">]>, undefined>, v.DescriptionAction<{
coin: string;
side: "B" | "A";
px: string;
sz: string;
time: number;
hash: `0x${string}`;
tid: number;
users: [`0x${string}`, `0x${string}`];
}[], "Array of recent trades.">]>, v.DescriptionAction<{
coin: string;
side: "B" | "A";
px: string;
sz: string;
time: number;
hash: `0x${string}`;
tid: number;
users: [`0x${string}`, `0x${string}`];
}[], "Event of array of trades for a specific asset.">]>;
export type TradesEvent = v.InferOutput<typeof TradesEvent>;
import type { SubscriptionConfig } from "./_types.js";
import type { WebSocketSubscription } from "../../../transport/websocket/mod.js";
/** Request parameters for the {@linkcode trades} function. */
export type TradesParameters = Omit<v.InferInput<typeof TradesRequest>, "type">;
/**
* Subscribe to real-time trade updates for a specific asset.
*
* @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 { trades } from "@nktkas/hyperliquid/api/subscription";
*
* const transport = new WebSocketTransport(); // only `WebSocketTransport`
*
* const sub = await trades(
* { transport },
* { coin: "ETH" },
* (data) => console.log(data),
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/
export declare function trades(config: SubscriptionConfig, params: TradesParameters, listener: (data: TradesEvent) => void): Promise<WebSocketSubscription>;
//# sourceMappingURL=trades.d.ts.map