UNPKG

bitget-api

Version:

Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.

89 lines (88 loc) 4.95 kB
import { WSAPIRequestBitgetV3 } from '../types/websockets/ws-api.js'; import { WebsocketClientOptions, WsKey, WsPrivateTopicV2, WsPrivateTopicV3, WsTopicSubscribeEventArgs, WsTopicSubscribePublicArgsV2 } from '../types/websockets/ws-general.js'; import { DefaultLogger } from './logger.js'; export declare const WS_LOGGER_CATEGORY: { category: string; }; /** * 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, Record<'all', NetworkMap<'livenet' | 'demo'>>>; /** Should be one WS key per unique URL */ export declare const WS_KEY_MAP: { readonly spotv1: "spotv1"; readonly mixv1: "mixv1"; readonly v2Public: "v2Public"; readonly v2Private: "v2Private"; readonly v3Public: "v3Public"; readonly v3Private: "v3Private"; }; /** Any WS keys in this list will trigger auth on connect, if credentials are available */ export declare const WS_AUTH_ON_CONNECT_KEYS: WsKey[]; /** Any WS keys in this list will ALWAYS skip the authentication process, even if credentials are available */ export declare const PUBLIC_WS_KEYS: WsKey[]; /** * Used to automatically determine if a sub request should be to a public or private ws (when there's two separate connections). * Unnecessary if there's only one connection to handle both public & private topics. */ export declare const PRIVATE_TOPICS: string[]; export declare const PRIVATE_TOPICS_V2: WsPrivateTopicV2[]; export declare const PRIVATE_TOPICS_V3: WsPrivateTopicV3[]; export declare function getWsUrl(wsKey: WsKey, options: WebsocketClientOptions, logger: DefaultLogger): Promise<string>; /** * 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; export declare function isPrivateChannel<TChannel extends string>(channel: TChannel): boolean; export declare function getWsKeyForTopicV1(subscribeEvent: WsTopicSubscribeEventArgs, _isPrivate?: boolean): WsKey; export declare function getWsKeyForTopicV2(subscribeEvent: WsTopicSubscribePublicArgsV2, isPrivate?: boolean): WsKey; /** Force subscription requests to be sent in smaller batches, if a number is returned */ export declare function getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null; export declare const WS_ERROR_ENUM: { INVALID_ACCESS_KEY: number; }; export declare function neverGuard(x: never, msg: string): Error; /** * #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; /** * 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<string>[]; /** * 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; /** * WS API promises are stored using a primary key. This key is constructed using * properties found in every request & reply. */ export declare function getPromiseRefForWSAPIRequest(requestEvent: WSAPIRequestBitgetV3<unknown>): string; export {};