@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
39 lines (38 loc) • 1.32 kB
TypeScript
/**
* Keep-alive watchdog for the WebSocket connection: pings the server on an
* interval and reconnects when a ping stays unanswered.
*
* @module
*/
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/transport/websocket/_keepAlive.ts" />
import type { ReconnectingWebSocket } from "@nktkas/rews";
import type { HyperliquidEventTarget } from "./_events.js";
/** Configuration options for the keep-alive watchdog. */
export interface WebSocketKeepAliveOptions {
/**
* Interval between pings in ms.
*
* The server closes a connection that has been silent for ~60 s, so pings must come more often than that.
*
* Default: `30_000`
*/
interval?: number;
/**
* Time to wait for a pong before forcing a reconnect, in ms.
*
* Default: `10_000`
*/
timeout?: number;
}
/** Pings the server while the connection is open and reconnects when a ping stays unanswered. */
export declare class WebSocketKeepAlive {
private readonly _socket;
private readonly _interval;
private readonly _timeout;
private _pingInterval;
private _pongTimeout;
constructor(socket: ReconnectingWebSocket, hlEvents: HyperliquidEventTarget, options?: WebSocketKeepAliveOptions);
private _start;
private _stop;
private _disarm;
}