/** * WioEX Stream Protocol Message Types * * These enums define the standard message types used for communication * between the WioEX Stream SDK and the WebSocket server. * * IMPORTANT: These types must be kept in sync between: * - SDK (TypeScript) * - Server (JavaScript) */ /** * Client-to-Server Message Types * Messages that the client sends to the server */ export enum ClientMessageType { /** Register/authenticate with the server using a JWT token */ REGISTER = 'register', /** Subscribe to real-time ticker data for specified symbols */ SUBSCRIBE = 'subscribe', /** Unsubscribe from ticker data for specified symbols */ UNSUBSCRIBE = 'unsubscribe', /** Subscribe to trading signals for specified symbols */ SUBSCRIBE_SIGNALS = 'subscribe-signals', /** Unsubscribe from trading signals for specified symbols */ UNSUBSCRIBE_SIGNALS = 'unsubscribe-signals', /** Send ping to server to check connection health */ PING = 'ping', /** Request server and connection status information */ STATUS = 'status', } /** * Server-to-Client Message Types * Messages that the server sends to the client */ export enum ServerMessageType { /** Server capability detection and negotiation */ CAPABILITY_DETECT = 'capability_detect', /** Initial connection establishment confirmation */ CONNECTED = 'connected', /** Registration/authentication success confirmation */ REGISTERED = 'registered', /** Subscription confirmation with list of subscribed symbols */ SUBSCRIBED = 'subscribed', /** Unsubscription confirmation with list of unsubscribed symbols */ UNSUBSCRIBED = 'unsubscribed', /** Real-time ticker data for a symbol */ TICKER = 'ticker', /** Trading signal data */ SIGNAL = 'signal', /** Signal trigger notification */ SIGNAL_TRIGGERED = 'signal-triggered', /** Signal subscription confirmation */ SIGNAL_SUBSCRIBED = 'signal-subscribed', /** Signal unsubscription confirmation */ SIGNAL_UNSUBSCRIBED = 'signal-unsubscribed', /** Response to ping request */ PONG = 'pong', /** Server status response */ STATUS_RESPONSE = 'status', /** Error message from server */ ERROR = 'error', } /** * Combined Message Types * Union of all possible message types for validation */ export type MessageType = ClientMessageType | ServerMessageType; /** * Message Status Types * Standard status indicators for server responses */ export enum MessageStatus { /** Operation completed successfully */ SUCCESS = 'success', /** Operation failed due to an error */ ERROR = 'error', /** Operation is in progress */ PENDING = 'pending', } /** * Error Types * Standard error categories for consistent error handling */ export enum ErrorType { /** Authentication or authorization failed */ AUTH_FAILED = 'auth_failed', /** Invalid message format or structure */ MESSAGE_ERROR = 'message_error', /** Unknown or unsupported message type */ UNKNOWN_MESSAGE_TYPE = 'unknown_message_type', /** Subscription operation failed */ SUBSCRIPTION_FAILED = 'subscription_failed', /** Unsubscription operation failed */ UNSUBSCRIPTION_FAILED = 'unsubscription_failed', /** Rate limiting exceeded */ RATE_LIMITED = 'rate_limited', /** Server internal error */ INTERNAL_ERROR = 'internal_error', /** Invalid symbol or parameter */ INVALID_SYMBOL = 'invalid_symbol', /** Maximum symbol limit exceeded */ SYMBOL_LIMIT_EXCEEDED = 'symbol_limit_exceeded', } /** * Protocol Formats * Supported message encoding formats */ export enum ProtocolFormat { /** JSON text format */ JSON = 'json', /** MessagePack binary format */ BINARY = 'binary', } /** * Type Guards and Validation Functions */ /** * Check if a string is a valid client message type */ export function isClientMessageType(type: string): type is ClientMessageType { return Object.values(ClientMessageType).includes(type as ClientMessageType); } /** * Check if a string is a valid server message type */ export function isServerMessageType(type: string): type is ServerMessageType { return Object.values(ServerMessageType).includes(type as ServerMessageType); } /** * Check if a string is a valid message type (client or server) */ export function isValidMessageType(type: string): type is MessageType { return isClientMessageType(type) || isServerMessageType(type); } /** * Check if a string is a valid message status */ export function isValidMessageStatus(status: string): status is MessageStatus { return Object.values(MessageStatus).includes(status as MessageStatus); } /** * Check if a string is a valid error type */ export function isValidErrorType(errorType: string): errorType is ErrorType { return Object.values(ErrorType).includes(errorType as ErrorType); } /** * Export constants for JavaScript compatibility */ export const MESSAGE_TYPES = { CLIENT: ClientMessageType, SERVER: ServerMessageType, STATUS: MessageStatus, ERROR: ErrorType, PROTOCOL: ProtocolFormat, } as const; /** * Default exports for backward compatibility */ export default MESSAGE_TYPES;