UNPKG

@nktkas/hyperliquid

Version:

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

56 lines 2.32 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { Address } from "../../_schemas.js"; import { WebData2Response } from "../../info/_methods/webData2.js"; /** Subscription to comprehensive user and market data events. */ export const WebData2Request = /* @__PURE__ */ (() => { return v.pipe(v.object({ /** Type of subscription. */ type: v.pipe(v.literal("webData2"), v.description("Type of subscription.")), /** User address. */ user: v.pipe(Address, v.description("User address.")), }), v.description("Subscription to comprehensive user and market data events.")); })(); /** Event of comprehensive user and market data. */ export const WebData2Event = /* @__PURE__ */ (() => { return v.pipe(WebData2Response, v.description("Event of comprehensive user and market data.")); })(); /** * Subscribe to comprehensive user and market data updates. * * @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 ISubscription} 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 { webData2 } from "@nktkas/hyperliquid/api/subscription"; * * const transport = new WebSocketTransport(); // only `WebSocketTransport` * * const sub = await webData2( * { transport }, * { user: "0x..." }, * (data) => console.log(data), * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions */ export function webData2(config, params, listener) { const payload = v.parse(WebData2Request, { type: "webData2", ...params }); return config.transport.subscribe(payload.type, payload, (e) => { if (e.detail.user === payload.user) { listener(e.detail); } }); } //# sourceMappingURL=webData2.js.map