@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
37 lines • 1.65 kB
TypeScript
import { TransportError } from "../../_errors.js";
import type { ReconnectingWebSocket } from "@nktkas/rews";
import type { HyperliquidEventTarget } from "./_hyperliquidEventTarget.js";
interface PendingRequest {
id: number | string;
resolve: (value?: any) => void;
reject: (reason?: any) => void;
}
/** Error thrown when a WebSocket request fails. */
export declare class WebSocketRequestError extends TransportError {
constructor(message?: string, options?: ErrorOptions);
}
/**
* Manages WebSocket requests to the Hyperliquid API.
* Handles request creation, sending, and mapping responses to their corresponding requests.
*/
export declare class WebSocketAsyncRequest {
protected socket: ReconnectingWebSocket;
protected lastId: number;
protected queue: PendingRequest[];
/**
* Creates a new WebSocket async request handler.
* @param socket - WebSocket connection instance for sending requests to the Hyperliquid WebSocket API
* @param hlEvents - Used to recognize Hyperliquid responses and match them with sent requests
*/
constructor(socket: ReconnectingWebSocket, hlEvents: HyperliquidEventTarget);
/**
* Sends a request to the Hyperliquid API.
* @returns A promise that resolves with the parsed JSON response body.
*/
request(method: "ping", signal?: AbortSignal): Promise<void>;
request<T>(method: "post" | "subscribe" | "unsubscribe", payload: unknown, signal?: AbortSignal): Promise<T>;
/** Normalizes an object and then converts it to a string. */
static requestToId(value: unknown): string;
}
export {};
//# sourceMappingURL=_postRequest.d.ts.map