/** * WioEX Stream SDK - Main Client */ import EventEmitter from 'eventemitter3'; import type { WioexStreamConfig, WioexStreamEvents, ConnectionState, ClientStats } from './types'; /** * WioEX WebSocket Streaming Client * * Provides real-time market data streaming via WebSocket */ export declare class WioexStreamClient extends EventEmitter { private config; private ws; private state; private subscribedStocks; private reconnectAttempts; private reconnectTimer; private tokenExpiresAt; private tokenRefreshTimer; private isRefreshingToken; private isReconnecting; private reconnectionLock; private stats; private errorReporter; private lastReceivedMessage; private tickerThrottler; private logger; private signalSubscriptions; constructor(config: WioexStreamConfig); /** * DEBUG FIX: Restored proper debug logging functionality * Previously broken by unconditional return statement */ private log; /** * DEBUG FIX: Restored lazy logging for expensive debug operations * Only executed when debug mode is enabled */ private logLazy; /** * Connect to WioEX WebSocket stream * Manual connect() calls have priority over auto-reconnect */ connect(): Promise; /** * Disconnect from WebSocket stream */ disconnect(): void; /** * Subscribe to stock ticker updates */ subscribe(stocks: string | string[]): void; /** * Unsubscribe from stock ticker updates */ unsubscribe(stocks: string | string[]): void; /** * Subscribe to trading signals for specific symbols */ subscribeSignals(symbols: string | string[]): void; /** * Unsubscribe from trading signals */ unsubscribeSignals(symbols: string | string[]): void; /** * Get currently subscribed signal symbols */ getSignalSubscriptions(): string[]; /** * Get current connection state */ getState(): ConnectionState; /** * Get subscribed stocks */ getSubscribedStocks(): string[]; /** * Get client statistics */ getStats(): ClientStats; /** * Check if connected */ isConnected(): boolean; /** * Handle WebSocket open event */ private handleOpen; /** * Handle WebSocket message event * Phase 3: Support both JSON and Binary (MessagePack) protocols */ private handleMessage; /** * Handle WebSocket error event */ private handleError; /** * Handle WebSocket close event */ private handleClose; /** * Handle registration response */ private handleRegistration; /** * Handle subscription response */ private handleSubscription; /** * Handle ticker update (with optional throttling) */ private handleTicker; /** * Handle signal message */ private handleSignal; /** * Handle signal triggered message */ private handleSignalTriggered; /** * Handle signal subscription response */ private handleSignalSubscription; /** * Handle signal unsubscription response */ private handleSignalUnsubscription; /** * Send message to WebSocket * Phase 3: Support both JSON and Binary (MessagePack) protocols */ private sendMessage; /** * Calculate adaptive reconnection delay * First attempt: 500ms, Second: 1000ms, Third+: 3000ms */ private getReconnectDelay; /** * Attempt to reconnect with adaptive delay * Phase 2 Optimization: Prevent duplicate reconnection attempts + Adaptive timing */ private attemptReconnect; /** * Clear all timers * Phase 2: Also reset reconnection flag */ private clearTimers; /** * Set connection state and emit event */ private setState; /** * Get WebSocket implementation (Node.js vs Browser) */ private getWebSocketImplementation; /** * Update authentication token (e.g., when token expires) * * @param token - New authentication token * @param expiresAt - Token expiration time (Unix timestamp in seconds) */ updateToken(token: string, expiresAt: number): void; /** * Schedule token refresh before expiry */ private scheduleTokenRefresh; /** * Handle token refresh */ private handleTokenRefresh; /** * Cancel scheduled token refresh */ private cancelTokenRefresh; /** * Retry a function with exponential or linear backoff */ private retryWithBackoff; /** * Fetch token from backend endpoint (browser only) */ private fetchTokenFromEndpoint; /** * Fetch token from WioEX API using API key (Node.js/Backend only) * * SECURITY: This method is blocked in browser environments. * Browser users must use tokenEndpoint pointing to their backend. */ private fetchTokenFromApiKey; /** * Fetch token using https module (fallback for older Node.js) */ private fetchTokenWithHttps; /** * Enhanced token validation */ private validateToken; /** * Generate random ID for WebSocket connection */ private generateRandomId; /** * Report error to WioEX API */ private reportError; } export default WioexStreamClient; //# sourceMappingURL=WioexStreamClient.d.ts.map