UNPKG

kucoin-api

Version:

Complete & robust Node.js SDK for Kucoin's REST APIs and WebSockets, with TypeScript & strong end to end tests.

53 lines (52 loc) 2.82 kB
import WebSocket from 'isomorphic-ws'; import { WsRequestOperationKucoin } from '../../types/websockets/ws-api.js'; import { MessageEventLike } from '../../types/websockets/ws-events.js'; /** Should be one WS key per unique URL */ export declare const WS_KEY_MAP: { readonly spotPublicV1: "spotPublicV1"; readonly spotPrivateV1: "spotPrivateV1"; readonly futuresPublicV1: "futuresPublicV1"; readonly futuresPrivateV1: "futuresPrivateV1"; /** Dedicated V2 (Pro) connection for push of public spot market data */ readonly spotPublicProV2: "spotPublicProV2"; /** Dedicated V2 (Pro) connection for push of public futures market data */ readonly futuresPublicProV2: "futuresPublicProV2"; /** Shared (spot & futures) V2 (Pro) connection for all private data */ readonly privateProV2: "privateProV2"; readonly wsApiSpotV1: "wsApiSpotV1"; readonly wsApiFuturesV1: "wsApiFuturesV1"; }; /** This is used to differentiate between each of the available websocket streams */ export type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP]; export type WSAPIWsKey = typeof WS_KEY_MAP.wsApiFuturesV1 | typeof WS_KEY_MAP.wsApiSpotV1; /** * Normalised internal format for a request (subscribe/unsubscribe/etc) on a topic, with optional parameters. * * - Topic: the topic this event is for * - Payload: the parameters to include, optional. E.g. auth requires key + sign. Some topics allow configurable parameters. */ export interface WsTopicRequest<TWSTopic extends string = string, TWSPayload = any> { topic: TWSTopic; payload?: TWSPayload; } /** * Conveniently allow users to request a topic either as string topics or objects (containing string topic + params) */ export type WsTopicRequestOrStringTopic<TWSTopic extends string, TWSPayload = any> = WsTopicRequest<TWSTopic, TWSPayload> | string; /** * #305: ws.terminate() is undefined in browsers. * This only works in node.js, not in browsers. * Does nothing if `ws` is undefined. Does nothing in browsers. */ export declare function safeTerminateWs(ws?: WebSocket | any, fallbackToClose?: boolean): boolean; /** * WS API promises are stored using a primary key. This key is constructed using * properties found in every request & reply. * * The counterpart to this is in resolveEmittableEvents */ export declare function getPromiseRefForWSAPIRequest(wsKey: WsKey, requestEvent: WsRequestOperationKucoin<string>): string; export declare function isWSAPIWsKey(wsKey: WsKey): wsKey is WSAPIWsKey; export declare function isBufferMessageEvent(msg: unknown): msg is MessageEventLike<Buffer>; export declare function bufferLooksLikeText(data?: Buffer | ArrayBufferLike | null): boolean; export declare function decompressMessageEvent(event: MessageEventLike<Buffer<ArrayBufferLike>>): Promise<MessageEventLike<any>>;