kucoin-api
Version:
Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.
84 lines (83 loc) • 4.48 kB
TypeScript
import { BaseWebsocketClient, EmittableEvent } from './lib/BaseWSClient.js';
import { WsKey, WsTopicRequest } from './lib/websocket/websocket-util.js';
import { WSConnectedResult } from './lib/websocket/WsStore.types.js';
import { Exact, WSAPIAuthenticationRequestFromServer, WsAPITopicRequestParamMap, WsAPITopicResponseMap, WsAPIWsKeyTopicMap, WsOperation } from './types/websockets/ws-api.js';
import { MessageEventLike } from './types/websockets/ws-events.js';
import { WsMarket } from './types/websockets/ws-general.js';
export declare const WS_LOGGER_CATEGORY: {
category: string;
};
export interface WSAPIRequestFlags {
/** If true, will skip auth requirement for WS API connection */
authIsOptional?: boolean | undefined;
}
/** Any WS keys in this list will ALWAYS skip the authentication process, even if credentials are available */
export declare const PUBLIC_WS_KEYS: WsKey[];
/**
* WS topics are always a string for this exchange. Some exchanges use complex objects.
*/
type WsTopic = string;
export declare class WebsocketClient extends BaseWebsocketClient<WsKey> {
private RESTClientCache;
private getRESTClient;
private getRestClientOptions;
private getWSConnectionInfo;
private signMessage;
/**
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
*/
connectAll(): Promise<(WSConnectedResult | undefined)[]>;
/**
* Request subscription to one or more topics. Pass topics as either an array of strings, or array of objects (if the topic has parameters).
* Objects should be formatted as {topic: string, params: object}.
*
* - Subscriptions are automatically routed to the correct websocket connection.
* - Authentication/connection is automatic.
* - Resubscribe after network issues is automatic.
*
* Call `unsubscribe(topics)` to remove topics
*/
subscribe(requests: (WsTopicRequest<WsTopic> | WsTopic) | (WsTopicRequest<WsTopic> | WsTopic)[], wsKey: WsKey): void;
/**
* Unsubscribe from one or more topics. Similar to subscribe() but in reverse.
*
* - Requests are automatically routed to the correct websocket connection.
* - These topics will be removed from the topic cache, so they won't be subscribed to again.
*/
unsubscribe(requests: (WsTopicRequest<WsTopic> | WsTopic) | (WsTopicRequest<WsTopic> | WsTopic)[], wsKey: WsKey): void;
sendWSAPIRequest<TWSKey extends keyof WsAPIWsKeyTopicMap, TWSOperation extends WsAPIWsKeyTopicMap[TWSKey], TWSParams extends Exact<WsAPITopicRequestParamMap[TWSOperation]>, TWSAPIResponse extends WsAPITopicResponseMap[TWSOperation] = WsAPITopicResponseMap[TWSOperation]>(wsKey: TWSKey, operation: TWSOperation, params: TWSParams & {
signRequest?: boolean;
}, requestFlags?: WSAPIRequestFlags): Promise<TWSAPIResponse>;
/**
*
* Internal methods
*
*/
private signWSAPIRequest;
/**
* Whatever url this method returns, it's connected to as-is!
*
* If a token or anything else is needed in the URL, this is a good place to add it.
*/
protected getWsUrl(wsKey: WsKey): Promise<string>;
protected sendPingEvent(wsKey: WsKey): void;
protected sendPongEvent(wsKey: WsKey): void;
protected isWsPing(msg: any): boolean;
protected isWsPong(msg: any): boolean;
protected resolveEmittableEvents(wsKey: WsKey, event: MessageEventLike): EmittableEvent[];
/**
* Determines if a topic is for a private channel, using a hardcoded list of strings
*/
protected isPrivateTopicRequest(request: WsTopicRequest<string>, wsKey: WsKey): boolean;
protected getWsKeyForMarket(market: WsMarket, isPrivate: boolean): WsKey;
protected getWsMarketForWsKey(key: WsKey): WsMarket;
protected getPrivateWSKeys(): WsKey[];
/** Force subscription requests to be sent in smaller batches, if a number is returned */
protected getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null;
/**
* Map one or more topics into fully prepared "subscribe request" events (already stringified and ready to send)
*/
protected getWsOperationEventsForTopics(topicRequests: WsTopicRequest<string>[], wsKey: WsKey, operation: WsOperation): Promise<string[]>;
protected getWsAuthRequestEvent(wsKey: WsKey, eventToAuth?: WSAPIAuthenticationRequestFromServer): Promise<object | string | 'waitForEvent' | void>;
}
export {};