bitget-api 0.0.1 → 1.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 +85 -140
- package/lib/broker-client.d.ts +46 -0
- package/lib/broker-client.js +113 -0
- package/lib/broker-client.js.map +1 -0
- package/lib/constants/enum.d.ts +17 -0
- package/lib/constants/enum.js +21 -0
- package/lib/constants/enum.js.map +1 -0
- package/lib/futures-client.d.ts +146 -0
- package/lib/futures-client.js +380 -0
- package/lib/futures-client.js.map +1 -0
- package/lib/index.d.ts +8 -1
- package/lib/index.js +22 -13
- package/lib/index.js.map +1 -1
- package/lib/spot-client.d.ts +109 -0
- package/lib/spot-client.js +201 -0
- package/lib/spot-client.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.js +21 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/request/broker.d.ts +23 -0
- package/lib/types/request/broker.js +3 -0
- package/lib/types/request/broker.js.map +1 -0
- package/lib/types/request/futures.d.ts +114 -0
- package/lib/types/request/futures.js +3 -0
- package/lib/types/request/futures.js.map +1 -0
- package/lib/types/request/index.d.ts +4 -0
- package/lib/types/request/index.js +21 -0
- package/lib/types/request/index.js.map +1 -0
- package/lib/types/request/shared.d.ts +10 -0
- package/lib/types/request/shared.js +3 -0
- package/lib/types/request/shared.js.map +1 -0
- package/lib/types/request/spot.d.ts +19 -0
- package/lib/types/request/spot.js +3 -0
- package/lib/types/request/spot.js.map +1 -0
- package/lib/types/response/futures.d.ts +55 -0
- package/lib/types/response/futures.js +3 -0
- package/lib/types/response/futures.js.map +1 -0
- package/lib/types/response/index.d.ts +3 -0
- package/lib/types/response/index.js +20 -0
- package/lib/types/response/index.js.map +1 -0
- package/lib/types/response/shared.d.ts +6 -0
- package/lib/types/response/shared.js +3 -0
- package/lib/types/response/shared.js.map +1 -0
- package/lib/types/response/spot.d.ts +21 -0
- package/lib/types/response/spot.js +3 -0
- package/lib/types/response/spot.js.map +1 -0
- package/lib/types/shared.d.ts +5 -0
- package/lib/types/shared.js +3 -0
- package/lib/types/shared.js.map +1 -0
- package/lib/types/websockets/client.d.ts +37 -0
- package/lib/types/websockets/client.js +3 -0
- package/lib/types/websockets/client.js.map +1 -0
- package/lib/types/websockets/events.d.ts +75 -0
- package/lib/types/websockets/events.js +3 -0
- package/lib/types/websockets/events.js.map +1 -0
- package/lib/types/websockets/index.d.ts +2 -0
- package/lib/types/websockets/index.js +19 -0
- package/lib/types/websockets/index.js.map +1 -0
- package/lib/util/BaseRestClient.d.ts +40 -0
- package/lib/util/BaseRestClient.js +195 -0
- package/lib/util/BaseRestClient.js.map +1 -0
- package/lib/util/WsStore.d.ts +62 -0
- package/lib/util/WsStore.js +135 -0
- package/lib/util/WsStore.js.map +1 -0
- package/lib/util/browser-support.d.ts +1 -0
- package/lib/util/browser-support.js +44 -0
- package/lib/util/browser-support.js.map +1 -0
- package/lib/util/index.d.ts +6 -0
- package/lib/util/index.js +23 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/logger.d.ts +9 -0
- package/lib/util/logger.js +24 -0
- package/lib/util/logger.js.map +1 -0
- package/lib/util/node-support.d.ts +2 -0
- package/lib/util/node-support.js +33 -0
- package/lib/util/node-support.js.map +1 -0
- package/lib/util/requestUtils.d.ts +31 -0
- package/lib/util/requestUtils.js +53 -0
- package/lib/util/requestUtils.js.map +1 -0
- package/lib/util/type-guards.d.ts +9 -0
- package/lib/util/type-guards.js +50 -0
- package/lib/util/type-guards.js.map +1 -0
- package/lib/util/websocket-util.d.ts +38 -0
- package/lib/util/websocket-util.js +100 -0
- package/lib/util/websocket-util.js.map +1 -0
- package/lib/websocket-client.d.ts +121 -0
- package/lib/websocket-client.js +442 -0
- package/lib/websocket-client.js.map +1 -0
- package/package.json +16 -16
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WebsocketClient = void 0;
|
|
16
|
+
const events_1 = require("events");
|
|
17
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
18
|
+
const WsStore_1 = __importDefault(require("./util/WsStore"));
|
|
19
|
+
const util_1 = require("./util");
|
|
20
|
+
const LOGGER_CATEGORY = { category: 'bitget-ws' };
|
|
21
|
+
class WebsocketClient extends events_1.EventEmitter {
|
|
22
|
+
constructor(options, logger) {
|
|
23
|
+
super();
|
|
24
|
+
this.logger = logger || util_1.DefaultLogger;
|
|
25
|
+
this.wsStore = new WsStore_1.default(this.logger);
|
|
26
|
+
this.options = Object.assign({ pongTimeout: 1000, pingInterval: 10000, reconnectTimeout: 500, recvWindow: 0 }, options);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to topics & track/persist them. They will be automatically resubscribed to if the connection drops/reconnects.
|
|
30
|
+
* @param wsTopics topic or list of topics
|
|
31
|
+
* @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)
|
|
32
|
+
*/
|
|
33
|
+
subscribe(wsTopics, isPrivateTopic) {
|
|
34
|
+
const topics = Array.isArray(wsTopics) ? wsTopics : [wsTopics];
|
|
35
|
+
topics.forEach((topic) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const wsKey = (0, util_1.getWsKeyForTopic)(topic, isPrivateTopic);
|
|
38
|
+
// Persist this topic to the expected topics list
|
|
39
|
+
this.wsStore.addTopic(wsKey, topic);
|
|
40
|
+
// TODO: tidy up unsubscribe too, also in other connectors
|
|
41
|
+
// if connected, send subscription request
|
|
42
|
+
if (this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.CONNECTED)) {
|
|
43
|
+
// if not authenticated, dont sub to private topics yet.
|
|
44
|
+
// This'll happen automatically once authenticated
|
|
45
|
+
const isAuthenticated = (_a = this.wsStore.get(wsKey)) === null || _a === void 0 ? void 0 : _a.isAuthenticated;
|
|
46
|
+
if (!isAuthenticated) {
|
|
47
|
+
return this.requestSubscribeTopics(wsKey, topics.filter((topic) => !(0, util_1.isPrivateChannel)(topic.channel)));
|
|
48
|
+
}
|
|
49
|
+
return this.requestSubscribeTopics(wsKey, topics);
|
|
50
|
+
}
|
|
51
|
+
// start connection process if it hasn't yet begun. Topics are automatically subscribed to on-connect
|
|
52
|
+
if (!this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.CONNECTING) &&
|
|
53
|
+
!this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.RECONNECTING)) {
|
|
54
|
+
return this.connect(wsKey);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Unsubscribe from topics & remove them from memory. They won't be re-subscribed to if the connection reconnects.
|
|
60
|
+
* @param wsTopics topic or list of topics
|
|
61
|
+
* @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)
|
|
62
|
+
*/
|
|
63
|
+
unsubscribe(wsTopics, isPrivateTopic) {
|
|
64
|
+
const topics = Array.isArray(wsTopics) ? wsTopics : [wsTopics];
|
|
65
|
+
topics.forEach((topic) => this.wsStore.deleteTopic((0, util_1.getWsKeyForTopic)(topic, isPrivateTopic), topic));
|
|
66
|
+
// TODO: should this really happen on each wsKey?? seems weird
|
|
67
|
+
this.wsStore.getKeys().forEach((wsKey) => {
|
|
68
|
+
// unsubscribe request only necessary if active connection exists
|
|
69
|
+
if (this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.CONNECTED)) {
|
|
70
|
+
this.requestUnsubscribeTopics(wsKey, topics);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** Get the WsStore that tracks websockets & topics */
|
|
75
|
+
getWsStore() {
|
|
76
|
+
return this.wsStore;
|
|
77
|
+
}
|
|
78
|
+
close(wsKey, force) {
|
|
79
|
+
this.logger.info('Closing connection', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
80
|
+
this.setWsState(wsKey, util_1.WsConnectionStateEnum.CLOSING);
|
|
81
|
+
this.clearTimers(wsKey);
|
|
82
|
+
const ws = this.getWs(wsKey);
|
|
83
|
+
ws === null || ws === void 0 ? void 0 : ws.close();
|
|
84
|
+
if (force) {
|
|
85
|
+
ws === null || ws === void 0 ? void 0 : ws.terminate();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
closeAll(force) {
|
|
89
|
+
this.wsStore.getKeys().forEach((key) => {
|
|
90
|
+
this.close(key, force);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
|
|
95
|
+
*/
|
|
96
|
+
connectAll() {
|
|
97
|
+
return [this.connect(util_1.WS_KEY_MAP.spotv1), this.connect(util_1.WS_KEY_MAP.mixv1)];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Request connection to a specific websocket, instead of waiting for automatic connection.
|
|
101
|
+
*/
|
|
102
|
+
connect(wsKey) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
try {
|
|
105
|
+
if (this.wsStore.isWsOpen(wsKey)) {
|
|
106
|
+
this.logger.error('Refused to connect to ws with existing active connection', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
107
|
+
return this.wsStore.getWs(wsKey);
|
|
108
|
+
}
|
|
109
|
+
if (this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.CONNECTING)) {
|
|
110
|
+
this.logger.error('Refused to connect to ws, connection attempt already active', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!this.wsStore.getConnectionState(wsKey) ||
|
|
114
|
+
this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.INITIAL)) {
|
|
115
|
+
this.setWsState(wsKey, util_1.WsConnectionStateEnum.CONNECTING);
|
|
116
|
+
}
|
|
117
|
+
const url = this.getWsUrl(wsKey); // + authParams;
|
|
118
|
+
const ws = this.connectToWsUrl(url, wsKey);
|
|
119
|
+
return this.wsStore.setWs(wsKey, ws);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
this.parseWsError('Connection failed', err, wsKey);
|
|
123
|
+
this.reconnectWithDelay(wsKey, this.options.reconnectTimeout);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
parseWsError(context, error, wsKey) {
|
|
128
|
+
if (!error.message) {
|
|
129
|
+
this.logger.error(`${context} due to unexpected error: `, error);
|
|
130
|
+
this.emit('response', Object.assign(Object.assign({}, error), { wsKey }));
|
|
131
|
+
this.emit('exception', Object.assign(Object.assign({}, error), { wsKey }));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
switch (error.message) {
|
|
135
|
+
case 'Unexpected server response: 401':
|
|
136
|
+
this.logger.error(`${context} due to 401 authorization failure.`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
137
|
+
break;
|
|
138
|
+
default:
|
|
139
|
+
this.logger.error(`${context} due to unexpected response error: "${(error === null || error === void 0 ? void 0 : error.msg) || (error === null || error === void 0 ? void 0 : error.message) || error}"`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey, error }));
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
this.emit('response', Object.assign(Object.assign({}, error), { wsKey }));
|
|
143
|
+
this.emit('exception', Object.assign(Object.assign({}, error), { wsKey }));
|
|
144
|
+
}
|
|
145
|
+
/** Get a signature, build the auth request and send it */
|
|
146
|
+
sendAuthRequest(wsKey) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
try {
|
|
149
|
+
const { apiKey, apiSecret, apiPass, recvWindow } = this.options;
|
|
150
|
+
const { signature, expiresAt } = yield (0, util_1.getWsAuthSignature)(apiKey, apiSecret, apiPass, recvWindow);
|
|
151
|
+
this.logger.info(`Sending auth request...`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
152
|
+
const request = {
|
|
153
|
+
op: 'login',
|
|
154
|
+
args: [
|
|
155
|
+
{
|
|
156
|
+
apiKey: this.options.apiKey,
|
|
157
|
+
passphrase: this.options.apiPass,
|
|
158
|
+
timestamp: expiresAt,
|
|
159
|
+
sign: signature,
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
// console.log('ws auth req', request);
|
|
164
|
+
return this.tryWsSend(wsKey, JSON.stringify(request));
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
this.logger.silly(e, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
reconnectWithDelay(wsKey, connectionDelayMs) {
|
|
172
|
+
this.clearTimers(wsKey);
|
|
173
|
+
if (this.wsStore.getConnectionState(wsKey) !==
|
|
174
|
+
util_1.WsConnectionStateEnum.CONNECTING) {
|
|
175
|
+
this.setWsState(wsKey, util_1.WsConnectionStateEnum.RECONNECTING);
|
|
176
|
+
}
|
|
177
|
+
this.wsStore.get(wsKey, true).activeReconnectTimer = setTimeout(() => {
|
|
178
|
+
this.logger.info('Reconnecting to websocket', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
179
|
+
this.connect(wsKey);
|
|
180
|
+
}, connectionDelayMs);
|
|
181
|
+
}
|
|
182
|
+
ping(wsKey) {
|
|
183
|
+
if (this.wsStore.get(wsKey, true).activePongTimer) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.clearPongTimer(wsKey);
|
|
187
|
+
this.logger.silly('Sending ping', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
188
|
+
this.tryWsSend(wsKey, JSON.stringify({ op: 'ping' }));
|
|
189
|
+
this.wsStore.get(wsKey, true).activePongTimer = setTimeout(() => {
|
|
190
|
+
var _a;
|
|
191
|
+
this.logger.info('Pong timeout - closing socket to reconnect', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
192
|
+
(_a = this.getWs(wsKey)) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
193
|
+
delete this.wsStore.get(wsKey, true).activePongTimer;
|
|
194
|
+
}, this.options.pongTimeout);
|
|
195
|
+
}
|
|
196
|
+
clearTimers(wsKey) {
|
|
197
|
+
this.clearPingTimer(wsKey);
|
|
198
|
+
this.clearPongTimer(wsKey);
|
|
199
|
+
const wsState = this.wsStore.get(wsKey);
|
|
200
|
+
if (wsState === null || wsState === void 0 ? void 0 : wsState.activeReconnectTimer) {
|
|
201
|
+
clearTimeout(wsState.activeReconnectTimer);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Send a ping at intervals
|
|
205
|
+
clearPingTimer(wsKey) {
|
|
206
|
+
const wsState = this.wsStore.get(wsKey);
|
|
207
|
+
if (wsState === null || wsState === void 0 ? void 0 : wsState.activePingTimer) {
|
|
208
|
+
clearInterval(wsState.activePingTimer);
|
|
209
|
+
wsState.activePingTimer = undefined;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Expect a pong within a time limit
|
|
213
|
+
clearPongTimer(wsKey) {
|
|
214
|
+
const wsState = this.wsStore.get(wsKey);
|
|
215
|
+
if (wsState === null || wsState === void 0 ? void 0 : wsState.activePongTimer) {
|
|
216
|
+
clearTimeout(wsState.activePongTimer);
|
|
217
|
+
wsState.activePongTimer = undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @private Use the `subscribe(topics)` method to subscribe to topics. Send WS message to subscribe to topics.
|
|
222
|
+
*/
|
|
223
|
+
requestSubscribeTopics(wsKey, topics) {
|
|
224
|
+
if (!topics.length) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const maxTopicsPerEvent = (0, util_1.getMaxTopicsPerSubscribeEvent)(wsKey);
|
|
228
|
+
if (maxTopicsPerEvent && topics.length > maxTopicsPerEvent) {
|
|
229
|
+
this.logger.silly(`Subscribing to topics in batches of ${maxTopicsPerEvent}`);
|
|
230
|
+
for (var i = 0; i < topics.length; i += maxTopicsPerEvent) {
|
|
231
|
+
const batch = topics.slice(i, i + maxTopicsPerEvent);
|
|
232
|
+
this.logger.silly(`Subscribing to batch of ${batch.length}`);
|
|
233
|
+
this.requestSubscribeTopics(wsKey, batch);
|
|
234
|
+
}
|
|
235
|
+
this.logger.silly(`Finished batch subscribing to ${topics.length} topics`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const wsMessage = JSON.stringify({
|
|
239
|
+
op: 'subscribe',
|
|
240
|
+
args: topics,
|
|
241
|
+
});
|
|
242
|
+
this.tryWsSend(wsKey, wsMessage);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics.
|
|
246
|
+
*/
|
|
247
|
+
requestUnsubscribeTopics(wsKey, topics) {
|
|
248
|
+
if (!topics.length) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const maxTopicsPerEvent = (0, util_1.getMaxTopicsPerSubscribeEvent)(wsKey);
|
|
252
|
+
if (maxTopicsPerEvent && topics.length > maxTopicsPerEvent) {
|
|
253
|
+
this.logger.silly(`Unsubscribing to topics in batches of ${maxTopicsPerEvent}`);
|
|
254
|
+
for (var i = 0; i < topics.length; i += maxTopicsPerEvent) {
|
|
255
|
+
const batch = topics.slice(i, i + maxTopicsPerEvent);
|
|
256
|
+
this.logger.silly(`Unsubscribing to batch of ${batch.length}`);
|
|
257
|
+
this.requestUnsubscribeTopics(wsKey, batch);
|
|
258
|
+
}
|
|
259
|
+
this.logger.silly(`Finished batch unsubscribing to ${topics.length} topics`);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const wsMessage = JSON.stringify({
|
|
263
|
+
op: 'unsubscribe',
|
|
264
|
+
args: topics,
|
|
265
|
+
});
|
|
266
|
+
this.tryWsSend(wsKey, wsMessage);
|
|
267
|
+
}
|
|
268
|
+
tryWsSend(wsKey, wsMessage) {
|
|
269
|
+
try {
|
|
270
|
+
this.logger.silly(`Sending upstream ws message: `, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsMessage,
|
|
271
|
+
wsKey }));
|
|
272
|
+
if (!wsKey) {
|
|
273
|
+
throw new Error('Cannot send message due to no known websocket for this wsKey');
|
|
274
|
+
}
|
|
275
|
+
const ws = this.getWs(wsKey);
|
|
276
|
+
if (!ws) {
|
|
277
|
+
throw new Error(`${wsKey} socket not connected yet, call "connectAll()" first then try again when the "open" event arrives`);
|
|
278
|
+
}
|
|
279
|
+
ws.send(wsMessage);
|
|
280
|
+
}
|
|
281
|
+
catch (e) {
|
|
282
|
+
this.logger.error(`Failed to send WS message`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsMessage,
|
|
283
|
+
wsKey, exception: e }));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
connectToWsUrl(url, wsKey) {
|
|
287
|
+
var _a;
|
|
288
|
+
this.logger.silly(`Opening WS connection to URL: ${url}`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
289
|
+
const agent = (_a = this.options.requestOptions) === null || _a === void 0 ? void 0 : _a.agent;
|
|
290
|
+
const ws = new isomorphic_ws_1.default(url, undefined, agent ? { agent } : undefined);
|
|
291
|
+
ws.onopen = (event) => this.onWsOpen(event, wsKey);
|
|
292
|
+
ws.onmessage = (event) => this.onWsMessage(event, wsKey);
|
|
293
|
+
ws.onerror = (event) => this.parseWsError('websocket error', event, wsKey);
|
|
294
|
+
ws.onclose = (event) => this.onWsClose(event, wsKey);
|
|
295
|
+
return ws;
|
|
296
|
+
}
|
|
297
|
+
onWsOpen(event, wsKey) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
if (this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.CONNECTING)) {
|
|
300
|
+
this.logger.info('Websocket connected', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
301
|
+
this.emit('open', { wsKey, event });
|
|
302
|
+
}
|
|
303
|
+
else if (this.wsStore.isConnectionState(wsKey, util_1.WsConnectionStateEnum.RECONNECTING)) {
|
|
304
|
+
this.logger.info('Websocket reconnected', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
305
|
+
this.emit('reconnected', { wsKey, event });
|
|
306
|
+
}
|
|
307
|
+
this.setWsState(wsKey, util_1.WsConnectionStateEnum.CONNECTED);
|
|
308
|
+
// Some websockets require an auth packet to be sent after opening the connection
|
|
309
|
+
if (util_1.WS_AUTH_ON_CONNECT_KEYS.includes(wsKey)) {
|
|
310
|
+
yield this.sendAuthRequest(wsKey);
|
|
311
|
+
}
|
|
312
|
+
// Reconnect to topics known before it connected
|
|
313
|
+
// Private topics will be resubscribed to once reconnected
|
|
314
|
+
const topics = [...this.wsStore.getTopics(wsKey)];
|
|
315
|
+
const publicTopics = topics.filter((topic) => !(0, util_1.isPrivateChannel)(topic.channel));
|
|
316
|
+
this.requestSubscribeTopics(wsKey, publicTopics);
|
|
317
|
+
this.wsStore.get(wsKey, true).activePingTimer = setInterval(() => this.ping(wsKey), this.options.pingInterval);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/** Handle subscription to private topics _after_ authentication successfully completes asynchronously */
|
|
321
|
+
onWsAuthenticated(wsKey) {
|
|
322
|
+
const wsState = this.wsStore.get(wsKey, true);
|
|
323
|
+
wsState.isAuthenticated = true;
|
|
324
|
+
const topics = [...this.wsStore.getTopics(wsKey)];
|
|
325
|
+
const privateTopics = topics.filter((topic) => (0, util_1.isPrivateChannel)(topic.channel));
|
|
326
|
+
if (privateTopics.length) {
|
|
327
|
+
this.subscribe(privateTopics, true);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
onWsMessage(event, wsKey) {
|
|
331
|
+
try {
|
|
332
|
+
// any message can clear the pong timer - wouldn't get a message if the ws wasn't working
|
|
333
|
+
this.clearPongTimer(wsKey);
|
|
334
|
+
if ((0, util_1.isWsPong)(event)) {
|
|
335
|
+
this.logger.silly('Received pong', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const msg = JSON.parse((event && event['data']) || event);
|
|
339
|
+
const emittableEvent = Object.assign(Object.assign({}, msg), { wsKey });
|
|
340
|
+
if (typeof msg === 'object') {
|
|
341
|
+
if (typeof msg['code'] === 'number') {
|
|
342
|
+
if (msg.event === 'login' && msg.code === 0) {
|
|
343
|
+
this.logger.info(`Successfully authenticated WS client`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
344
|
+
this.emit('response', emittableEvent);
|
|
345
|
+
this.emit('authenticated', emittableEvent);
|
|
346
|
+
this.onWsAuthenticated(wsKey);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (msg['event']) {
|
|
351
|
+
if (msg.event === 'error') {
|
|
352
|
+
this.logger.error(`WS Error received`, Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey, message: msg || 'no message',
|
|
353
|
+
// messageType: typeof msg,
|
|
354
|
+
// messageString: JSON.stringify(msg),
|
|
355
|
+
event }));
|
|
356
|
+
this.emit('exception', emittableEvent);
|
|
357
|
+
this.emit('response', emittableEvent);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
return this.emit('response', emittableEvent);
|
|
361
|
+
}
|
|
362
|
+
if (msg['arg']) {
|
|
363
|
+
return this.emit('update', emittableEvent);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
this.logger.warning('Unhandled/unrecognised ws event message', Object.assign(Object.assign({}, LOGGER_CATEGORY), { message: msg || 'no message',
|
|
367
|
+
// messageType: typeof msg,
|
|
368
|
+
// messageString: JSON.stringify(msg),
|
|
369
|
+
event,
|
|
370
|
+
wsKey }));
|
|
371
|
+
// fallback emit anyway
|
|
372
|
+
return this.emit('update', emittableEvent);
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
this.logger.error('Failed to parse ws event message', Object.assign(Object.assign({}, LOGGER_CATEGORY), { error: e, event,
|
|
376
|
+
wsKey }));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
onWsClose(event, wsKey) {
|
|
380
|
+
this.logger.info('Websocket connection closed', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
381
|
+
if (this.wsStore.getConnectionState(wsKey) !== util_1.WsConnectionStateEnum.CLOSING) {
|
|
382
|
+
this.reconnectWithDelay(wsKey, this.options.reconnectTimeout);
|
|
383
|
+
this.emit('reconnect', { wsKey, event });
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
this.setWsState(wsKey, util_1.WsConnectionStateEnum.INITIAL);
|
|
387
|
+
this.emit('close', { wsKey, event });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
getWs(wsKey) {
|
|
391
|
+
return this.wsStore.getWs(wsKey);
|
|
392
|
+
}
|
|
393
|
+
setWsState(wsKey, state) {
|
|
394
|
+
this.wsStore.setConnectionState(wsKey, state);
|
|
395
|
+
}
|
|
396
|
+
getWsUrl(wsKey) {
|
|
397
|
+
if (this.options.wsUrl) {
|
|
398
|
+
return this.options.wsUrl;
|
|
399
|
+
}
|
|
400
|
+
const networkKey = 'livenet';
|
|
401
|
+
switch (wsKey) {
|
|
402
|
+
case util_1.WS_KEY_MAP.spotv1: {
|
|
403
|
+
return util_1.WS_BASE_URL_MAP.spotv1.all[networkKey];
|
|
404
|
+
}
|
|
405
|
+
case util_1.WS_KEY_MAP.mixv1: {
|
|
406
|
+
return util_1.WS_BASE_URL_MAP.mixv1.all[networkKey];
|
|
407
|
+
}
|
|
408
|
+
default: {
|
|
409
|
+
this.logger.error('getWsUrl(): Unhandled wsKey: ', Object.assign(Object.assign({}, LOGGER_CATEGORY), { wsKey }));
|
|
410
|
+
throw (0, util_1.neverGuard)(wsKey, `getWsUrl(): Unhandled wsKey`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Subscribe to a topic
|
|
416
|
+
* @param instType instrument type (refer to API docs).
|
|
417
|
+
* @param topic topic name (e.g. "ticker").
|
|
418
|
+
* @param instId instrument ID (e.g. "BTCUSDT"). Use "default" for private topics.
|
|
419
|
+
*/
|
|
420
|
+
subscribeTopic(instType, topic, instId = 'default') {
|
|
421
|
+
return this.subscribe({
|
|
422
|
+
instType,
|
|
423
|
+
instId,
|
|
424
|
+
channel: topic,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Unsubscribe from a topic
|
|
429
|
+
* @param instType instrument type (refer to API docs).
|
|
430
|
+
* @param topic topic name (e.g. "ticker").
|
|
431
|
+
* @param instId instrument ID (e.g. "BTCUSDT"). Use "default" for private topics to get all symbols.
|
|
432
|
+
*/
|
|
433
|
+
unsubscribeTopic(instType, topic, instId = 'default') {
|
|
434
|
+
return this.unsubscribe({
|
|
435
|
+
instType,
|
|
436
|
+
instId,
|
|
437
|
+
channel: topic,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
exports.WebsocketClient = WebsocketClient;
|
|
442
|
+
//# sourceMappingURL=websocket-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-client.js","sourceRoot":"","sources":["../src/websocket-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,kEAAsC;AAEtC,6DAGwB;AASxB,iCAYgB;AAEhB,MAAM,eAAe,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AA2ClD,MAAa,eAAgB,SAAQ,qBAAY;IAK/C,YACE,OAAoC,EACpC,MAA6B;QAE7B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,oBAAa,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAExC,IAAI,CAAC,OAAO,mBACV,WAAW,EAAE,IAAI,EACjB,YAAY,EAAE,KAAK,EACnB,gBAAgB,EAAE,GAAG,EACrB,UAAU,EAAE,CAAC,IACV,OAAO,CACX,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,SAAS,CACd,QAAiE,EACjE,cAAwB;QAExB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAE/D,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;;YACvB,MAAM,KAAK,GAAG,IAAA,uBAAgB,EAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YAEtD,iDAAiD;YACjD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAEpC,0DAA0D;YAE1D,0CAA0C;YAC1C,IACE,IAAI,CAAC,OAAO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AAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;aAC9C;YACD,OAAO,CAAC,CAAC;gBACP,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,kCAC5C,eAAe,KAClB,KAAK,IACL,CAAC;gBACH,MAAM,IAAA,iBAAU,EAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;aACxD;SACF;IACH,CAAC;IAED;;;;;OAKG;IACI,cAAc,CACnB,QAAwB,EACxB,KAAc,EACd,SAAiB,SAAS;QAE1B,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,QAAQ;YACR,MAAM;YACN,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,gBAAgB,CACrB,QAAwB,EACxB,KAAc,EACd,SAAiB,SAAS;QAE1B,OAAO,IAAI,CAAC,WAAW,CAAC;YACtB,QAAQ;YACR,MAAM;YACN,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC;CACF;AA7mBD,0CA6mBC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bitget-api",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & integration tests.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -22,22 +22,22 @@
|
|
|
22
22
|
"author": "Tiago Siebler (https://github.com/tiagosiebler)",
|
|
23
23
|
"contributors": [],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"axios": "^0.
|
|
26
|
-
"isomorphic-ws": "^
|
|
27
|
-
"ws": "^
|
|
25
|
+
"axios": "^0.27.2",
|
|
26
|
+
"isomorphic-ws": "^5.0.0",
|
|
27
|
+
"ws": "^8.9.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/jest": "^
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"eslint": "^
|
|
33
|
-
"jest": "^
|
|
34
|
-
"source-map-loader": "^
|
|
35
|
-
"ts-jest": "^
|
|
36
|
-
"ts-loader": "^
|
|
37
|
-
"typescript": "^4.
|
|
38
|
-
"webpack": "^5.
|
|
39
|
-
"webpack-bundle-analyzer": "^4.1
|
|
40
|
-
"webpack-cli": "^4.
|
|
30
|
+
"@types/jest": "^29.0.3",
|
|
31
|
+
"@types/node": "^18.7.23",
|
|
32
|
+
"eslint": "^8.24.0",
|
|
33
|
+
"jest": "^29.1.1",
|
|
34
|
+
"source-map-loader": "^4.0.0",
|
|
35
|
+
"ts-jest": "^29.0.2",
|
|
36
|
+
"ts-loader": "^9.4.1",
|
|
37
|
+
"typescript": "^4.8.4",
|
|
38
|
+
"webpack": "^5.74.0",
|
|
39
|
+
"webpack-bundle-analyzer": "^4.6.1",
|
|
40
|
+
"webpack-cli": "^4.10.0"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|
|
43
43
|
"bitget",
|