bitget-api
Version:
Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.
80 lines (79 loc) • 4.23 kB
TypeScript
import { WSOperation, WSOperationLoginParams, WsRequestOperationBitget } from './types/websockets/ws-api.js';
import { MessageEventLike } from './types/websockets/ws-events.js';
import { BitgetInstTypeV2, WsKey, WsTopicV2 } from './types/websockets/ws-general.js';
import { BaseWebsocketClient, EmittableEvent, MidflightWsRequestEvent } from './util/BaseWSClient.js';
import { WsTopicRequest } from './util/websocket-util.js';
import { WSConnectedResult } from './util/WsStore.types.js';
export declare class WebsocketClientV2 extends BaseWebsocketClient<WsKey, WsRequestOperationBitget<object>> {
/**
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
*/
connectAll(): Promise<WSConnectedResult | undefined>[];
/** Some private channels use `coin` instead of `instId`. This method handles building the sub/unsub request */
private getSubRequest;
/**
* Subscribe to a topic
* @param instType instrument type (refer to API docs).
* @param topic topic name (e.g. "ticker").
* @param instId instrument ID (e.g. "BTCUSDT"). Use "default" for private topics.
*/
subscribeTopic(instType: BitgetInstTypeV2, topic: WsTopicV2, coin?: string): Promise<unknown>;
/**
* Unsubscribe from a topic
* @param instType instrument type (refer to API docs).
* @param topic topic name (e.g. "ticker").
* @param instId instrument ID (e.g. "BTCUSDT"). Use "default" for private topics to get all symbols.
*/
unsubscribeTopic(instType: BitgetInstTypeV2, topic: WsTopicV2, coin?: string): Promise<unknown>;
/**
* 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, category: CategoryV5}.
*
* - 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<WsTopicV2 | string> | WsTopicV2) | (WsTopicRequest<WsTopicV2 | string> | WsTopicV2)[], wsKey: WsKey): Promise<unknown>;
/**
* 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<WsTopicV2 | string> | WsTopicV2) | (WsTopicRequest<WsTopicV2 | string> | WsTopicV2)[], wsKey: WsKey): Promise<unknown>;
/**
*
*
* Internal methods required to integrate with the BaseWSClient
*
*
*/
protected sendPingEvent(wsKey: WsKey): void;
protected sendPongEvent(wsKey: WsKey): void;
protected isWsPing(data: any): boolean;
protected isWsPong(data: any): boolean;
protected isPrivateTopicRequest(_request: WsTopicRequest<string>, wsKey: WsKey): boolean;
protected getPrivateWSKeys(): WsKey[];
protected isAuthOnConnectWsKey(wsKey: WsKey): boolean;
protected getWsUrl(wsKey: WsKey): Promise<string>;
protected getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null;
/**
* @returns one or more correctly structured request events for performing a operations over WS. This can vary per exchange spec.
*/
protected getWsRequestEvents(operation: WSOperation, requests: WsTopicRequest<string, object>[]): Promise<MidflightWsRequestEvent<WsRequestOperationBitget<object>>[]>;
private getWsAuthSignature;
private signMessage;
protected getWsAuthRequestEvent(wsKey: WsKey): Promise<WsRequestOperationBitget<WSOperationLoginParams>>;
/**
* Abstraction called to sort ws events into emittable event types (response to a request, data update, etc)
*/
protected resolveEmittableEvents(wsKey: WsKey, event: MessageEventLike): EmittableEvent[];
/**
* @deprecrated not supported by Bitget's V2 API offering
*/
sendWSAPIRequest(): Promise<unknown>;
}