bybit-api 3.10.30 → 4.0.0-beta.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.
Files changed (146) hide show
  1. package/README.md +301 -178
  2. package/lib/index.d.ts +0 -11
  3. package/lib/index.js +0 -11
  4. package/lib/index.js.map +1 -1
  5. package/lib/rest-client-v5.d.ts +1 -1
  6. package/lib/rest-client-v5.js +1 -1
  7. package/lib/spot-client-v3.d.ts +8 -81
  8. package/lib/spot-client-v3.js +7 -172
  9. package/lib/spot-client-v3.js.map +1 -1
  10. package/lib/types/index.d.ts +1 -2
  11. package/lib/types/index.js +1 -2
  12. package/lib/types/index.js.map +1 -1
  13. package/lib/types/request/index.d.ts +0 -1
  14. package/lib/types/request/index.js +0 -1
  15. package/lib/types/request/index.js.map +1 -1
  16. package/lib/types/request/v5-account.d.ts +1 -1
  17. package/lib/types/request/v5-asset.d.ts +1 -1
  18. package/lib/types/request/v5-market.d.ts +1 -1
  19. package/lib/types/request/v5-position.d.ts +1 -1
  20. package/lib/types/request/v5-pre-upgrade.d.ts +1 -1
  21. package/lib/types/request/v5-spot-leverage-token.d.ts +1 -1
  22. package/lib/types/request/v5-trade.d.ts +1 -1
  23. package/lib/types/request/v5-user.d.ts +1 -1
  24. package/lib/types/response/v5-account.d.ts +1 -1
  25. package/lib/types/response/v5-asset.d.ts +1 -1
  26. package/lib/types/response/v5-market.d.ts +1 -1
  27. package/lib/types/response/v5-position.d.ts +1 -1
  28. package/lib/types/response/v5-spot-leverage-token.d.ts +1 -1
  29. package/lib/types/response/v5-trade.d.ts +1 -1
  30. package/lib/types/response/v5-user.d.ts +1 -1
  31. package/lib/types/{request/spot.js → shared-v5.js} +1 -1
  32. package/lib/types/shared-v5.js.map +1 -0
  33. package/lib/types/shared.d.ts +1 -19
  34. package/lib/types/websockets/index.d.ts +3 -0
  35. package/lib/types/websockets/index.js +20 -0
  36. package/lib/types/websockets/index.js.map +1 -0
  37. package/lib/types/websockets/ws-api.d.ts +73 -0
  38. package/lib/types/websockets/ws-api.js +10 -0
  39. package/lib/types/websockets/ws-api.js.map +1 -0
  40. package/lib/types/websockets/ws-confirmations.d.ts +13 -0
  41. package/lib/types/{websocket.events.js → websockets/ws-confirmations.js} +1 -1
  42. package/lib/types/websockets/ws-confirmations.js.map +1 -0
  43. package/lib/types/{websocket.events.d.ts → websockets/ws-events.d.ts} +9 -3
  44. package/lib/types/websockets/ws-events.js +11 -0
  45. package/lib/types/websockets/ws-events.js.map +1 -0
  46. package/lib/types/{websockets.d.ts → websockets/ws-general.d.ts} +35 -10
  47. package/lib/types/{v5-shared.js → websockets/ws-general.js} +1 -1
  48. package/lib/types/websockets/ws-general.js.map +1 -0
  49. package/lib/util/BaseRestClient.d.ts +1 -1
  50. package/lib/util/BaseRestClient.js +15 -39
  51. package/lib/util/BaseRestClient.js.map +1 -1
  52. package/lib/util/BaseWSClient.d.ts +221 -0
  53. package/lib/util/BaseWSClient.js +733 -0
  54. package/lib/util/BaseWSClient.js.map +1 -0
  55. package/lib/util/index.d.ts +1 -2
  56. package/lib/util/index.js +1 -2
  57. package/lib/util/index.js.map +1 -1
  58. package/lib/util/logger.d.ts +2 -5
  59. package/lib/util/logger.js +3 -12
  60. package/lib/util/logger.js.map +1 -1
  61. package/lib/util/requestUtils.d.ts +7 -10
  62. package/lib/util/requestUtils.js +6 -33
  63. package/lib/util/requestUtils.js.map +1 -1
  64. package/lib/util/typeGuards.d.ts +7 -1
  65. package/lib/util/typeGuards.js +41 -5
  66. package/lib/util/typeGuards.js.map +1 -1
  67. package/lib/util/webCryptoAPI.d.ts +10 -0
  68. package/lib/util/webCryptoAPI.js +69 -0
  69. package/lib/util/webCryptoAPI.js.map +1 -0
  70. package/lib/util/websockets/WsStore.d.ts +71 -0
  71. package/lib/util/websockets/WsStore.js +269 -0
  72. package/lib/util/websockets/WsStore.js.map +1 -0
  73. package/lib/util/websockets/WsStore.types.d.ts +50 -0
  74. package/lib/util/websockets/WsStore.types.js +14 -0
  75. package/lib/util/websockets/WsStore.types.js.map +1 -0
  76. package/lib/util/websockets/index.d.ts +3 -0
  77. package/lib/util/websockets/index.js +20 -0
  78. package/lib/util/websockets/index.js.map +1 -0
  79. package/lib/util/websockets/websocket-util.d.ts +92 -0
  80. package/lib/util/websockets/websocket-util.js +280 -0
  81. package/lib/util/websockets/websocket-util.js.map +1 -0
  82. package/lib/websocket-client.d.ts +107 -114
  83. package/lib/websocket-client.js +422 -716
  84. package/lib/websocket-client.js.map +1 -1
  85. package/package.json +4 -4
  86. package/lib/account-asset-client-v3.d.ts +0 -87
  87. package/lib/account-asset-client-v3.js +0 -154
  88. package/lib/account-asset-client-v3.js.map +0 -1
  89. package/lib/account-asset-client.d.ts +0 -46
  90. package/lib/account-asset-client.js +0 -108
  91. package/lib/account-asset-client.js.map +0 -1
  92. package/lib/contract-client.d.ts +0 -136
  93. package/lib/contract-client.js +0 -251
  94. package/lib/contract-client.js.map +0 -1
  95. package/lib/copy-trading-client.d.ts +0 -60
  96. package/lib/copy-trading-client.js +0 -114
  97. package/lib/copy-trading-client.js.map +0 -1
  98. package/lib/inverse-client.d.ts +0 -104
  99. package/lib/inverse-client.js +0 -213
  100. package/lib/inverse-client.js.map +0 -1
  101. package/lib/inverse-futures-client.d.ts +0 -217
  102. package/lib/inverse-futures-client.js +0 -224
  103. package/lib/inverse-futures-client.js.map +0 -1
  104. package/lib/linear-client.d.ts +0 -112
  105. package/lib/linear-client.js +0 -225
  106. package/lib/linear-client.js.map +0 -1
  107. package/lib/spot-client.d.ts +0 -46
  108. package/lib/spot-client.js +0 -131
  109. package/lib/spot-client.js.map +0 -1
  110. package/lib/types/request/spot.d.ts +0 -79
  111. package/lib/types/request/spot.js.map +0 -1
  112. package/lib/types/v5-shared.js.map +0 -1
  113. package/lib/types/websocket.events.js.map +0 -1
  114. package/lib/types/websockets.js +0 -3
  115. package/lib/types/websockets.js.map +0 -1
  116. package/lib/types/ws-events/failed-topic-subscription-confirmation.d.ts +0 -4
  117. package/lib/types/ws-events/failed-topic-subscription-confirmation.js +0 -3
  118. package/lib/types/ws-events/failed-topic-subscription-confirmation.js.map +0 -1
  119. package/lib/types/ws-events/succeeded-topic-subscription-confirmation.d.ts +0 -4
  120. package/lib/types/ws-events/succeeded-topic-subscription-confirmation.js +0 -3
  121. package/lib/types/ws-events/succeeded-topic-subscription-confirmation.js.map +0 -1
  122. package/lib/types/ws-events/topic-subscription-confirmation.d.ts +0 -7
  123. package/lib/types/ws-events/topic-subscription-confirmation.js +0 -3
  124. package/lib/types/ws-events/topic-subscription-confirmation.js.map +0 -1
  125. package/lib/unified-margin-client.d.ts +0 -140
  126. package/lib/unified-margin-client.js +0 -270
  127. package/lib/unified-margin-client.js.map +0 -1
  128. package/lib/usdc-option-client.d.ts +0 -110
  129. package/lib/usdc-option-client.js +0 -196
  130. package/lib/usdc-option-client.js.map +0 -1
  131. package/lib/usdc-perpetual-client.d.ts +0 -97
  132. package/lib/usdc-perpetual-client.js +0 -191
  133. package/lib/usdc-perpetual-client.js.map +0 -1
  134. package/lib/util/WsStore.d.ts +0 -57
  135. package/lib/util/WsStore.js +0 -97
  136. package/lib/util/WsStore.js.map +0 -1
  137. package/lib/util/browser-support.d.ts +0 -1
  138. package/lib/util/browser-support.js +0 -26
  139. package/lib/util/browser-support.js.map +0 -1
  140. package/lib/util/node-support.d.ts +0 -2
  141. package/lib/util/node-support.js +0 -21
  142. package/lib/util/node-support.js.map +0 -1
  143. package/lib/util/websocket-util.d.ts +0 -68
  144. package/lib/util/websocket-util.js +0 -506
  145. package/lib/util/websocket-util.js.map +0 -1
  146. /package/lib/types/{v5-shared.d.ts → shared-v5.d.ts} +0 -0
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsStore = exports.DEFERRED_PROMISE_REF = void 0;
4
+ exports.isDeepObjectMatch = isDeepObjectMatch;
5
+ const logger_1 = require("../logger");
6
+ const WsStore_types_1 = require("./WsStore.types");
7
+ /**
8
+ * Simple comparison of two objects, only checks 1-level deep (nested objects won't match)
9
+ */
10
+ function isDeepObjectMatch(object1, object2) {
11
+ if (typeof object1 === 'string' && typeof object2 === 'string') {
12
+ return object1 === object2;
13
+ }
14
+ if (typeof object1 !== 'object' || typeof object2 !== 'object') {
15
+ return false;
16
+ }
17
+ for (const key in object1) {
18
+ const value1 = object1[key];
19
+ const value2 = object2[key];
20
+ if (value1 !== value2) {
21
+ return false;
22
+ }
23
+ }
24
+ return true;
25
+ }
26
+ exports.DEFERRED_PROMISE_REF = {
27
+ CONNECTION_IN_PROGRESS: 'CONNECTION_IN_PROGRESS',
28
+ AUTHENTICATION_IN_PROGRESS: 'AUTHENTICATION_IN_PROGRESS',
29
+ };
30
+ class WsStore {
31
+ constructor(logger) {
32
+ this.wsState = {};
33
+ this.logger = logger || logger_1.DefaultLogger;
34
+ }
35
+ get(key, createIfMissing) {
36
+ if (this.wsState[key]) {
37
+ return this.wsState[key];
38
+ }
39
+ if (createIfMissing) {
40
+ return this.create(key);
41
+ }
42
+ }
43
+ getKeys() {
44
+ return Object.keys(this.wsState);
45
+ }
46
+ create(key) {
47
+ if (this.hasExistingActiveConnection(key)) {
48
+ this.logger.info('WsStore setConnection() overwriting existing open connection: ', this.getWs(key));
49
+ }
50
+ this.wsState[key] = {
51
+ subscribedTopics: new Set(),
52
+ connectionState: WsStore_types_1.WsConnectionStateEnum.INITIAL,
53
+ deferredPromiseStore: {},
54
+ };
55
+ return this.get(key);
56
+ }
57
+ delete(key) {
58
+ // TODO: should we allow this at all? Perhaps block this from happening...
59
+ if (this.hasExistingActiveConnection(key)) {
60
+ const ws = this.getWs(key);
61
+ this.logger.info('WsStore deleting state for connection still open: ', ws);
62
+ ws === null || ws === void 0 ? void 0 : ws.close();
63
+ }
64
+ delete this.wsState[key];
65
+ }
66
+ /* connection websocket */
67
+ hasExistingActiveConnection(key) {
68
+ return this.get(key) && this.isWsOpen(key);
69
+ }
70
+ getWs(key) {
71
+ var _a;
72
+ return (_a = this.get(key)) === null || _a === void 0 ? void 0 : _a.ws;
73
+ }
74
+ setWs(key, wsConnection) {
75
+ if (this.isWsOpen(key)) {
76
+ this.logger.info('WsStore setConnection() overwriting existing open connection: ', this.getWs(key));
77
+ }
78
+ this.get(key, true).ws = wsConnection;
79
+ return wsConnection;
80
+ }
81
+ getDeferredPromise(wsKey, promiseRef) {
82
+ const storeForKey = this.get(wsKey);
83
+ if (!storeForKey) {
84
+ return;
85
+ }
86
+ const deferredPromiseStore = storeForKey.deferredPromiseStore;
87
+ return deferredPromiseStore[promiseRef];
88
+ }
89
+ createDeferredPromise(wsKey, promiseRef, throwIfExists) {
90
+ const existingPromise = this.getDeferredPromise(wsKey, promiseRef);
91
+ if (existingPromise) {
92
+ if (throwIfExists) {
93
+ throw new Error(`Promise exists for "${wsKey}"`);
94
+ }
95
+ else {
96
+ // console.log('existing promise');
97
+ return existingPromise;
98
+ }
99
+ }
100
+ // console.log('create promise');
101
+ const createIfMissing = true;
102
+ const storeForKey = this.get(wsKey, createIfMissing);
103
+ // TODO: Once stable, use Promise.withResolvers in future
104
+ const deferredPromise = {};
105
+ deferredPromise.promise = new Promise((resolve, reject) => {
106
+ deferredPromise.resolve = resolve;
107
+ deferredPromise.reject = reject;
108
+ });
109
+ const deferredPromiseStore = storeForKey.deferredPromiseStore;
110
+ deferredPromiseStore[promiseRef] = deferredPromise;
111
+ return deferredPromise;
112
+ }
113
+ resolveDeferredPromise(wsKey, promiseRef, value, removeAfter) {
114
+ const promise = this.getDeferredPromise(wsKey, promiseRef);
115
+ if (promise === null || promise === void 0 ? void 0 : promise.resolve) {
116
+ promise.resolve(value);
117
+ }
118
+ if (removeAfter) {
119
+ this.removeDeferredPromise(wsKey, promiseRef);
120
+ }
121
+ }
122
+ rejectDeferredPromise(wsKey, promiseRef, value, removeAfter) {
123
+ const promise = this.getDeferredPromise(wsKey, promiseRef);
124
+ if (promise === null || promise === void 0 ? void 0 : promise.reject) {
125
+ promise.reject(value);
126
+ }
127
+ if (removeAfter) {
128
+ this.removeDeferredPromise(wsKey, promiseRef);
129
+ }
130
+ }
131
+ removeDeferredPromise(wsKey, promiseRef) {
132
+ const storeForKey = this.get(wsKey);
133
+ if (!storeForKey) {
134
+ return;
135
+ }
136
+ const deferredPromise = storeForKey.deferredPromiseStore[promiseRef];
137
+ if (deferredPromise) {
138
+ // Just in case it's pending
139
+ if (deferredPromise.resolve) {
140
+ deferredPromise.resolve('promiseRemoved');
141
+ }
142
+ delete storeForKey.deferredPromiseStore[promiseRef];
143
+ }
144
+ }
145
+ rejectAllDeferredPromises(wsKey, reason) {
146
+ const storeForKey = this.get(wsKey);
147
+ const deferredPromiseStore = storeForKey.deferredPromiseStore;
148
+ if (!storeForKey || !deferredPromiseStore) {
149
+ return;
150
+ }
151
+ const reservedKeys = Object.values(exports.DEFERRED_PROMISE_REF);
152
+ for (const promiseRef in deferredPromiseStore) {
153
+ // Skip reserved keys, such as the connection promise
154
+ if (reservedKeys.includes(promiseRef)) {
155
+ continue;
156
+ }
157
+ try {
158
+ this.rejectDeferredPromise(wsKey, promiseRef, reason, true);
159
+ }
160
+ catch (e) {
161
+ this.logger.error('rejectAllDeferredPromises(): Exception rejecting deferred promise', { wsKey: wsKey, reason, promiseRef, exception: e });
162
+ }
163
+ }
164
+ }
165
+ /** Get promise designed to track a connection attempt in progress. Resolves once connected. */
166
+ getConnectionInProgressPromise(wsKey) {
167
+ return this.getDeferredPromise(wsKey, exports.DEFERRED_PROMISE_REF.CONNECTION_IN_PROGRESS);
168
+ }
169
+ getAuthenticationInProgressPromise(wsKey) {
170
+ return this.getDeferredPromise(wsKey, exports.DEFERRED_PROMISE_REF.AUTHENTICATION_IN_PROGRESS);
171
+ }
172
+ /**
173
+ * Create a deferred promise designed to track a connection attempt in progress.
174
+ *
175
+ * Will throw if existing promise is found.
176
+ */
177
+ createConnectionInProgressPromise(wsKey, throwIfExists) {
178
+ return this.createDeferredPromise(wsKey, exports.DEFERRED_PROMISE_REF.CONNECTION_IN_PROGRESS, throwIfExists);
179
+ }
180
+ createAuthenticationInProgressPromise(wsKey, throwIfExists) {
181
+ return this.createDeferredPromise(wsKey, exports.DEFERRED_PROMISE_REF.AUTHENTICATION_IN_PROGRESS, throwIfExists);
182
+ }
183
+ /** Remove promise designed to track a connection attempt in progress */
184
+ removeConnectingInProgressPromise(wsKey) {
185
+ return this.removeDeferredPromise(wsKey, exports.DEFERRED_PROMISE_REF.CONNECTION_IN_PROGRESS);
186
+ }
187
+ removeAuthenticationInProgressPromise(wsKey) {
188
+ return this.removeDeferredPromise(wsKey, exports.DEFERRED_PROMISE_REF.AUTHENTICATION_IN_PROGRESS);
189
+ }
190
+ /* connection state */
191
+ isWsOpen(key) {
192
+ const existingConnection = this.getWs(key);
193
+ return (!!existingConnection &&
194
+ existingConnection.readyState === existingConnection.OPEN);
195
+ }
196
+ getConnectionState(key) {
197
+ return this.get(key, true).connectionState;
198
+ }
199
+ setConnectionState(key, state) {
200
+ this.get(key, true).connectionState = state;
201
+ }
202
+ isConnectionState(key, state) {
203
+ return this.getConnectionState(key) === state;
204
+ }
205
+ /**
206
+ * Check if we're currently in the process of opening a connection for any reason. Safer than only checking "CONNECTING" as the state
207
+ * @param key
208
+ * @returns
209
+ */
210
+ isConnectionAttemptInProgress(key) {
211
+ const isConnectionInProgress = this.isConnectionState(key, WsStore_types_1.WsConnectionStateEnum.CONNECTING) ||
212
+ this.isConnectionState(key, WsStore_types_1.WsConnectionStateEnum.RECONNECTING);
213
+ return isConnectionInProgress;
214
+ }
215
+ /* subscribed topics */
216
+ getTopics(key) {
217
+ return this.get(key, true).subscribedTopics;
218
+ }
219
+ getTopicsByKey() {
220
+ const result = {};
221
+ for (const refKey in this.wsState) {
222
+ result[refKey] = this.getTopics(refKey);
223
+ }
224
+ return result;
225
+ }
226
+ // Since topics are objects we can't rely on the set to detect duplicates
227
+ /**
228
+ * Find matching "topic" request from the store
229
+ * @param key
230
+ * @param topic
231
+ * @returns
232
+ */
233
+ getMatchingTopic(key, topic) {
234
+ // if (typeof topic === 'string') {
235
+ // return this.getMatchingTopic(key, { channel: topic });
236
+ // }
237
+ const allTopics = this.getTopics(key).values();
238
+ for (const storedTopic of allTopics) {
239
+ if (isDeepObjectMatch(topic, storedTopic)) {
240
+ return storedTopic;
241
+ }
242
+ }
243
+ }
244
+ addTopic(key, topic) {
245
+ // if (typeof topic === 'string') {
246
+ // return this.addTopic(key, {
247
+ // instType: 'sp',
248
+ // channel: topic,
249
+ // instId: 'default',
250
+ // };
251
+ // }
252
+ // Check for duplicate topic. If already tracked, don't store this one
253
+ const existingTopic = this.getMatchingTopic(key, topic);
254
+ if (existingTopic) {
255
+ return this.getTopics(key);
256
+ }
257
+ return this.getTopics(key).add(topic);
258
+ }
259
+ deleteTopic(key, topic) {
260
+ // Check if we're subscribed to a topic like this
261
+ const storedTopic = this.getMatchingTopic(key, topic);
262
+ if (storedTopic) {
263
+ this.getTopics(key).delete(storedTopic);
264
+ }
265
+ return this.getTopics(key);
266
+ }
267
+ }
268
+ exports.WsStore = WsStore;
269
+ //# sourceMappingURL=WsStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WsStore.js","sourceRoot":"","sources":["../../../src/util/websockets/WsStore.ts"],"names":[],"mappings":";;;AAcA,8CAkBC;AA7BD,sCAA0C;AAC1C,mDAKyB;AAEzB;;GAEG;AACH,SAAgB,iBAAiB,CAAC,OAAgB,EAAE,OAAgB;IAClE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC/D,OAAO,OAAO,KAAK,OAAO,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAI,OAAe,CAAC,GAAG,CA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 1,
5
+ CONNECTED = 2,
6
+ CLOSING = 3,
7
+ RECONNECTING = 4
8
+ }
9
+ export interface DeferredPromise<TSuccess = any, TError = any> {
10
+ resolve?: (value: TSuccess) => TSuccess;
11
+ reject?: (value: TError) => TError;
12
+ promise?: Promise<TSuccess>;
13
+ }
14
+ export interface WSConnectedResult {
15
+ wsKey: string;
16
+ }
17
+ export interface WsStoredState<TWSTopicSubscribeEvent extends string | object> {
18
+ /** The currently active websocket connection */
19
+ ws?: WebSocket;
20
+ /** The current lifecycle state of the connection (enum) */
21
+ connectionState?: WsConnectionStateEnum;
22
+ /** A timer that will send an upstream heartbeat (ping) when it expires */
23
+ activePingTimer?: ReturnType<typeof setTimeout> | undefined;
24
+ /** A timer tracking that an upstream heartbeat was sent, expecting a reply before it expires */
25
+ activePongTimer?: ReturnType<typeof setTimeout> | undefined;
26
+ /** If a reconnection is in progress, this will have the timer for the delayed reconnect */
27
+ activeReconnectTimer?: ReturnType<typeof setTimeout> | undefined;
28
+ /**
29
+ * When a connection attempt is in progress (even for reconnect), a promise is stored here.
30
+ *
31
+ * This promise will resolve once connected (and will then get removed);
32
+ */
33
+ deferredPromiseStore: Record<string, DeferredPromise>;
34
+ /**
35
+ * All the topics we are expected to be subscribed to on this connection (and we automatically resubscribe to if the connection drops)
36
+ *
37
+ * A "Set" and a deep-object-match are used to ensure we only subscribe to a
38
+ * topic once (tracking a list of unique topics we're expected to be connected to)
39
+ */
40
+ subscribedTopics: Set<TWSTopicSubscribeEvent>;
41
+ /** Whether this connection has completed authentication (only applies to private connections) */
42
+ isAuthenticated?: boolean;
43
+ /**
44
+ * Whether this connection has completed authentication before for the Websocket API, so it k
45
+ * nows to automatically reauth if reconnected
46
+ */
47
+ didAuthWSAPI?: boolean;
48
+ /** To reauthenticate on the WS API, which channel do we send to? */
49
+ WSAPIAuthChannel?: string;
50
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsConnectionStateEnum = void 0;
4
+ var WsConnectionStateEnum;
5
+ (function (WsConnectionStateEnum) {
6
+ WsConnectionStateEnum[WsConnectionStateEnum["INITIAL"] = 0] = "INITIAL";
7
+ WsConnectionStateEnum[WsConnectionStateEnum["CONNECTING"] = 1] = "CONNECTING";
8
+ WsConnectionStateEnum[WsConnectionStateEnum["CONNECTED"] = 2] = "CONNECTED";
9
+ WsConnectionStateEnum[WsConnectionStateEnum["CLOSING"] = 3] = "CLOSING";
10
+ WsConnectionStateEnum[WsConnectionStateEnum["RECONNECTING"] = 4] = "RECONNECTING";
11
+ // ERROR_RECONNECTING = 5,
12
+ // ERROR = 5,
13
+ })(WsConnectionStateEnum || (exports.WsConnectionStateEnum = WsConnectionStateEnum = {}));
14
+ //# sourceMappingURL=WsStore.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WsStore.types.js","sourceRoot":"","sources":["../../../src/util/websockets/WsStore.types.ts"],"names":[],"mappings":";;;AAGA,IAAY,qBAQX;AARD,WAAY,qBAAqB;IAC/B,uEAAW,CAAA;IACX,6EAAc,CAAA;IACd,2EAAa,CAAA;IACb,uEAAW,CAAA;IACX,iFAAgB,CAAA;IAChB,0BAA0B;IAC1B,aAAa;AACf,CAAC,EARW,qBAAqB,qCAArB,qBAAqB,QAQhC"}
@@ -0,0 +1,3 @@
1
+ export * from './websocket-util';
2
+ export * from './WsStore';
3
+ export * from './WsStore.types';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./websocket-util"), exports);
18
+ __exportStar(require("./WsStore"), exports);
19
+ __exportStar(require("./WsStore.types"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/websockets/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,4CAA0B;AAC1B,kDAAgC"}
@@ -0,0 +1,92 @@
1
+ import WebSocket from 'isomorphic-ws';
2
+ import { APIMarket, CategoryV5, WebsocketClientOptions, WsKey, WsTopic } from '../../types';
3
+ import { DefaultLogger } from '../logger';
4
+ import { WSAPIRequest } from '../../types/websockets/ws-api';
5
+ export declare const WS_LOGGER_CATEGORY: {
6
+ category: string;
7
+ };
8
+ export declare const WS_KEY_MAP: {
9
+ readonly v5SpotPublic: "v5SpotPublic";
10
+ readonly v5LinearPublic: "v5LinearPublic";
11
+ readonly v5InversePublic: "v5InversePublic";
12
+ readonly v5OptionPublic: "v5OptionPublic";
13
+ readonly v5Private: "v5Private";
14
+ /**
15
+ * The V5 Websocket API (for sending orders over WS)
16
+ */
17
+ readonly v5PrivateTrade: "v5PrivateTrade";
18
+ };
19
+ export declare const WS_AUTH_ON_CONNECT_KEYS: WsKey[];
20
+ export declare const PUBLIC_WS_KEYS: string[];
21
+ /**
22
+ * Normalised internal format for a request (subscribe/unsubscribe/etc) on a topic, with optional parameters.
23
+ *
24
+ * - Topic: the topic this event is for
25
+ * - Payload: the parameters to include, optional. E.g. auth requires key + sign. Some topics allow configurable parameters.
26
+ * - Category: required for bybit, since different categories have different public endpoints
27
+ */
28
+ export interface WsTopicRequest<TWSTopic extends string = string, TWSPayload = unknown> {
29
+ topic: TWSTopic;
30
+ payload?: TWSPayload;
31
+ category?: CategoryV5;
32
+ }
33
+ /**
34
+ * Conveniently allow users to request a topic either as string topics or objects (containing string topic + params)
35
+ */
36
+ export type WsTopicRequestOrStringTopic<TWSTopic extends string, TWSPayload = unknown> = WsTopicRequest<TWSTopic, TWSPayload> | string;
37
+ interface NetworkMapV3 {
38
+ livenet: string;
39
+ livenet2?: string;
40
+ testnet: string;
41
+ testnet2?: string;
42
+ }
43
+ type PublicPrivateNetwork = 'public' | 'private';
44
+ /**
45
+ * The following WS keys are logical.
46
+ *
47
+ * They're not directly used as a market. They usually have one private endpoint but many public ones,
48
+ * so they need a bit of extra handling for seamless messaging between endpoints.
49
+ *
50
+ * For the unified keys, the "split" happens using the symbol. Symbols suffixed with USDT are obviously USDT topics.
51
+ * For the v5 endpoints, the subscribe/unsubscribe call must specify the category the subscription should route to.
52
+ */
53
+ type PublicOnlyWsKeys = 'v5SpotPublic' | 'v5LinearPublic' | 'v5InversePublic' | 'v5OptionPublic';
54
+ export declare const WS_BASE_URL_MAP: Record<APIMarket, Record<PublicPrivateNetwork, NetworkMapV3>> & Record<PublicOnlyWsKeys, Record<'public', NetworkMapV3>> & Record<typeof WS_KEY_MAP.v5PrivateTrade, Record<PublicPrivateNetwork, NetworkMapV3>>;
55
+ export declare function isPrivateWsTopic(topic: string): boolean;
56
+ export declare function getWsKeyForTopic(market: APIMarket, topic: string, isPrivate?: boolean, category?: CategoryV5): WsKey;
57
+ export declare function getWsUrl(wsKey: WsKey, wsClientOptions: WebsocketClientOptions, logger: typeof DefaultLogger): string;
58
+ export declare function getMaxTopicsPerSubscribeEvent(market: APIMarket, wsKey: WsKey): number | null;
59
+ export declare const WS_ERROR_ENUM: {
60
+ NOT_AUTHENTICATED_SPOT_V3: string;
61
+ API_ERROR_GENERIC: string;
62
+ API_SIGN_AUTH_FAILED: string;
63
+ USDC_OPTION_AUTH_FAILED: string;
64
+ };
65
+ /**
66
+ * #305: ws.terminate() is undefined in browsers.
67
+ * This only works in node.js, not in browsers.
68
+ * Does nothing if `ws` is undefined.
69
+ */
70
+ export declare function safeTerminateWs(ws?: WebSocket | unknown): void;
71
+ /**
72
+ * WS API promises are stored using a primary key. This key is constructed using
73
+ * properties found in every request & reply.
74
+ */
75
+ export declare function getPromiseRefForWSAPIRequest(requestEvent: WSAPIRequest<unknown>): string;
76
+ /**
77
+ * Users can conveniently pass topics as strings or objects (object has topic name + optional params).
78
+ *
79
+ * This method normalises topics into objects (object has topic name + optional params).
80
+ */
81
+ export declare function getNormalisedTopicRequests(wsTopicRequests: WsTopicRequestOrStringTopic<string>[]): WsTopicRequest<string>[];
82
+ /**
83
+ * Groups topics in request into per-wsKey groups
84
+ * @param normalisedTopicRequests
85
+ * @param wsKey
86
+ * @param isPrivateTopic
87
+ * @returns
88
+ */
89
+ export declare function getTopicsPerWSKey(market: APIMarket, normalisedTopicRequests: WsTopicRequest[], wsKey?: WsKey, isPrivateTopic?: boolean): {
90
+ [key in WsKey]?: WsTopicRequest<WsTopic>[];
91
+ };
92
+ export {};