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.
- package/README.md +301 -178
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -11
- package/lib/index.js.map +1 -1
- package/lib/rest-client-v5.d.ts +1 -1
- package/lib/rest-client-v5.js +1 -1
- package/lib/spot-client-v3.d.ts +8 -81
- package/lib/spot-client-v3.js +7 -172
- package/lib/spot-client-v3.js.map +1 -1
- package/lib/types/index.d.ts +1 -2
- package/lib/types/index.js +1 -2
- package/lib/types/index.js.map +1 -1
- package/lib/types/request/index.d.ts +0 -1
- package/lib/types/request/index.js +0 -1
- package/lib/types/request/index.js.map +1 -1
- package/lib/types/request/v5-account.d.ts +1 -1
- package/lib/types/request/v5-asset.d.ts +1 -1
- package/lib/types/request/v5-market.d.ts +1 -1
- package/lib/types/request/v5-position.d.ts +1 -1
- package/lib/types/request/v5-pre-upgrade.d.ts +1 -1
- package/lib/types/request/v5-spot-leverage-token.d.ts +1 -1
- package/lib/types/request/v5-trade.d.ts +1 -1
- package/lib/types/request/v5-user.d.ts +1 -1
- package/lib/types/response/v5-account.d.ts +1 -1
- package/lib/types/response/v5-asset.d.ts +1 -1
- package/lib/types/response/v5-market.d.ts +1 -1
- package/lib/types/response/v5-position.d.ts +1 -1
- package/lib/types/response/v5-spot-leverage-token.d.ts +1 -1
- package/lib/types/response/v5-trade.d.ts +1 -1
- package/lib/types/response/v5-user.d.ts +1 -1
- package/lib/types/{request/spot.js → shared-v5.js} +1 -1
- package/lib/types/shared-v5.js.map +1 -0
- package/lib/types/shared.d.ts +1 -19
- package/lib/types/websockets/index.d.ts +3 -0
- package/lib/types/websockets/index.js +20 -0
- package/lib/types/websockets/index.js.map +1 -0
- package/lib/types/websockets/ws-api.d.ts +73 -0
- package/lib/types/websockets/ws-api.js +10 -0
- package/lib/types/websockets/ws-api.js.map +1 -0
- package/lib/types/websockets/ws-confirmations.d.ts +13 -0
- package/lib/types/{websocket.events.js → websockets/ws-confirmations.js} +1 -1
- package/lib/types/websockets/ws-confirmations.js.map +1 -0
- package/lib/types/{websocket.events.d.ts → websockets/ws-events.d.ts} +9 -3
- package/lib/types/websockets/ws-events.js +11 -0
- package/lib/types/websockets/ws-events.js.map +1 -0
- package/lib/types/{websockets.d.ts → websockets/ws-general.d.ts} +35 -10
- package/lib/types/{v5-shared.js → websockets/ws-general.js} +1 -1
- package/lib/types/websockets/ws-general.js.map +1 -0
- package/lib/util/BaseRestClient.d.ts +1 -1
- package/lib/util/BaseRestClient.js +15 -39
- package/lib/util/BaseRestClient.js.map +1 -1
- package/lib/util/BaseWSClient.d.ts +221 -0
- package/lib/util/BaseWSClient.js +733 -0
- package/lib/util/BaseWSClient.js.map +1 -0
- package/lib/util/index.d.ts +1 -2
- package/lib/util/index.js +1 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/logger.d.ts +2 -5
- package/lib/util/logger.js +3 -12
- package/lib/util/logger.js.map +1 -1
- package/lib/util/requestUtils.d.ts +7 -10
- package/lib/util/requestUtils.js +6 -33
- package/lib/util/requestUtils.js.map +1 -1
- package/lib/util/typeGuards.d.ts +7 -1
- package/lib/util/typeGuards.js +41 -5
- package/lib/util/typeGuards.js.map +1 -1
- package/lib/util/webCryptoAPI.d.ts +10 -0
- package/lib/util/webCryptoAPI.js +69 -0
- package/lib/util/webCryptoAPI.js.map +1 -0
- package/lib/util/websockets/WsStore.d.ts +71 -0
- package/lib/util/websockets/WsStore.js +269 -0
- package/lib/util/websockets/WsStore.js.map +1 -0
- package/lib/util/websockets/WsStore.types.d.ts +50 -0
- package/lib/util/websockets/WsStore.types.js +14 -0
- package/lib/util/websockets/WsStore.types.js.map +1 -0
- package/lib/util/websockets/index.d.ts +3 -0
- package/lib/util/websockets/index.js +20 -0
- package/lib/util/websockets/index.js.map +1 -0
- package/lib/util/websockets/websocket-util.d.ts +92 -0
- package/lib/util/websockets/websocket-util.js +280 -0
- package/lib/util/websockets/websocket-util.js.map +1 -0
- package/lib/websocket-client.d.ts +107 -114
- package/lib/websocket-client.js +422 -716
- package/lib/websocket-client.js.map +1 -1
- package/package.json +4 -4
- package/lib/account-asset-client-v3.d.ts +0 -87
- package/lib/account-asset-client-v3.js +0 -154
- package/lib/account-asset-client-v3.js.map +0 -1
- package/lib/account-asset-client.d.ts +0 -46
- package/lib/account-asset-client.js +0 -108
- package/lib/account-asset-client.js.map +0 -1
- package/lib/contract-client.d.ts +0 -136
- package/lib/contract-client.js +0 -251
- package/lib/contract-client.js.map +0 -1
- package/lib/copy-trading-client.d.ts +0 -60
- package/lib/copy-trading-client.js +0 -114
- package/lib/copy-trading-client.js.map +0 -1
- package/lib/inverse-client.d.ts +0 -104
- package/lib/inverse-client.js +0 -213
- package/lib/inverse-client.js.map +0 -1
- package/lib/inverse-futures-client.d.ts +0 -217
- package/lib/inverse-futures-client.js +0 -224
- package/lib/inverse-futures-client.js.map +0 -1
- package/lib/linear-client.d.ts +0 -112
- package/lib/linear-client.js +0 -225
- package/lib/linear-client.js.map +0 -1
- package/lib/spot-client.d.ts +0 -46
- package/lib/spot-client.js +0 -131
- package/lib/spot-client.js.map +0 -1
- package/lib/types/request/spot.d.ts +0 -79
- package/lib/types/request/spot.js.map +0 -1
- package/lib/types/v5-shared.js.map +0 -1
- package/lib/types/websocket.events.js.map +0 -1
- package/lib/types/websockets.js +0 -3
- package/lib/types/websockets.js.map +0 -1
- package/lib/types/ws-events/failed-topic-subscription-confirmation.d.ts +0 -4
- package/lib/types/ws-events/failed-topic-subscription-confirmation.js +0 -3
- package/lib/types/ws-events/failed-topic-subscription-confirmation.js.map +0 -1
- package/lib/types/ws-events/succeeded-topic-subscription-confirmation.d.ts +0 -4
- package/lib/types/ws-events/succeeded-topic-subscription-confirmation.js +0 -3
- package/lib/types/ws-events/succeeded-topic-subscription-confirmation.js.map +0 -1
- package/lib/types/ws-events/topic-subscription-confirmation.d.ts +0 -7
- package/lib/types/ws-events/topic-subscription-confirmation.js +0 -3
- package/lib/types/ws-events/topic-subscription-confirmation.js.map +0 -1
- package/lib/unified-margin-client.d.ts +0 -140
- package/lib/unified-margin-client.js +0 -270
- package/lib/unified-margin-client.js.map +0 -1
- package/lib/usdc-option-client.d.ts +0 -110
- package/lib/usdc-option-client.js +0 -196
- package/lib/usdc-option-client.js.map +0 -1
- package/lib/usdc-perpetual-client.d.ts +0 -97
- package/lib/usdc-perpetual-client.js +0 -191
- package/lib/usdc-perpetual-client.js.map +0 -1
- package/lib/util/WsStore.d.ts +0 -57
- package/lib/util/WsStore.js +0 -97
- package/lib/util/WsStore.js.map +0 -1
- package/lib/util/browser-support.d.ts +0 -1
- package/lib/util/browser-support.js +0 -26
- package/lib/util/browser-support.js.map +0 -1
- package/lib/util/node-support.d.ts +0 -2
- package/lib/util/node-support.js +0 -21
- package/lib/util/node-support.js.map +0 -1
- package/lib/util/websocket-util.d.ts +0 -68
- package/lib/util/websocket-util.js +0 -506
- package/lib/util/websocket-util.js.map +0 -1
- /package/lib/types/{v5-shared.d.ts → shared-v5.d.ts} +0 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WS_ERROR_ENUM = exports.WS_BASE_URL_MAP = exports.PUBLIC_WS_KEYS = exports.WS_AUTH_ON_CONNECT_KEYS = exports.WS_KEY_MAP = exports.WS_LOGGER_CATEGORY = void 0;
|
|
4
|
+
exports.isPrivateWsTopic = isPrivateWsTopic;
|
|
5
|
+
exports.getWsKeyForTopic = getWsKeyForTopic;
|
|
6
|
+
exports.getWsUrl = getWsUrl;
|
|
7
|
+
exports.getMaxTopicsPerSubscribeEvent = getMaxTopicsPerSubscribeEvent;
|
|
8
|
+
exports.safeTerminateWs = safeTerminateWs;
|
|
9
|
+
exports.getPromiseRefForWSAPIRequest = getPromiseRefForWSAPIRequest;
|
|
10
|
+
exports.getNormalisedTopicRequests = getNormalisedTopicRequests;
|
|
11
|
+
exports.getTopicsPerWSKey = getTopicsPerWSKey;
|
|
12
|
+
const typeGuards_1 = require("../typeGuards");
|
|
13
|
+
exports.WS_LOGGER_CATEGORY = { category: 'bybit-ws' };
|
|
14
|
+
exports.WS_KEY_MAP = {
|
|
15
|
+
v5SpotPublic: 'v5SpotPublic',
|
|
16
|
+
v5LinearPublic: 'v5LinearPublic',
|
|
17
|
+
v5InversePublic: 'v5InversePublic',
|
|
18
|
+
v5OptionPublic: 'v5OptionPublic',
|
|
19
|
+
v5Private: 'v5Private',
|
|
20
|
+
/**
|
|
21
|
+
* The V5 Websocket API (for sending orders over WS)
|
|
22
|
+
*/
|
|
23
|
+
v5PrivateTrade: 'v5PrivateTrade',
|
|
24
|
+
};
|
|
25
|
+
exports.WS_AUTH_ON_CONNECT_KEYS = [
|
|
26
|
+
exports.WS_KEY_MAP.v5Private,
|
|
27
|
+
exports.WS_KEY_MAP.v5PrivateTrade,
|
|
28
|
+
];
|
|
29
|
+
exports.PUBLIC_WS_KEYS = [
|
|
30
|
+
exports.WS_KEY_MAP.v5SpotPublic,
|
|
31
|
+
exports.WS_KEY_MAP.v5LinearPublic,
|
|
32
|
+
exports.WS_KEY_MAP.v5InversePublic,
|
|
33
|
+
exports.WS_KEY_MAP.v5OptionPublic,
|
|
34
|
+
];
|
|
35
|
+
/** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */
|
|
36
|
+
const PRIVATE_TOPICS = [
|
|
37
|
+
'stop_order',
|
|
38
|
+
'outboundAccountInfo',
|
|
39
|
+
'executionReport',
|
|
40
|
+
'ticketInfo',
|
|
41
|
+
// copy trading apis
|
|
42
|
+
'copyTradePosition',
|
|
43
|
+
'copyTradeOrder',
|
|
44
|
+
'copyTradeExecution',
|
|
45
|
+
'copyTradeWallet',
|
|
46
|
+
// usdc options
|
|
47
|
+
'user.openapi.option.position',
|
|
48
|
+
'user.openapi.option.trade',
|
|
49
|
+
'user.order',
|
|
50
|
+
'user.openapi.option.order',
|
|
51
|
+
'user.service',
|
|
52
|
+
'user.openapi.greeks',
|
|
53
|
+
'user.mmp.event',
|
|
54
|
+
// usdc perps
|
|
55
|
+
'user.openapi.perp.position',
|
|
56
|
+
'user.openapi.perp.trade',
|
|
57
|
+
'user.openapi.perp.order',
|
|
58
|
+
'user.service',
|
|
59
|
+
// unified margin
|
|
60
|
+
'user.position.unifiedAccount',
|
|
61
|
+
'user.execution.unifiedAccount',
|
|
62
|
+
'user.order.unifiedAccount',
|
|
63
|
+
'user.wallet.unifiedAccount',
|
|
64
|
+
'user.greeks.unifiedAccount',
|
|
65
|
+
// contract v3
|
|
66
|
+
'user.position.contractAccount',
|
|
67
|
+
'user.execution.contractAccount',
|
|
68
|
+
'user.order.contractAccount',
|
|
69
|
+
'user.wallet.contractAccount',
|
|
70
|
+
// v5
|
|
71
|
+
'position',
|
|
72
|
+
'execution',
|
|
73
|
+
'order',
|
|
74
|
+
'wallet',
|
|
75
|
+
'greeks',
|
|
76
|
+
];
|
|
77
|
+
exports.WS_BASE_URL_MAP = {
|
|
78
|
+
v5: {
|
|
79
|
+
public: {
|
|
80
|
+
livenet: 'public topics are routed internally via the public wskeys',
|
|
81
|
+
testnet: 'public topics are routed internally via the public wskeys',
|
|
82
|
+
},
|
|
83
|
+
private: {
|
|
84
|
+
livenet: 'wss://stream.bybit.com/v5/private',
|
|
85
|
+
testnet: 'wss://stream-testnet.bybit.com/v5/private',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
v5PrivateTrade: {
|
|
89
|
+
public: {
|
|
90
|
+
livenet: 'public topics are routed internally via the public wskeys',
|
|
91
|
+
testnet: 'public topics are routed internally via the public wskeys',
|
|
92
|
+
},
|
|
93
|
+
private: {
|
|
94
|
+
livenet: 'wss://stream.bybit.com/v5/trade',
|
|
95
|
+
testnet: 'wss://stream-testnet.bybit.com/v5/trade',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
v5SpotPublic: {
|
|
99
|
+
public: {
|
|
100
|
+
livenet: 'wss://stream.bybit.com/v5/public/spot',
|
|
101
|
+
testnet: 'wss://stream-testnet.bybit.com/v5/public/spot',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
v5LinearPublic: {
|
|
105
|
+
public: {
|
|
106
|
+
livenet: 'wss://stream.bybit.com/v5/public/linear',
|
|
107
|
+
testnet: 'wss://stream-testnet.bybit.com/v5/public/linear',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
v5InversePublic: {
|
|
111
|
+
public: {
|
|
112
|
+
livenet: 'wss://stream.bybit.com/v5/public/inverse',
|
|
113
|
+
testnet: 'wss://stream-testnet.bybit.com/v5/public/inverse',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
v5OptionPublic: {
|
|
117
|
+
public: {
|
|
118
|
+
livenet: 'wss://stream.bybit.com/v5/public/option',
|
|
119
|
+
testnet: 'wss://stream-testnet.bybit.com/v5/public/option',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
function isPrivateWsTopic(topic) {
|
|
124
|
+
return PRIVATE_TOPICS.includes(topic);
|
|
125
|
+
}
|
|
126
|
+
function getWsKeyForTopic(market, topic, isPrivate, category) {
|
|
127
|
+
const isPrivateTopic = isPrivate === true || PRIVATE_TOPICS.includes(topic);
|
|
128
|
+
switch (market) {
|
|
129
|
+
case 'v5': {
|
|
130
|
+
if (isPrivateTopic) {
|
|
131
|
+
return exports.WS_KEY_MAP.v5Private;
|
|
132
|
+
}
|
|
133
|
+
switch (category) {
|
|
134
|
+
case 'spot': {
|
|
135
|
+
return exports.WS_KEY_MAP.v5SpotPublic;
|
|
136
|
+
}
|
|
137
|
+
case 'linear': {
|
|
138
|
+
return exports.WS_KEY_MAP.v5LinearPublic;
|
|
139
|
+
}
|
|
140
|
+
case 'inverse': {
|
|
141
|
+
return exports.WS_KEY_MAP.v5InversePublic;
|
|
142
|
+
}
|
|
143
|
+
case 'option': {
|
|
144
|
+
return exports.WS_KEY_MAP.v5OptionPublic;
|
|
145
|
+
}
|
|
146
|
+
case undefined: {
|
|
147
|
+
throw new Error('Category cannot be undefined');
|
|
148
|
+
}
|
|
149
|
+
default: {
|
|
150
|
+
throw (0, typeGuards_1.neverGuard)(category, 'getWsKeyForTopic(v5): Unhandled v5 category');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
default: {
|
|
155
|
+
throw (0, typeGuards_1.neverGuard)(market, 'getWsKeyForTopic(): Unhandled market');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function getWsUrl(wsKey, wsClientOptions, logger) {
|
|
160
|
+
const wsUrl = wsClientOptions.wsUrl;
|
|
161
|
+
if (wsUrl) {
|
|
162
|
+
return wsUrl;
|
|
163
|
+
}
|
|
164
|
+
// https://bybit-exchange.github.io/docs/v5/demo
|
|
165
|
+
const isDemoTrading = wsClientOptions.demoTrading;
|
|
166
|
+
if (isDemoTrading) {
|
|
167
|
+
return 'wss://stream-demo.bybit.com/v5/private';
|
|
168
|
+
}
|
|
169
|
+
const isTestnet = wsClientOptions.testnet;
|
|
170
|
+
const networkKey = isTestnet ? 'testnet' : 'livenet';
|
|
171
|
+
switch (wsKey) {
|
|
172
|
+
case exports.WS_KEY_MAP.v5Private: {
|
|
173
|
+
return exports.WS_BASE_URL_MAP.v5.private[networkKey];
|
|
174
|
+
}
|
|
175
|
+
case exports.WS_KEY_MAP.v5PrivateTrade: {
|
|
176
|
+
return exports.WS_BASE_URL_MAP[wsKey].private[networkKey];
|
|
177
|
+
}
|
|
178
|
+
case exports.WS_KEY_MAP.v5SpotPublic: {
|
|
179
|
+
return exports.WS_BASE_URL_MAP.v5SpotPublic.public[networkKey];
|
|
180
|
+
}
|
|
181
|
+
case exports.WS_KEY_MAP.v5LinearPublic: {
|
|
182
|
+
return exports.WS_BASE_URL_MAP.v5LinearPublic.public[networkKey];
|
|
183
|
+
}
|
|
184
|
+
case exports.WS_KEY_MAP.v5InversePublic: {
|
|
185
|
+
return exports.WS_BASE_URL_MAP.v5InversePublic.public[networkKey];
|
|
186
|
+
}
|
|
187
|
+
case exports.WS_KEY_MAP.v5OptionPublic: {
|
|
188
|
+
return exports.WS_BASE_URL_MAP.v5OptionPublic.public[networkKey];
|
|
189
|
+
}
|
|
190
|
+
default: {
|
|
191
|
+
logger.error('getWsUrl(): Unhandled wsKey: ', {
|
|
192
|
+
category: 'bybit-ws',
|
|
193
|
+
wsKey,
|
|
194
|
+
});
|
|
195
|
+
throw (0, typeGuards_1.neverGuard)(wsKey, 'getWsUrl(): Unhandled wsKey');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function getMaxTopicsPerSubscribeEvent(market, wsKey) {
|
|
200
|
+
switch (market) {
|
|
201
|
+
case 'v5': {
|
|
202
|
+
if (wsKey === exports.WS_KEY_MAP.v5SpotPublic) {
|
|
203
|
+
return 10;
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
default: {
|
|
208
|
+
throw (0, typeGuards_1.neverGuard)(market, 'getWsKeyForTopic(): Unhandled market');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.WS_ERROR_ENUM = {
|
|
213
|
+
NOT_AUTHENTICATED_SPOT_V3: '-1004',
|
|
214
|
+
API_ERROR_GENERIC: '10001',
|
|
215
|
+
API_SIGN_AUTH_FAILED: '10003',
|
|
216
|
+
USDC_OPTION_AUTH_FAILED: '3303006',
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* #305: ws.terminate() is undefined in browsers.
|
|
220
|
+
* This only works in node.js, not in browsers.
|
|
221
|
+
* Does nothing if `ws` is undefined.
|
|
222
|
+
*/
|
|
223
|
+
function safeTerminateWs(ws) {
|
|
224
|
+
// #305: ws.terminate() undefined in browsers
|
|
225
|
+
if (ws && typeof ws['terminate'] === 'function') {
|
|
226
|
+
ws.terminate();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* WS API promises are stored using a primary key. This key is constructed using
|
|
231
|
+
* properties found in every request & reply.
|
|
232
|
+
*/
|
|
233
|
+
function getPromiseRefForWSAPIRequest(requestEvent) {
|
|
234
|
+
const promiseRef = [requestEvent.op, requestEvent.reqId].join('_');
|
|
235
|
+
return promiseRef;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
|
|
239
|
+
*
|
|
240
|
+
* This method normalises topics into objects (object has topic name + optional params).
|
|
241
|
+
*/
|
|
242
|
+
function getNormalisedTopicRequests(wsTopicRequests) {
|
|
243
|
+
const normalisedTopicRequests = [];
|
|
244
|
+
for (const wsTopicRequest of wsTopicRequests) {
|
|
245
|
+
// passed as string, convert to object
|
|
246
|
+
if (typeof wsTopicRequest === 'string') {
|
|
247
|
+
const topicRequest = {
|
|
248
|
+
topic: wsTopicRequest,
|
|
249
|
+
payload: undefined,
|
|
250
|
+
};
|
|
251
|
+
normalisedTopicRequests.push(topicRequest);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
// already a normalised object, thanks to user
|
|
255
|
+
normalisedTopicRequests.push(wsTopicRequest);
|
|
256
|
+
}
|
|
257
|
+
return normalisedTopicRequests;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Groups topics in request into per-wsKey groups
|
|
261
|
+
* @param normalisedTopicRequests
|
|
262
|
+
* @param wsKey
|
|
263
|
+
* @param isPrivateTopic
|
|
264
|
+
* @returns
|
|
265
|
+
*/
|
|
266
|
+
function getTopicsPerWSKey(market, normalisedTopicRequests, wsKey, isPrivateTopic) {
|
|
267
|
+
const perWsKeyTopics = {};
|
|
268
|
+
// Sort into per wsKey arrays, in case topics are mixed together for different wsKeys
|
|
269
|
+
for (const topicRequest of normalisedTopicRequests) {
|
|
270
|
+
const derivedWsKey = wsKey ||
|
|
271
|
+
getWsKeyForTopic(market, topicRequest.topic, isPrivateTopic, topicRequest.category);
|
|
272
|
+
if (!perWsKeyTopics[derivedWsKey] ||
|
|
273
|
+
!Array.isArray(perWsKeyTopics[derivedWsKey])) {
|
|
274
|
+
perWsKeyTopics[derivedWsKey] = [];
|
|
275
|
+
}
|
|
276
|
+
perWsKeyTopics[derivedWsKey].push(topicRequest);
|
|
277
|
+
}
|
|
278
|
+
return perWsKeyTopics;
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=websocket-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-util.js","sourceRoot":"","sources":["../../../src/util/websockets/websocket-util.ts"],"names":[],"mappings":";;;AAyLA,4CAEC;AAED,4CAyCC;AAED,4BA8CC;AAED,sEAeC;AAcD,0CAKC;AAKD,oEAKC;AAOD,gEAoBC;AASD,8CAgCC;AA7XD,8CAA2C;AAE9B,QAAA,kBAAkB,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAE9C,QAAA,UAAU,GAAG;IACxB,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,SAAS,EAAE,WAAW;IACtB;;OAEG;IACH,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAEE,QAAA,uBAAuB,GAAY;IAC9C,kBAAU,CAAC,SAAS;IACpB,kBAAU,CAAC,cAAc;CAC1B,CAAC;AAEW,QAAA,cAAc,GAAG;IAC5B,kBAAU,CAAC,YAAY;IACvB,kBAAU,CAAC,cAAc;IACzB,kBAAU,CAAC,eAAe;IAC1B,kBAAU,CAAC,cAAc;CACd,CAAC;AAEd,gHAAgH;AAChH,MAAM,cAAc,GAAG;IACrB,YAAY;IACZ,qBAAqB;IACrB,iBAAiB;IACjB,YAAY;IACZ,oBAAoB;IACpB,mBAAmB;IACnB,gBAAgB;IAChB,oBAAoB;IACpB,iBAAiB;IACjB,eAAe;IACf,8BAA8B;IAC9B,2BAA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,EAAE,cAAc;gBACrB,OAAO,EAAE,SAAS;aACnB,CAAC;YACF,uBAAuB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC3C,SAAS;QACX,CAAC;QAED,8CAA8C;QAC9C,uBAAuB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,MAAiB,EACjB,uBAAyC,EACzC,KAAa,EACb,cAAwB;IAIxB,MAAM,cAAc,GAAmD,EAAE,CAAC;IAE1E,qFAAqF;IACrF,KAAK,MAAM,YAAY,IAAI,uBAAuB,EAAE,CAAC;QACnD,MAAM,YAAY,GAChB,KAAK;YACL,gBAAgB,CACd,MAAM,EACN,YAAY,CAAC,KAAK,EAClB,cAAc,EACd,YAAY,CAAC,QAAQ,CACtB,CAAC;QAEJ,IACE,CAAC,cAAc,CAAC,YAAY,CAAC;YAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,EAC5C,CAAC;YACD,cAAc,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QACpC,CAAC;QAED,cAAc,CAAC,YAAY,CAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -1,144 +1,137 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
1
|
import WebSocket from 'isomorphic-ws';
|
|
4
|
-
import { CategoryV5,
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}) => void;
|
|
24
|
-
/** Connection closed */
|
|
25
|
-
close: (evt: {
|
|
26
|
-
wsKey: WsKey;
|
|
27
|
-
event: any;
|
|
28
|
-
}) => void;
|
|
29
|
-
/** Received reply to websocket command (e.g. after subscribing to topics) */
|
|
30
|
-
response: (response: any) => void;
|
|
31
|
-
/** Received data for topic */
|
|
32
|
-
update: (response: any) => void;
|
|
33
|
-
/** Exception from ws client OR custom listeners */
|
|
34
|
-
error: (response: any) => void;
|
|
35
|
-
}
|
|
36
|
-
export declare interface WebsocketClient {
|
|
37
|
-
on<U extends keyof WebsocketClientEvents>(event: U, listener: WebsocketClientEvents[U]): this;
|
|
38
|
-
emit<U extends keyof WebsocketClientEvents>(event: U, ...args: Parameters<WebsocketClientEvents[U]>): boolean;
|
|
39
|
-
}
|
|
40
|
-
export declare class WebsocketClient extends EventEmitter {
|
|
41
|
-
private logger;
|
|
42
|
-
private restClient?;
|
|
43
|
-
private options;
|
|
44
|
-
private wsStore;
|
|
45
|
-
private pendingTopicsSubscriptions;
|
|
46
|
-
constructor(options: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
|
|
47
|
-
/** Get the WsStore that tracks websockets & topics */
|
|
48
|
-
getWsStore(): WsStore;
|
|
49
|
-
isTestnet(): boolean;
|
|
2
|
+
import { CategoryV5, MessageEventLike, WsKey, WsMarket, WsTopic } from './types';
|
|
3
|
+
import { WSConnectedResult, WS_KEY_MAP, WsTopicRequest } from './util';
|
|
4
|
+
import { BaseWebsocketClient, EmittableEvent, MidflightWsRequestEvent } from './util/BaseWSClient';
|
|
5
|
+
import { Exact, WSAPIOperation, WsAPIOperationResponseMap, WsAPITopicRequestParamMap, WsAPIWsKeyTopicMap, WsOperation, WsRequestOperationBybit } from './types/websockets/ws-api';
|
|
6
|
+
export declare class WebsocketClient extends BaseWebsocketClient<WsKey, WsRequestOperationBybit<WsTopic>> {
|
|
7
|
+
/**
|
|
8
|
+
* Request connection of all dependent (public & private) websockets, instead of waiting
|
|
9
|
+
* for automatic connection by SDK.
|
|
10
|
+
*/
|
|
11
|
+
connectAll(): Promise<WSConnectedResult | undefined>[];
|
|
12
|
+
/**
|
|
13
|
+
* Ensures the WS API connection is active and ready.
|
|
14
|
+
*
|
|
15
|
+
* You do not need to call this, but if you call this before making any WS API requests,
|
|
16
|
+
* it can accelerate the first request (by preparing the connection in advance).
|
|
17
|
+
*/
|
|
18
|
+
connectWSAPI(): Promise<unknown>;
|
|
19
|
+
connectPublic(): Promise<WSConnectedResult | undefined>[];
|
|
20
|
+
connectPrivate(): Promise<WebSocket | undefined>;
|
|
50
21
|
/**
|
|
51
22
|
* Subscribe to V5 topics & track/persist them.
|
|
52
23
|
* @param wsTopics - topic or list of topics
|
|
53
|
-
* @param category - the API category this topic is for (e.g. "linear").
|
|
54
|
-
*
|
|
24
|
+
* @param category - the API category this topic is for (e.g. "linear").
|
|
25
|
+
* The value is only important when connecting to public topics and will be ignored for private topics.
|
|
26
|
+
* @param isPrivateTopic - optional - the library will try to detect private topics, you can use this
|
|
27
|
+
* to mark a topic as private (if the topic isn't recognised yet)
|
|
55
28
|
*/
|
|
56
|
-
subscribeV5(wsTopics: WsTopic[] | WsTopic, category: CategoryV5, isPrivateTopic?: boolean): Promise<
|
|
29
|
+
subscribeV5(wsTopics: WsTopic[] | WsTopic, category: CategoryV5, isPrivateTopic?: boolean): Promise<unknown>[];
|
|
57
30
|
/**
|
|
58
|
-
*
|
|
31
|
+
* Unsubscribe from V5 topics & remove them from memory. They won't be re-subscribed to if the
|
|
32
|
+
* connection reconnects.
|
|
59
33
|
*
|
|
60
|
-
* Note: for public V5 topics use the `subscribeV5()` method.
|
|
61
|
-
*
|
|
62
|
-
* Topics will be automatically resubscribed to if the connection resets/drops/reconnects.
|
|
63
34
|
* @param wsTopics - topic or list of topics
|
|
64
|
-
* @param
|
|
35
|
+
* @param category - the API category this topic is for (e.g. "linear"). The value is only
|
|
36
|
+
* important when connecting to public topics and will be ignored for private topics.
|
|
37
|
+
* @param isPrivateTopic - optional - the library will try to detect private topics, you can
|
|
38
|
+
* use this to mark a topic as private (if the topic isn't recognised yet)
|
|
65
39
|
*/
|
|
66
|
-
|
|
67
|
-
private upsertPendingTopicsSubscriptions;
|
|
40
|
+
unsubscribeV5(wsTopics: WsTopic[] | WsTopic, category: CategoryV5, isPrivateTopic?: boolean): Promise<unknown>[];
|
|
68
41
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
42
|
+
* Note: subscribeV5() might be simpler to use. The end result is the same.
|
|
43
|
+
*
|
|
44
|
+
* Request subscription to one or more topics. Pass topics as either an array of strings,
|
|
45
|
+
* or array of objects (if the topic has parameters).
|
|
46
|
+
*
|
|
47
|
+
* Objects should be formatted as {topic: string, params: object, category: CategoryV5}.
|
|
48
|
+
*
|
|
49
|
+
* - Subscriptions are automatically routed to the correct websocket connection.
|
|
50
|
+
* - Authentication/connection is automatic.
|
|
51
|
+
* - Resubscribe after network issues is automatic.
|
|
52
|
+
*
|
|
53
|
+
* Call `unsubscribe(topics)` to remove topics
|
|
54
|
+
*/
|
|
55
|
+
subscribe(requests: (WsTopicRequest<WsTopic> | WsTopic) | (WsTopicRequest<WsTopic> | WsTopic)[], wsKey?: WsKey): void;
|
|
56
|
+
/**
|
|
57
|
+
* Note: unsubscribe() might be simpler to use. The end result is the same.
|
|
58
|
+
* Unsubscribe from one or more topics. Similar to subscribe() but in reverse.
|
|
59
|
+
*
|
|
60
|
+
* - Requests are automatically routed to the correct websocket connection.
|
|
61
|
+
* - These topics will be removed from the topic cache, so they won't be subscribed to again.
|
|
62
|
+
*/
|
|
63
|
+
unsubscribe(requests: (WsTopicRequest<WsTopic> | WsTopic) | (WsTopicRequest<WsTopic> | WsTopic)[], wsKey?: WsKey): void;
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
*
|
|
67
|
+
*
|
|
68
|
+
* WS API Methods - similar to the REST API, but via WebSockets
|
|
69
|
+
* https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline
|
|
70
|
+
*
|
|
71
|
+
*
|
|
72
|
+
*
|
|
73
73
|
*/
|
|
74
|
-
unsubscribeV5(wsTopics: WsTopic[] | WsTopic, category: CategoryV5, isPrivateTopic?: boolean): void;
|
|
75
|
-
private removeTopicPendingSubscription;
|
|
76
|
-
private clearTopicsPendingSubscriptions;
|
|
77
74
|
/**
|
|
78
|
-
*
|
|
75
|
+
* Send a Websocket API command/request on a connection. Returns a promise that resolves on reply.
|
|
76
|
+
*
|
|
77
|
+
* WS API Documentation for list of operations and parameters:
|
|
78
|
+
* https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline
|
|
79
79
|
*
|
|
80
|
-
*
|
|
80
|
+
* Returned promise is rejected if:
|
|
81
|
+
* - an exception is detected in the reply, OR
|
|
82
|
+
* - the connection disconnects for any reason (even if automatic reconnect will happen).
|
|
81
83
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
+
* Authentication is automatic. If you didn't request authentication yourself, there might
|
|
85
|
+
* be a small delay after your first request, while the SDK automatically authenticates.
|
|
86
|
+
*
|
|
87
|
+
* @param wsKey - The connection this event is for. Currently only "v5PrivateTrade" is supported
|
|
88
|
+
* for Bybit, since that is the dedicated WS API connection.
|
|
89
|
+
* @param operation - The command being sent, e.g. "order.create" to submit a new order.
|
|
90
|
+
* @param params - Any request parameters for the command. E.g. `OrderParamsV5` to submit a new
|
|
91
|
+
* order. Only send parameters for the request body. Everything else is automatically handled.
|
|
92
|
+
* @returns Promise - tries to resolve with async WS API response. Rejects if disconnected or exception is seen in async WS API response
|
|
84
93
|
*/
|
|
85
|
-
|
|
94
|
+
sendWSAPIRequest<TWSKey extends keyof WsAPIWsKeyTopicMap, TWSOperation extends WsAPIWsKeyTopicMap[TWSKey], TWSParams extends Exact<WsAPITopicRequestParamMap[TWSOperation]>>(wsKey: TWSKey, operation: TWSOperation, ...params: TWSParams extends undefined ? [] : [TWSParams]): Promise<WsAPIOperationResponseMap[TWSOperation]>;
|
|
95
|
+
sendWSAPIRequest<TWSOpreation extends WSAPIOperation = 'order.create'>(wsKey: typeof WS_KEY_MAP.v5PrivateTrade, operation: TWSOpreation, params: WsAPITopicRequestParamMap[TWSOpreation]): Promise<WsAPIOperationResponseMap[TWSOpreation]>;
|
|
96
|
+
sendWSAPIRequest<TWSOpreation extends WSAPIOperation = 'order.amend'>(wsKey: typeof WS_KEY_MAP.v5PrivateTrade, operation: TWSOpreation, params: WsAPITopicRequestParamMap[TWSOpreation]): Promise<WsAPIOperationResponseMap[TWSOpreation]>;
|
|
97
|
+
sendWSAPIRequest<TWSOpreation extends WSAPIOperation = 'order.cancel'>(wsKey: typeof WS_KEY_MAP.v5PrivateTrade, operation: TWSOpreation, params: WsAPITopicRequestParamMap[TWSOpreation]): Promise<WsAPIOperationResponseMap[TWSOpreation]>;
|
|
86
98
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
99
|
+
*
|
|
100
|
+
*
|
|
101
|
+
* Internal methods - not intended for public use
|
|
102
|
+
*
|
|
103
|
+
*
|
|
89
104
|
*/
|
|
90
|
-
private prepareRESTClient;
|
|
91
|
-
close(wsKey: WsKey, force?: boolean): void;
|
|
92
|
-
closeAll(force?: boolean): void;
|
|
93
105
|
/**
|
|
94
|
-
*
|
|
106
|
+
* @returns The WS URL to connect to for this WS key
|
|
95
107
|
*/
|
|
96
|
-
|
|
97
|
-
connectPublic(): Promise<WebSocket | undefined>[];
|
|
98
|
-
connectPrivate(): Promise<WebSocket | undefined>;
|
|
99
|
-
private connect;
|
|
100
|
-
private parseWsError;
|
|
108
|
+
protected getWsUrl(wsKey: WsKey): Promise<string>;
|
|
101
109
|
/**
|
|
102
110
|
* Return params required to make authorized request
|
|
103
111
|
*/
|
|
104
|
-
private
|
|
105
|
-
private
|
|
112
|
+
private getWsAuthURLSuffix;
|
|
113
|
+
private signMessage;
|
|
114
|
+
protected getWsAuthRequestEvent(wsKey: WsKey): Promise<WsRequestOperationBybit<string>>;
|
|
106
115
|
private getWsAuthSignature;
|
|
107
|
-
private
|
|
108
|
-
|
|
116
|
+
private signWSAPIRequest;
|
|
117
|
+
protected sendPingEvent(wsKey: WsKey): void;
|
|
118
|
+
protected sendPongEvent(wsKey: WsKey): void;
|
|
119
|
+
/** Force subscription requests to be sent in smaller batches, if a number is returned */
|
|
120
|
+
protected getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null;
|
|
109
121
|
/**
|
|
110
|
-
*
|
|
111
|
-
* If closed, trigger a reconnect immediately
|
|
122
|
+
* @returns one or more correctly structured request events for performing a operations over WS. This can vary per exchange spec.
|
|
112
123
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
private clearPongTimer;
|
|
117
|
-
private clearReconnectTimer;
|
|
124
|
+
protected getWsRequestEvents(market: WsMarket, operation: WsOperation, requests: WsTopicRequest<string>[], wsKey: WsKey): Promise<MidflightWsRequestEvent<WsRequestOperationBybit<WsTopic>>[]>;
|
|
125
|
+
protected getPrivateWSKeys(): WsKey[];
|
|
126
|
+
protected isAuthOnConnectWsKey(wsKey: WsKey): boolean;
|
|
118
127
|
/**
|
|
119
|
-
*
|
|
128
|
+
* Determines if a topic is for a private channel, using a hardcoded list of strings
|
|
120
129
|
*/
|
|
121
|
-
|
|
130
|
+
protected isPrivateTopicRequest(request: WsTopicRequest<string>): boolean;
|
|
131
|
+
protected isWsPing(msg: any): boolean;
|
|
132
|
+
protected isWsPong(msg: any): boolean;
|
|
122
133
|
/**
|
|
123
|
-
*
|
|
134
|
+
* Abstraction called to sort ws events into emittable event types (response to a request, data update, etc)
|
|
124
135
|
*/
|
|
125
|
-
|
|
126
|
-
tryWsSend(wsKey: WsKey, wsMessage: string): void;
|
|
127
|
-
private connectToWsUrl;
|
|
128
|
-
private onWsOpen;
|
|
129
|
-
private onWsMessage;
|
|
130
|
-
private updatePendingTopicSubscriptionStatus;
|
|
131
|
-
private onWsClose;
|
|
132
|
-
private getWs;
|
|
133
|
-
private setWsState;
|
|
134
|
-
private wrongMarketError;
|
|
135
|
-
/** @deprecated use "market: 'spotv3" client */
|
|
136
|
-
subscribePublicSpotTrades(symbol: string, binary?: boolean): void;
|
|
137
|
-
/** @deprecated use "market: 'spotv3" client */
|
|
138
|
-
subscribePublicSpotTradingPair(symbol: string, binary?: boolean): void;
|
|
139
|
-
/** @deprecated use "market: 'spotv3" client */
|
|
140
|
-
subscribePublicSpotV1Kline(symbol: string, candleSize: KlineInterval, binary?: boolean): void;
|
|
141
|
-
/** @deprecated use "market: 'spotv3" client */
|
|
142
|
-
subscribePublicSpotOrderbook(symbol: string, depth: 'full' | 'merge' | 'delta', dumpScale?: number, binary?: boolean): void;
|
|
136
|
+
protected resolveEmittableEvents(wsKey: WsKey, event: MessageEventLike): EmittableEvent[];
|
|
143
137
|
}
|
|
144
|
-
export {};
|