kucoin-universal-sdk
Version:
Official KuCoin Universal SDK.
99 lines (98 loc) • 3.19 kB
TypeScript
/**
* WebSocketEvent defines the types of WebSocket events
*/
export declare enum WebSocketEvent {
EventConnected = "EventConnected",
EventDisconnected = "EventDisconnected",
EventTryReconnect = "EventTryReconnect",
EventMessageReceived = "EventMessageReceived",
EventErrorReceived = "EventErrorReceived",
EventPongReceived = "EventPongReceived",
EventReadBufferFull = "EventReadBufferFull",
EventWriteBufferFull = "EventWriteBufferFull",
EventCallbackError = "EventCallbackError",
EventReSubscribeOK = "EventReSubscribeOK",
EventReSubscribeError = "EventReSubscribeError",
EventClientFail = "EventClientFail",
EventClientShutdown = "EventClientShutdown"
}
/**
* WebSocketCallback is a generic callback function type that handles all WebSocket events
*/
export type WebSocketCallback = (event: WebSocketEvent, msg: string) => void;
/**
* WebSocketClientOption contains the settings for the WebSocket client
*/
export interface WebSocketClientOption {
/**
* Enable auto-reconnect; default: true
*/
reconnect: boolean;
/**
* Maximum reconnect attempts, -1 means forever; default: -1
*/
reconnectAttempts: number;
/**
* Interval between reconnect attempts (milliseconds); default: 5000
*/
reconnectInterval: number;
/**
* Timeout for establishing a WebSocket connection (milliseconds); default: 10000
*/
dialTimeout: number;
/**
* Read buffer for messages; default: 1024
*/
readMessageBuffer: number;
/**
* Write timeout (milliseconds); default: 30000
*/
writeTimeout: number;
/**
* General callback function to handle all WebSocket events
*/
eventCallback?: WebSocketCallback;
}
/**
* Default values for WebSocketClientOption
*/
export declare const DEFAULT_WEBSOCKET_CLIENT_OPTION: WebSocketClientOption;
/**
* WebSocketClientOptionBuilder is a builder for WebSocketClientOption
*/
export declare class WebSocketClientOptionBuilder {
private option;
constructor();
/**
* Set whether to enable auto-reconnect
*/
withReconnect(reconnect: boolean): WebSocketClientOptionBuilder;
/**
* Set the maximum reconnect attempts
*/
withReconnectAttempts(attempts: number): WebSocketClientOptionBuilder;
/**
* Set the interval between reconnect attempts (milliseconds)
*/
withReconnectInterval(interval: number): WebSocketClientOptionBuilder;
/**
* Set the timeout for establishing a WebSocket connection (milliseconds)
*/
withDialTimeout(timeout: number): WebSocketClientOptionBuilder;
/**
* Set the read buffer size for messages
*/
withReadMessageBuffer(readMessageBuffer: number): WebSocketClientOptionBuilder;
/**
* Set the write timeout (milliseconds)
*/
withWriteTimeout(timeout: number): WebSocketClientOptionBuilder;
/**
* Set the callback function to handle WebSocket events
*/
withEventCallback(callback: WebSocketCallback): WebSocketClientOptionBuilder;
/**
* Build and return the WebSocketClientOption instance
*/
build(): WebSocketClientOption;
}