bitmart-api
Version:
Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.
80 lines (79 loc) • 3.44 kB
TypeScript
import WebSocket from 'isomorphic-ws';
import { BaseWebsocketClient, EmittableEvent } from './lib/BaseWSClient.js';
import { MessageEventLike } from './lib/requestUtils.js';
import { WsKey } from './lib/websocket/websocket-util.js';
import { WsMarket } from './types/websockets/client.js';
export declare const WS_LOGGER_CATEGORY: {
category: string;
};
/** 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 bitmart. Some exchanges use complex objects
*/
type WsTopic = string;
export declare class WebsocketClient extends BaseWebsocketClient<WsMarket, WsKey, WsTopic> {
/**
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
*/
connectAll(): Promise<WebSocket | undefined>[];
/**
* Request subscription to one or more topics.
*
* - Subscriptions are automatically routed to the correct websocket connection.
* - Authentication/connection is automatic.
* - Resubscribe after network issues is automatic.
*
* Call `unsubscribeTopics(topics)` to remove topics
*/
subscribeTopics(topics: WsTopic[]): void;
/**
* Unsubscribe from one or more topics.
*
* - 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.
*/
unsubscribeTopics(topics: WsTopic[]): void;
/**
*
* Internal methods
*
*/
protected sendPingEvent(wsKey: WsKey): void;
protected isWsPong(msg: any): boolean;
protected resolveEmittableEvents(event: MessageEventLike): EmittableEvent[];
/**
* Determines if a topic is for a private channel, using a hardcoded list of strings
*/
protected isPrivateChannel(topic: WsTopic): boolean;
protected getWsKeyForMarket(market: WsMarket, isPrivate: boolean): WsKey;
protected getWsMarketForWsKey(key: WsKey): WsMarket;
protected getWsKeyForTopic(topic: WsTopic): WsKey;
protected getPrivateWSKeys(): WsKey[];
protected getWsUrl(wsKey: WsKey): string;
/** 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 getWsSubscribeEventsForTopics(topics: WsTopic[], wsKey: WsKey): string[];
/**
* Map one or more topics into fully prepared "unsubscribe request" events (already stringified and ready to send)
*/
protected getWsUnsubscribeEventsForTopics(topics: WsTopic[], wsKey: WsKey): string[];
/**
* @returns a correctly structured events for performing an operation over WS. This can vary per exchange spec.
*/
private getWsRequestEvent;
protected getWsAuthRequestEvent(wsKey: WsKey): Promise<object>;
/**
* This exchange API is split into "markets" that behave differently (different base URLs).
* The market can easily be resolved using the topic name.
*/
private getMarketForTopic;
/**
* Used to split sub/unsub logic by websocket connection
*/
private arrangeTopicsIntoWsKeyGroups;
}
export {};