UNPKG

bitget-api

Version:

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

85 lines (84 loc) 4.72 kB
import { WsAPIOperationResponseMap, WSAPIRequestFlags, WsAPITopicRequestParamMap, WsAPIWsKeyTopicMap, WSOperation, WSOperationLoginParams, WsRequestOperationBitget } from './types/websockets/ws-api.js'; import { MessageEventLike } from './types/websockets/ws-events.js'; import { BitgetInstTypeV3, WsKey, WsTopicV3 } 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'; /** * WebSocket client dedicated to the unified account (V3) WebSockets. * * Your Bitget account needs to be upgraded to unified account mode, to use the account-level WebSocket topics. */ export declare class WebsocketClientV3 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>[]; /** * Ensures the WS API connection is active and ready. * * You do not need to call this, but if you call this before making any WS API requests, * it can accelerate the first request (by preparing the connection in advance). */ connectWSAPI(): 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<TWSPayload extends { instType?: BitgetInstTypeV3; }>(requests: (WsTopicRequest<WsTopicV3, TWSPayload> | WsTopicV3) | (WsTopicRequest<WsTopicV3, TWSPayload> | WsTopicV3)[], 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<TWSPayload extends { instType?: BitgetInstTypeV3; }>(requests: (WsTopicRequest<WsTopicV3, TWSPayload> | WsTopicV3) | (WsTopicRequest<WsTopicV3, TWSPayload> | WsTopicV3)[], 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[]; /** * V3/UTA supports order placement via WebSockets. This is the WS API: * https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel * * @returns a promise that resolves/rejects when a matching response arrives */ sendWSAPIRequest<TWSKey extends keyof WsAPIWsKeyTopicMap, TWSOperation extends WsAPIWsKeyTopicMap[TWSKey], TWSParams extends WsAPITopicRequestParamMap[TWSOperation], TWSAPIResponse extends WsAPIOperationResponseMap[TWSOperation] = WsAPIOperationResponseMap[TWSOperation]>(wsKey: WsKey, operation: TWSOperation, category: BitgetInstTypeV3, params: TWSParams & { signRequest?: boolean; }, requestFlags?: WSAPIRequestFlags): Promise<TWSAPIResponse>; }