import { WsAPIOperationResponseMap, WSAPIRequestFlags, WsAPITopicRequestParamMap, WsAPIWsKeyTopicMap, WSOperation, WsRequestOperationOKX } from './types/websockets/ws-api.js'; import { MessageEventLike, WsDataEvent } from './types/websockets/ws-events.js'; import { WSClientConfigurableOptions } from './types/websockets/ws-general.js'; import { WsAuthRequestArg, WsChannelSubUnSubRequestArg } from './types/websockets/ws-request.js'; import { BaseWebsocketClient, EmittableEvent, MidflightWsRequestEvent, WSClientEventMap } from './util/BaseWSClient.js'; import { DefaultLogger } from './util/logger.js'; import { WsKey, WsTopicRequest } from './util/websocket-util.js'; import { WSConnectedResult } from './util/WsStore.types.js'; export declare interface WebsocketClient { on>(event: U, listener: WSClientEventMap[U]): this; emit>(event: U, ...args: Parameters[U]>): boolean; } export declare class WebsocketClient extends BaseWebsocketClient> { constructor(options?: WSClientConfigurableOptions, logger?: DefaultLogger); /** * Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library */ connectAll(): Promise[]; connectPublic(businessEndpoint?: boolean): Promise; connectPrivate(businessEndpoint?: boolean): Promise; /** * Ensures the WS API connection is active and ready. * * You do not need to call this, but if you call this before making any WS API requests, * it can accelerate the first request (by preparing the connection in advance). */ connectWSAPI(): Promise; /** * Subscribe to topics & track/persist them. They will be automatically resubscribed to if the connection drops/reconnects. * @param wsEvents topic or list of topics * @param isPrivateTopic optional - the library will try to detect private topics, you can use this to mark a topic as private (if the topic isn't recognised yet) */ subscribe(wsEvents: WsChannelSubUnSubRequestArg[] | WsChannelSubUnSubRequestArg, isPrivateTopic?: boolean): Promise[]; /** * Unsubscribe from topics & remove them from memory. They won't be re-subscribed to if the connection reconnects. * @param wsTopics topic or list of topics * @param isPrivateTopic optional - the library will try to detect private topics, you can use this to mark a topic as private (if the topic isn't recognised yet) */ unsubscribe(wsEvents: WsChannelSubUnSubRequestArg[] | WsChannelSubUnSubRequestArg, isPrivateTopic?: boolean): Promise[]; /** * * * Internal methods required to integrate with the BaseWSClient * * */ getMarketWsKey(type: 'private' | 'business'): WsKey; protected sendPingEvent(wsKey: WsKey): void; protected sendPongEvent(wsKey: WsKey): void; protected isWsPing(data: any): boolean; protected isWsPong(data: any): boolean; protected isPrivateTopicRequest(_request: WsTopicRequest, wsKey: WsKey): boolean; protected getPrivateWSKeys(): WsKey[]; protected isAuthOnConnectWsKey(wsKey: WsKey): boolean; protected getWsUrl(wsKey: WsKey): Promise; protected getMaxTopicsPerSubscribeEvent(): number | null; /** * @returns one or more correctly structured request events for performing a operations over WS. This can vary per exchange spec. */ protected getWsRequestEvents(operation: WSOperation, requests: WsTopicRequest[]): Promise>[]>; private signMessage; protected getWsAuthRequestEvent(wsKey: WsKey, skipIsPublicWsKeyCheck: boolean): Promise | null>; private getWsAuthSignature; /** * Abstraction called to sort ws events into emittable event types (response to a request, data update, etc) */ protected resolveEmittableEvents(wsKey: WsKey, event: MessageEventLike): EmittableEvent[]; /** * OKX supports order placement via WebSockets. This is the WS API: * https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-place-order * * For convenient promise-wrapped usage of the WS API, instance the WebsocketAPIClient class exported by this SDK. * * For demo trading, set demoTrading:true in the WS Client config. * * @returns a promise that resolves/rejects when a matching response arrives */ sendWSAPIRequest(rawWsKey: WsKey, operation: TWSOperation, params: TWSParams & { signRequest?: boolean; }, requestFlags?: WSAPIRequestFlags): Promise; }