/** * WebSocket manager for persistent Dexalot streaming connections. * Uses the `ws` package on Node and the native WebSocket API in browsers. */ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting'; export type MessageCallback = (data: any) => void; /** Optional Dexalot private-topic signing hooks (address + signMessage). */ export interface WebSocketDexalotAuth { getAddress(): Promise; signMessage(message: string): Promise; } export interface WebSocketDexalotOptions { /** Milliseconds added to auth timestamp for clock skew (see `DEXALOT_WS_TIME_OFFSET_MS`). */ wsTimeOffsetMs?: number; auth?: WebSocketDexalotAuth; } export interface WebSocketConfig { /** Seconds between ping messages (default: 30) */ pingInterval?: number; /** Seconds to wait for pong before reconnecting (default: 10) */ pingTimeout?: number; /** Initial reconnect delay in seconds (default: 1) */ reconnectInitialDelay?: number; /** Maximum reconnect delay in seconds (default: 60) */ reconnectMaxDelay?: number; /** Exponential backoff multiplier (default: 2.0) */ reconnectExponentialBase?: number; /** Maximum reconnection attempts, 0 = infinite (default: 10) */ reconnectMaxAttempts?: number; } export interface OrderbookSubscriptionMeta { kind: 'orderbook'; pair: string; decimal: number; } /** * WebSocket manager with auto-reconnection, heartbeat, and subscription management. */ export declare class WebSocketManager { private ws; private state; private subscriptions; private reconnectAttempts; private pingTimer; private pongTimer; private reconnectTimer; private readonly wsUrl; private readonly config; private readonly dexalot; private staticAuthSignature; constructor(wsUrl: string, config?: WebSocketConfig, dexalot?: WebSocketDexalotOptions); /** * Set the signature used for private topic subscriptions when `dexalot.auth` is not set. * If both are present, `dexalot.auth` (timestamped subscribe payload) takes precedence. */ setAuthSignature(signature: string): void; /** * Connect to the WebSocket server. */ connect(): void; /** * Set up WebSocket event handlers. */ private setupEventHandlers; /** * Handle incoming WebSocket message. */ private handleMessage; /** * Subscribe to a topic. * @param meta When set with kind `orderbook`, sends Dexalot orderbook subscribe wire payload. */ subscribe(topic: string, callback: MessageCallback, isPrivate?: boolean, meta?: OrderbookSubscriptionMeta | null): void; /** * Unsubscribe from a topic. */ unsubscribe(topic: string): void; private appendTraderAddress; /** * Send subscription message to server. */ private sendSubscription; /** * Resubscribe to all topics after reconnection. */ private resubscribeAll; /** * Start ping interval. */ private startPingInterval; /** * Stop ping interval. */ private stopPingInterval; /** * Start pong timeout timer. */ private startPongTimer; /** * Reset pong timer (called when any message is received). */ private resetPongTimer; /** * Schedule a reconnection attempt. */ private scheduleReconnect; /** * Force reconnection. */ private reconnect; /** * Clean up timers and connection. */ private cleanup; /** * Disconnect from the WebSocket server. */ disconnect(): void; /** * Check if connected. */ get isConnected(): boolean; /** * Get current connection state. */ getState(): ConnectionState; /** * Get list of subscribed topics. */ getSubscribedTopics(): string[]; } //# sourceMappingURL=websocketManager.d.ts.map