bitmart-api
Version:
Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.
67 lines (66 loc) • 3.53 kB
TypeScript
import WebSocket from 'isomorphic-ws';
import { WsTopic } from '../../types/websockets/client.js';
import { MessageEventLike } from '../requestUtils.js';
/**
* 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.
* - Category: required for bybit, since different categories have different public endpoints
*/
export interface WsTopicRequest<TWSTopic extends string = string, TWSPayload = unknown> {
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 = unknown> = WsTopicRequest<TWSTopic, TWSPayload> | string;
/** 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";
readonly futuresPublicV2: "futuresPublicV2";
readonly futuresPrivateV2: "futuresPrivateV2";
};
/** This is used to differentiate between each of the available websocket streams */
export type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP];
/**
* Some exchanges have two livenet environments, some have test environments, some dont. This allows easy flexibility for different exchanges.
* Examples:
* - One livenet and one testnet: NetworkMap<'livenet' | 'testnet'>
* - One livenet, sometimes two, one testnet: NetworkMap<'livenet' | 'testnet', 'livenet2'>
* - Only one livenet, no other networks: NetworkMap<'livenet'>
*/
type NetworkMap<TRequiredKeys extends string, TOptionalKeys extends string | undefined = undefined> = Record<TRequiredKeys, string> & (TOptionalKeys extends string ? Record<TOptionalKeys, string | undefined> : Record<TRequiredKeys, string>);
export declare const WS_BASE_URL_MAP: Record<WsKey, NetworkMap<'livenet', 'demo'>>;
export declare const WS_ERROR_ENUM: {
INVALID_ACCESS_KEY: string;
};
export declare function neverGuard(x: never, msg: string): Error;
/**
* 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;
/**
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
*
* This method normalises topics into objects (object has topic name + optional params).
*/
export declare function getNormalisedTopicRequests(wsTopicRequests: WsTopicRequestOrStringTopic<string>[]): WsTopicRequest<WsTopic>[];
/**
* WebSocket.ping() is not available in browsers. This is a simple check used to
* disable heartbeats in browers, for exchanges that use native WebSocket ping/pong frames.
*/
export declare function isWSPingFrameAvailable(): boolean;
/**
* WebSocket.pong() is not available in browsers. This is a simple check used to
* disable heartbeats in browers, for exchanges that use native WebSocket ping/pong frames.
*/
export declare function isWSPongFrameAvailable(): boolean;
export declare function decompressMessageEvent(event: MessageEventLike<Buffer<ArrayBufferLike>>): Promise<MessageEventLike<any>>;
export {};