@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
58 lines (57 loc) • 2.65 kB
TypeScript
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/api/subscription/_methods/activeAssetCtx.ts" />
import * as v from "valibot";
import type { PerpAssetCtx } from "../../info/_methods/_base/mod.js";
/**
* Subscription to context events for a specific perpetual asset.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/
export declare const ActiveAssetCtxRequest: v.ObjectSchema<{
/** Type of subscription. */
readonly type: v.LiteralSchema<"activeAssetCtx", undefined>;
/** Asset symbol (e.g., BTC). */
readonly coin: v.StringSchema<undefined>;
}, undefined>;
export type ActiveAssetCtxRequest = v.InferOutput<typeof ActiveAssetCtxRequest>;
/**
* Event of active perpetual asset context.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/
export type ActiveAssetCtxEvent = {
/** Asset symbol (e.g., BTC). */
coin: string;
/** Context for a specific perpetual asset. */
ctx: PerpAssetCtx;
};
import type { ISubscription } from "../../../transport/mod.js";
import type { SubscriptionConfig, SubscriptionOptions } from "./_base/mod.js";
/** Request parameters for the {@linkcode activeAssetCtx} function. */
export type ActiveAssetCtxParameters = Omit<v.InferInput<typeof ActiveAssetCtxRequest>, "type">;
/**
* Subscribe to context updates for a specific perpetual 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.
* @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 { activeAssetCtx } from "@nktkas/hyperliquid/api/subscription";
*
* const transport = new WebSocketTransport();
*
* const sub = await activeAssetCtx(
* { transport },
* { coin: "ETH" },
* (data) => console.log(data),
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
*/
export declare function activeAssetCtx(config: SubscriptionConfig, params: ActiveAssetCtxParameters, listener: (data: ActiveAssetCtxEvent) => void, options?: SubscriptionOptions): Promise<ISubscription>;