bitget-api 1.1.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -33
- package/lib/broker-client.d.ts +4 -1
- package/lib/broker-client.js +4 -1
- package/lib/broker-client.js.map +1 -1
- package/lib/futures-client.d.ts +4 -1
- package/lib/futures-client.js +4 -1
- package/lib/futures-client.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/rest-client-v2.d.ts +268 -0
- package/lib/rest-client-v2.js +573 -0
- package/lib/rest-client-v2.js.map +1 -0
- package/lib/spot-client.d.ts +4 -1
- package/lib/spot-client.js +4 -1
- package/lib/spot-client.js.map +1 -1
- package/lib/types/request/index.d.ts +5 -3
- package/lib/types/request/index.js +5 -3
- package/lib/types/request/index.js.map +1 -1
- package/lib/types/request/shared.d.ts +4 -0
- package/lib/types/request/v1/brokerV1.js +3 -0
- package/lib/types/request/v1/brokerV1.js.map +1 -0
- package/lib/types/request/{futures.d.ts → v1/futuresV1.d.ts} +1 -1
- package/lib/types/request/v1/futuresV1.js +3 -0
- package/lib/types/request/v1/futuresV1.js.map +1 -0
- package/lib/types/request/{spot.d.ts → v1/spotV1.d.ts} +1 -1
- package/lib/types/request/{broker.js → v1/spotV1.js} +1 -1
- package/lib/types/request/v1/spotV1.js.map +1 -0
- package/lib/types/request/v2/futures.d.ts +22 -0
- package/lib/types/request/v2/futures.js.map +1 -0
- package/lib/types/request/v2/spot.d.ts +8 -0
- package/lib/types/request/{spot.js.map → v2/spot.js.map} +1 -1
- package/lib/types/response/shared.d.ts +2 -2
- package/lib/types/websockets/client.d.ts +40 -1
- package/lib/util/BaseWSClient.d.ts +112 -0
- package/lib/util/BaseWSClient.js +395 -0
- package/lib/util/BaseWSClient.js.map +1 -0
- package/lib/util/WsStore.d.ts +10 -46
- package/lib/util/WsStore.js +2 -11
- package/lib/util/WsStore.js.map +1 -1
- package/lib/util/WsStore.types.d.ts +26 -0
- package/lib/util/WsStore.types.js +13 -0
- package/lib/util/WsStore.types.js.map +1 -0
- package/lib/util/requestUtils.d.ts +1 -0
- package/lib/util/requestUtils.js +1 -0
- package/lib/util/requestUtils.js.map +1 -1
- package/lib/util/type-guards.d.ts +5 -1
- package/lib/util/type-guards.js +11 -1
- package/lib/util/type-guards.js.map +1 -1
- package/lib/util/websocket-util.d.ts +5 -2
- package/lib/util/websocket-util.js +36 -3
- package/lib/util/websocket-util.js.map +1 -1
- package/lib/websocket-client-v2.d.ts +33 -0
- package/lib/websocket-client-v2.js +104 -0
- package/lib/websocket-client-v2.js.map +1 -0
- package/lib/websocket-client.d.ts +8 -2
- package/lib/websocket-client.js +27 -15
- package/lib/websocket-client.js.map +1 -1
- package/package.json +3 -3
- package/lib/types/request/broker.js.map +0 -1
- package/lib/types/request/futures.js.map +0 -1
- /package/lib/types/request/{broker.d.ts → v1/brokerV1.d.ts} +0 -0
- /package/lib/types/request/{futures.js → v2/futures.js} +0 -0
- /package/lib/types/request/{spot.js → v2/spot.js} +0 -0
|
@@ -14,8 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./v1/brokerV1"), exports);
|
|
18
|
+
__exportStar(require("./v1/futuresV1"), exports);
|
|
19
|
+
__exportStar(require("./v1/spotV1"), exports);
|
|
20
|
+
__exportStar(require("./v2/futures"), exports);
|
|
21
|
+
__exportStar(require("./v2/spot"), exports);
|
|
19
22
|
__exportStar(require("./shared"), exports);
|
|
20
|
-
__exportStar(require("./spot"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B;AAC/B,8CAA4B;AAC5B,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brokerV1.js","sourceRoot":"","sources":["../../../../src/types/request/v1/brokerV1.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderTimeInForce } from '
|
|
1
|
+
import { OrderTimeInForce } from '../shared';
|
|
2
2
|
export declare type FuturesProductType = 'umcbl' | 'dmcbl' | 'cmcbl' | 'sumcbl' | 'sdmcbl' | 'scmcbl';
|
|
3
3
|
export declare type FuturesKlineInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1H' | '2H' | '4H' | '6H' | '12H' | '1D' | '3D' | '1W' | '1M' | '6Hutc' | '12Hutc' | '1Dutc' | '3Dutc' | '1Wutc' | '1Mutc';
|
|
4
4
|
export declare type FuturesHoldSide = 'long' | 'short';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"futuresV1.js","sourceRoot":"","sources":["../../../../src/types/request/v1/futuresV1.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderTimeInForce } from '
|
|
1
|
+
import { OrderTimeInForce } from '../shared';
|
|
2
2
|
export declare type WalletType = 'spot' | 'mix_usdt' | 'mix_usd';
|
|
3
3
|
export declare type SpotKlineInterval = '1min' | '5min' | '15min' | '30min' | '1h' | '4h' | '6h' | '12h' | '1M' | '1W' | '1week' | '6Hutc' | '12Hutc' | '1Dutc' | '3Dutc' | '1Wutc' | '1Mutc';
|
|
4
4
|
export interface NewWalletTransfer {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spotV1.js","sourceRoot":"","sources":["../../../../src/types/request/v1/spotV1.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FuturesKlineInterval } from '../v1/futuresV1';
|
|
2
|
+
export declare type FuturesProductTypeV2 = 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES' | 'SUSDT-FUTURES' | 'SCOIN-FUTURES' | 'SUSDC-FUTURES';
|
|
3
|
+
export declare type FuturesKlineTypeV2 = 'MARKET' | 'MARK' | 'INDEX';
|
|
4
|
+
export interface FuturesAccountBillRequestV2 {
|
|
5
|
+
productType: FuturesProductTypeV2;
|
|
6
|
+
symbol?: string;
|
|
7
|
+
coin?: string;
|
|
8
|
+
businessType?: string;
|
|
9
|
+
idLessThan?: string;
|
|
10
|
+
startTime?: string;
|
|
11
|
+
endTime?: string;
|
|
12
|
+
limit?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface FuturesCandlesRequestV2 {
|
|
15
|
+
symbol: string;
|
|
16
|
+
productType: FuturesProductTypeV2;
|
|
17
|
+
granularity: FuturesKlineInterval;
|
|
18
|
+
startTime?: string;
|
|
19
|
+
endTime?: string;
|
|
20
|
+
kLineType?: FuturesKlineTypeV2;
|
|
21
|
+
limit?: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"futures.js","sourceRoot":"","sources":["../../../../src/types/request/v2/futures.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../../src/types/request/v2/spot.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { WS_KEY_MAP } from '../../util';
|
|
2
|
+
import { FuturesProductTypeV2 } from '../request';
|
|
3
|
+
/** A "topic" is always a string */
|
|
4
|
+
export declare type BitgetInstType = 'SP' | 'SPBL' | 'MC' | 'UMCBL' | 'DMCBL';
|
|
5
|
+
export declare type BitgetInstTypeV2 = 'SPOT' | FuturesProductTypeV2;
|
|
2
6
|
export declare type WsPublicSpotTopic = 'ticker' | 'candle1W' | 'candle1D' | 'candle12H' | 'candle4H' | 'candle1H' | 'candle30m' | 'candle15m' | 'candle5m' | 'candle1m' | 'books' | 'books5' | 'trade';
|
|
3
7
|
export declare type WsPublicFuturesTopic = WsPublicSpotTopic;
|
|
4
8
|
export declare type WsPrivateSpotTopic = 'account' | 'orders';
|
|
@@ -6,8 +10,43 @@ export declare type WsPrivateFuturesTopic = 'account' | 'positions' | 'orders' |
|
|
|
6
10
|
export declare type WsPublicTopic = WsPublicSpotTopic | WsPublicFuturesTopic;
|
|
7
11
|
export declare type WsPrivateTopic = WsPrivateSpotTopic | WsPrivateFuturesTopic;
|
|
8
12
|
export declare type WsTopic = WsPublicTopic | WsPrivateTopic;
|
|
13
|
+
export declare type WsPublicTopicV2 = 'index-price' | 'ticker' | 'candle1m' | 'candle5m' | 'candle15' | 'candle30m' | 'candle1H' | 'candle4H' | 'candle6H' | 'candle12H' | 'candle1D' | 'candle3D' | 'candle1W' | 'candle1M' | 'candle6Hutc' | 'candle12Hutc' | 'candle1Dutc' | 'candle3Dutc' | 'candle1Wutc' | 'candle1Mutc' | 'trade' | 'books' | 'books1' | 'books5' | 'books15';
|
|
14
|
+
export declare type WSPrivateTopicFuturesV2 = 'positions' | 'orders-algo' | 'positions-history';
|
|
15
|
+
export declare type WSPrivateTopicMarginV2 = 'orders-crossed' | 'account-crossed' | 'account-isolated' | 'orders-isolated';
|
|
16
|
+
export declare type WsPrivateTopicV2 = 'account' | 'orders' | WSPrivateTopicFuturesV2 | WSPrivateTopicMarginV2;
|
|
17
|
+
export declare type WsTopicV2 = WsPublicTopicV2 | WsPrivateTopicV2;
|
|
9
18
|
/** This is used to differentiate between each of the available websocket streams */
|
|
10
|
-
export declare type WsKey = typeof WS_KEY_MAP[keyof typeof WS_KEY_MAP];
|
|
19
|
+
export declare type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP];
|
|
20
|
+
/**
|
|
21
|
+
* Event args for subscribing/unsubscribing
|
|
22
|
+
*/
|
|
23
|
+
export interface WsTopicSubscribeEventArgs {
|
|
24
|
+
instType: BitgetInstType;
|
|
25
|
+
channel: WsTopic;
|
|
26
|
+
instId?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare type WsTopicSubscribePublicArgsV2 = {
|
|
29
|
+
instType: BitgetInstTypeV2;
|
|
30
|
+
channel: WsPublicTopicV2;
|
|
31
|
+
/** The symbol, e.g. "BTCUSDT" */
|
|
32
|
+
instId: string;
|
|
33
|
+
};
|
|
34
|
+
export declare type WsInstIdChannelsV2 = 'orders' | WSPrivateTopicFuturesV2 | 'orders-crossed' | 'orders-isolated';
|
|
35
|
+
export declare type WsTopicSubscribePrivateInstIdArgsV2 = {
|
|
36
|
+
instType: BitgetInstTypeV2;
|
|
37
|
+
channel: WsInstIdChannelsV2;
|
|
38
|
+
/** The symbol, e.g. "BTCUSDT" */
|
|
39
|
+
instId?: string;
|
|
40
|
+
};
|
|
41
|
+
export declare type WsCoinChannelsV2 = 'account' | 'account-crossed' | 'account-isolated';
|
|
42
|
+
export declare type WsTopicSubscribePrivateCoinArgsV2 = {
|
|
43
|
+
instType: BitgetInstTypeV2;
|
|
44
|
+
channel: WsCoinChannelsV2;
|
|
45
|
+
coin: 'default' | string;
|
|
46
|
+
};
|
|
47
|
+
export declare type WsTopicSubscribePrivateArgsV2 = WsTopicSubscribePrivateInstIdArgsV2 | WsTopicSubscribePrivateCoinArgsV2;
|
|
48
|
+
export declare type WsTopicSubscribeEventArgsV2 = WsTopicSubscribePublicArgsV2 | WsTopicSubscribePrivateArgsV2;
|
|
49
|
+
/** General configuration for the WebsocketClient */
|
|
11
50
|
export interface WSClientConfigurableOptions {
|
|
12
51
|
/** Your API key */
|
|
13
52
|
apiKey?: string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import WebSocket from 'isomorphic-ws';
|
|
4
|
+
import { WebsocketClientOptions, WSClientConfigurableOptions } from '../types';
|
|
5
|
+
import WsStore from './WsStore';
|
|
6
|
+
import { DefaultLogger } from './logger';
|
|
7
|
+
interface WSClientEventMap<WsKey extends string> {
|
|
8
|
+
/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
|
|
9
|
+
open: (evt: {
|
|
10
|
+
wsKey: WsKey;
|
|
11
|
+
event: any;
|
|
12
|
+
}) => void;
|
|
13
|
+
/** Reconnecting a dropped connection */
|
|
14
|
+
reconnect: (evt: {
|
|
15
|
+
wsKey: WsKey;
|
|
16
|
+
event: any;
|
|
17
|
+
}) => void;
|
|
18
|
+
/** Successfully reconnected a connection that dropped */
|
|
19
|
+
reconnected: (evt: {
|
|
20
|
+
wsKey: WsKey;
|
|
21
|
+
event: any;
|
|
22
|
+
}) => void;
|
|
23
|
+
/** Connection closed */
|
|
24
|
+
close: (evt: {
|
|
25
|
+
wsKey: WsKey;
|
|
26
|
+
event: any;
|
|
27
|
+
}) => void;
|
|
28
|
+
/** Received reply to websocket command (e.g. after subscribing to topics) */
|
|
29
|
+
response: (response: any & {
|
|
30
|
+
wsKey: WsKey;
|
|
31
|
+
}) => void;
|
|
32
|
+
/** Received data for topic */
|
|
33
|
+
update: (response: any & {
|
|
34
|
+
wsKey: WsKey;
|
|
35
|
+
}) => void;
|
|
36
|
+
/** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
|
|
37
|
+
exception: (response: any & {
|
|
38
|
+
wsKey: WsKey;
|
|
39
|
+
}) => void;
|
|
40
|
+
/** Confirmation that a connection successfully authenticated */
|
|
41
|
+
authenticated: (event: {
|
|
42
|
+
wsKey: WsKey;
|
|
43
|
+
event: any;
|
|
44
|
+
}) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface BaseWebsocketClient<TWSKey extends string, TWSTopicSubscribeEventArgs extends object> {
|
|
47
|
+
on<U extends keyof WSClientEventMap<TWSKey>>(event: U, listener: WSClientEventMap<TWSKey>[U]): this;
|
|
48
|
+
emit<U extends keyof WSClientEventMap<TWSKey>>(event: U, ...args: Parameters<WSClientEventMap<TWSKey>[U]>): boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface BaseWSClientImpl {
|
|
51
|
+
}
|
|
52
|
+
export declare abstract class BaseWebsocketClient<TWSKey extends string, TWSTopicSubscribeEventArgs extends object> extends EventEmitter {
|
|
53
|
+
private wsStore;
|
|
54
|
+
protected logger: typeof DefaultLogger;
|
|
55
|
+
protected options: WebsocketClientOptions;
|
|
56
|
+
constructor(options: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
|
|
57
|
+
protected abstract getWsKeyForTopic(subscribeEvent: TWSTopicSubscribeEventArgs, isPrivate?: boolean): TWSKey;
|
|
58
|
+
protected abstract isPrivateChannel(subscribeEvent: TWSTopicSubscribeEventArgs): boolean;
|
|
59
|
+
protected abstract shouldAuthOnConnect(wsKey: TWSKey): boolean;
|
|
60
|
+
protected abstract getWsUrl(wsKey: TWSKey): string;
|
|
61
|
+
protected abstract getMaxTopicsPerSubscribeEvent(wsKey: TWSKey): number | null;
|
|
62
|
+
/**
|
|
63
|
+
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
|
|
64
|
+
*/
|
|
65
|
+
abstract connectAll(): Promise<WebSocket | undefined>[];
|
|
66
|
+
/**
|
|
67
|
+
* Subscribe to topics & track/persist them. They will be automatically resubscribed to if the connection drops/reconnects.
|
|
68
|
+
* @param wsTopics topic or list of topics
|
|
69
|
+
* @param isPrivateTopic optional - the library will try to detect private topics, you can use this to mark a topic as private (if the topic isn't recognised yet)
|
|
70
|
+
*/
|
|
71
|
+
subscribe(wsTopics: TWSTopicSubscribeEventArgs[] | TWSTopicSubscribeEventArgs, isPrivateTopic?: boolean): void;
|
|
72
|
+
/**
|
|
73
|
+
* Unsubscribe from topics & remove them from memory. They won't be re-subscribed to if the connection reconnects.
|
|
74
|
+
* @param wsTopics topic or list of topics
|
|
75
|
+
* @param isPrivateTopic optional - the library will try to detect private topics, you can use this to mark a topic as private (if the topic isn't recognised yet)
|
|
76
|
+
*/
|
|
77
|
+
unsubscribe(wsTopics: TWSTopicSubscribeEventArgs[] | TWSTopicSubscribeEventArgs, isPrivateTopic?: boolean): void;
|
|
78
|
+
/** Get the WsStore that tracks websockets & topics */
|
|
79
|
+
getWsStore(): WsStore<TWSKey, TWSTopicSubscribeEventArgs>;
|
|
80
|
+
close(wsKey: TWSKey, force?: boolean): void;
|
|
81
|
+
closeAll(force?: boolean): void;
|
|
82
|
+
/**
|
|
83
|
+
* Request connection to a specific websocket, instead of waiting for automatic connection.
|
|
84
|
+
*/
|
|
85
|
+
protected connect(wsKey: TWSKey): Promise<WebSocket | undefined>;
|
|
86
|
+
private parseWsError;
|
|
87
|
+
/** Get a signature, build the auth request and send it */
|
|
88
|
+
private sendAuthRequest;
|
|
89
|
+
private reconnectWithDelay;
|
|
90
|
+
private ping;
|
|
91
|
+
private clearTimers;
|
|
92
|
+
private clearPingTimer;
|
|
93
|
+
private clearPongTimer;
|
|
94
|
+
/**
|
|
95
|
+
* @private Use the `subscribe(topics)` method to subscribe to topics. Send WS message to subscribe to topics.
|
|
96
|
+
*/
|
|
97
|
+
private requestSubscribeTopics;
|
|
98
|
+
/**
|
|
99
|
+
* @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics.
|
|
100
|
+
*/
|
|
101
|
+
private requestUnsubscribeTopics;
|
|
102
|
+
tryWsSend(wsKey: TWSKey, wsMessage: string): void;
|
|
103
|
+
private connectToWsUrl;
|
|
104
|
+
private onWsOpen;
|
|
105
|
+
/** Handle subscription to private topics _after_ authentication successfully completes asynchronously */
|
|
106
|
+
private onWsAuthenticated;
|
|
107
|
+
private onWsMessage;
|
|
108
|
+
private onWsClose;
|
|
109
|
+
private getWs;
|
|
110
|
+
private setWsState;
|
|
111
|
+
}
|
|
112
|
+
export {};
|