UNPKG

@nktkas/hyperliquid

Version:

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

84 lines (83 loc) 3.39 kB
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/api/subscription/_methods/userFundings.ts" /> import * as v from "valibot"; /** * Subscription to user funding events for a specific user. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions */ export declare const UserFundingsRequest: v.ObjectSchema<{ /** Type of subscription. */ readonly type: v.LiteralSchema<"userFundings", undefined>; /** User address. */ readonly user: 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>; export type UserFundingsRequest = v.InferOutput<typeof UserFundingsRequest>; /** * Event of user fundings. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions */ export type UserFundingsEvent = { /** * User address. * @pattern ^0x[a-fA-F0-9]{40}$ */ user: `0x${string}`; /** Array of user funding ledger updates. */ fundings: { /** Timestamp of the update (in ms since epoch). */ time: number; /** Asset symbol (e.g., BTC). */ coin: string; /** * Amount transferred in USDC. * @pattern ^-?[0-9]+(\.[0-9]+)?$ */ usdc: string; /** * Signed position size. * @pattern ^-?[0-9]+(\.[0-9]+)?$ */ szi: string; /** * Applied funding rate. * @pattern ^-?[0-9]+(\.[0-9]+)?$ */ fundingRate: string; /** Number of samples. */ nSamples: number | null; }[]; /** Whether this is an initial snapshot. */ isSnapshot?: true; }; import type { ISubscription } from "../../../transport/mod.js"; import type { SubscriptionConfig, SubscriptionOptions } from "./_base/mod.js"; /** Request parameters for the {@linkcode userFundings} function. */ export type UserFundingsParameters = Omit<v.InferInput<typeof UserFundingsRequest>, "type">; /** * Subscribe to funding payment 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. * @param options Options to control the subscription lifecycle. * @return A request-promise that resolves with a {@link ISubscription} object to manage the subscription lifecycle. * * @throws {ValidationError} 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 { userFundings } from "@nktkas/hyperliquid/api/subscription"; * * const transport = new WebSocketTransport(); * * const sub = await userFundings( * { transport }, * { user: "0x..." }, * (data) => console.log(data), * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions */ export declare function userFundings(config: SubscriptionConfig, params: UserFundingsParameters, listener: (data: UserFundingsEvent) => void, options?: SubscriptionOptions): Promise<ISubscription>;