/// import { EventEmitter } from 'events'; import { WebSocketChannelKey } from './constant.js'; export type WebSocketRequestType = 'login' | 'subscribe' | 'unsubscribe'; export type WebSocketReqponseType = WebSocketRequestType | 'error'; export type Channel = 'account' | 'orders' | 'rfqs' | 'quotes' | 'struc-block-trades' | 'tickers' | 'public-struc-block-trades' | 'instruments' | 'open-interest' | 'funding-rate' | 'price-limit' | 'opt-summary' | 'estimated-price' | 'deposit-info' | 'withdrawal-info' | 'liquidation-orders' | 'balance_and_position'; export interface Arg { channel?: Channel; } export interface WebSocketRequest { op: WebSocketRequestType; args: T[]; } export interface WebSocketResponse { event: WebSocketReqponseType; arg: T; } export interface WebSocketLoginResponse { event: 'login'; code: string; msg: string; } export interface WebSocketPush { arg: T; data: TD[]; } export interface Options { apiKey: string; passphrase: string; secretKey: string; } export interface ResponseEventData { channel: WebSocketChannelKey; data: WebSocketResponse; } export interface PushEventData { channel: WebSocketChannelKey; data: WebSocketPush; } export declare interface OkxWebSocketClient { emit(event: 'authorized'): boolean; emit(event: 'push', data: PushEventData): boolean; emit(event: 'response', data: ResponseEventData): boolean; on(event: 'authorized', listener: () => void): this; on(event: 'push', listener: (data: PushEventData) => void): this; on(event: 'response', listener: (data: { channel: WebSocketChannelKey; data: WebSocketResponse; }) => void): this; } export declare class OkxWebSocketClient extends EventEmitter { /** * WebSocket clients for different channels */ private _clients; private _apiKey; private _passphrase; private _secretKey; private _authorized; /** * @deprecated use `OkxWebSocket.getInstance` instead to ensure the application will use the same clients all the time. */ constructor(options: Options); /** * Init WebSocket Client for certain Channel * @param key {WebSocketChannelKey} * @returns {WebSocket} */ private _initClient; /** * Login to private channel */ private _loginToPrivateChannel; /** * Handle message received from a specific channel * @param key {WebSocketChannelKey} Key of the channel * @param message Message content */ private _handleMessage; /** * Send message to certain channel * @param key Key of the channel * @param message Message content */ send(key: WebSocketChannelKey, message: string | object): void; privateChannelReady(): Promise; private static _instance; static getInstance(opts: Options): OkxWebSocketClient; }