UNPKG

okx-api

Version:

Complete Node.js SDK for OKX's REST APIs and WebSockets, with TypeScript & end-to-end tests

77 lines (76 loc) 3.81 kB
import { EventEmitter } from 'events'; import WebSocket from 'isomorphic-ws'; import { WsDataEvent } from './types/websockets/ws-events.js'; import { WSClientConfigurableOptions } from './types/websockets/ws-general.js'; import { WsChannelSubUnSubRequestArg } from './types/websockets/ws-request.js'; import { WSClientEventMap } from './util/BaseWSClient.js'; import { DefaultLogger } from './util/logger.js'; import { WsKey } from './util/websocket-util.js'; import WsStore from './util/WsStore.js'; export declare interface WebsocketClientLegacy { on<U extends keyof WSClientEventMap<WsKey, WsDataEvent>>(event: U, listener: WSClientEventMap<WsKey>[U]): this; emit<U extends keyof WSClientEventMap<WsKey, WsDataEvent>>(event: U, ...args: Parameters<WSClientEventMap<WsKey>[U]>): boolean; } /** * @deprecated This is the old WebsocketClient that was part of the SDK prior to the V3 release. This legacy WebsocketClient is temporarily included but will be removed with the next major release. */ export declare class WebsocketClientLegacy extends EventEmitter { private logger; private options; private wsStore; constructor(options: WSClientConfigurableOptions, logger?: DefaultLogger); /** * 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): void; /** * 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(wsTopics: WsChannelSubUnSubRequestArg[] | WsChannelSubUnSubRequestArg, isPrivateTopic?: boolean): void; /** Get the WsStore that tracks websocket & topic state */ getWsStore(): WsStore<WsKey, WsChannelSubUnSubRequestArg>; close(wsKey: WsKey, force?: boolean): void; closeAll(force?: boolean): void; /** * Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library */ connectAll(): Promise<WebSocket | undefined>[]; connectPublic(businessEndpoint?: boolean): Promise<WebSocket | undefined>; connectPrivate(businessEndpoint?: boolean): Promise<WebSocket | undefined>; private connect; private parseWsError; /** * Return params required to make authorized request */ private getWsAuthRequest; private getWsAuthSignature; private sendAuthRequest; private reconnectWithDelay; private ping; /** * Closes a connection, if it's even open. If open, this will trigger a reconnect asynchronously. * If closed, trigger a reconnect immediately. */ private executeReconnectableClose; private clearTimers; private clearPingTimer; private clearPongTimer; private clearReconnectTimer; /** * @private Use the `subscribe(topics)` method to subscribe to topics. Send WS message to subscribe to topics. */ private requestSubscribeTopics; /** * @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics. */ private requestUnsubscribeTopics; tryWsSend(wsKey: WsKey, wsMessage: string): void; private connectToWsUrl; private onWsOpen; private onWsMessage; private onWsClose; }