bybit-api 2.4.0-beta.2 → 3.0.2
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 +62 -43
- package/lib/inverse-client.d.ts +18 -126
- package/lib/inverse-client.js.map +1 -1
- package/lib/linear-client.d.ts +20 -142
- package/lib/linear-client.js.map +1 -1
- package/lib/spot-client-v3.d.ts +2 -6
- package/lib/spot-client-v3.js.map +1 -1
- package/lib/spot-client.js +1 -1
- package/lib/spot-client.js.map +1 -1
- package/lib/types/request/index.d.ts +2 -1
- package/lib/types/request/index.js +2 -1
- package/lib/types/request/index.js.map +1 -1
- package/lib/types/request/inverse.d.ts +120 -0
- package/lib/types/request/{usdt-perp.js → inverse.js} +1 -1
- package/lib/types/request/inverse.js.map +1 -0
- package/lib/types/request/linear.d.ts +160 -0
- package/lib/types/request/linear.js +3 -0
- package/lib/types/request/linear.js.map +1 -0
- package/lib/types/request/spot.d.ts +5 -0
- package/lib/types/shared.d.ts +2 -1
- package/lib/types/websockets.d.ts +1 -1
- package/lib/util/BaseRestClient.d.ts +4 -8
- package/lib/util/BaseRestClient.js +16 -23
- package/lib/util/BaseRestClient.js.map +1 -1
- package/lib/util/WsStore.d.ts +1 -1
- package/lib/util/requestUtils.d.ts +8 -4
- package/lib/util/requestUtils.js +9 -6
- package/lib/util/requestUtils.js.map +1 -1
- package/lib/util/websocket-util.d.ts +6 -1
- package/lib/util/websocket-util.js +86 -1
- package/lib/util/websocket-util.js.map +1 -1
- package/lib/websocket-client.d.ts +31 -22
- package/lib/websocket-client.js +143 -72
- package/lib/websocket-client.js.map +1 -1
- package/package.json +2 -2
- package/lib/types/request/usdt-perp.d.ts +0 -20
- package/lib/types/request/usdt-perp.js.map +0 -1
|
@@ -6,7 +6,7 @@ interface NetworkMapV3 {
|
|
|
6
6
|
testnet2?: string;
|
|
7
7
|
}
|
|
8
8
|
declare type PublicPrivateNetwork = 'public' | 'private';
|
|
9
|
-
export declare const WS_BASE_URL_MAP: Record<APIMarket, Record<PublicPrivateNetwork, NetworkMapV3>>;
|
|
9
|
+
export declare const WS_BASE_URL_MAP: Record<APIMarket | 'unifiedPerpUSDT' | 'unifiedPerpUSDC', Record<PublicPrivateNetwork, NetworkMapV3>>;
|
|
10
10
|
export declare const WS_KEY_MAP: {
|
|
11
11
|
readonly inverse: "inverse";
|
|
12
12
|
readonly linearPrivate: "linearPrivate";
|
|
@@ -19,10 +19,15 @@ export declare const WS_KEY_MAP: {
|
|
|
19
19
|
readonly usdcOptionPublic: "usdcOptionPublic";
|
|
20
20
|
readonly usdcPerpPrivate: "usdcPerpPrivate";
|
|
21
21
|
readonly usdcPerpPublic: "usdcPerpPublic";
|
|
22
|
+
readonly unifiedPrivate: "unifiedPrivate";
|
|
23
|
+
readonly unifiedOptionPublic: "unifiedOptionPublic";
|
|
24
|
+
readonly unifiedPerpUSDTPublic: "unifiedPerpUSDTPublic";
|
|
25
|
+
readonly unifiedPerpUSDCPublic: "unifiedPerpUSDCPublic";
|
|
22
26
|
};
|
|
23
27
|
export declare const WS_AUTH_ON_CONNECT_KEYS: WsKey[];
|
|
24
28
|
export declare const PUBLIC_WS_KEYS: string[];
|
|
25
29
|
export declare function getWsKeyForTopic(market: APIMarket, topic: string, isPrivate?: boolean): WsKey;
|
|
30
|
+
export declare function getMaxTopicsPerSubscribeEvent(market: APIMarket): number | null;
|
|
26
31
|
export declare function getUsdcWsKeyForTopic(topic: string, subGroup: 'option' | 'perp'): WsKey;
|
|
27
32
|
export declare const WS_ERROR_ENUM: {
|
|
28
33
|
NOT_AUTHENTICATED_SPOT_V3: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.neverGuard = exports.WS_ERROR_ENUM = exports.getUsdcWsKeyForTopic = exports.getWsKeyForTopic = exports.PUBLIC_WS_KEYS = exports.WS_AUTH_ON_CONNECT_KEYS = exports.WS_KEY_MAP = exports.WS_BASE_URL_MAP = void 0;
|
|
3
|
+
exports.neverGuard = exports.WS_ERROR_ENUM = exports.getUsdcWsKeyForTopic = exports.getMaxTopicsPerSubscribeEvent = exports.getWsKeyForTopic = exports.PUBLIC_WS_KEYS = exports.WS_AUTH_ON_CONNECT_KEYS = exports.WS_KEY_MAP = exports.WS_BASE_URL_MAP = void 0;
|
|
4
4
|
exports.WS_BASE_URL_MAP = {
|
|
5
5
|
inverse: {
|
|
6
6
|
public: {
|
|
@@ -70,6 +70,46 @@ exports.WS_BASE_URL_MAP = {
|
|
|
70
70
|
testnet: 'wss://stream-testnet.bybit.com/trade/option/usdc/private/v1',
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
|
+
unifiedOption: {
|
|
74
|
+
public: {
|
|
75
|
+
livenet: 'wss://stream.bybit.com/option/usdc/public/v3',
|
|
76
|
+
testnet: 'wss://stream-testnet.bybit.com/option/usdc/public/v3',
|
|
77
|
+
},
|
|
78
|
+
private: {
|
|
79
|
+
livenet: 'wss://stream.bybit.com/unified/private/v3',
|
|
80
|
+
testnet: 'wss://stream-testnet.bybit.com/unified/private/v3',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
unifiedPerp: {
|
|
84
|
+
public: {
|
|
85
|
+
livenet: 'useBaseSpecificEndpoint',
|
|
86
|
+
testnet: 'useBaseSpecificEndpoint',
|
|
87
|
+
},
|
|
88
|
+
private: {
|
|
89
|
+
livenet: 'wss://stream.bybit.com/unified/private/v3',
|
|
90
|
+
testnet: 'wss://stream-testnet.bybit.com/unified/private/v3',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
unifiedPerpUSDT: {
|
|
94
|
+
public: {
|
|
95
|
+
livenet: 'wss://stream.bybit.com/contract/usdt/public/v3',
|
|
96
|
+
testnet: 'wss://stream-testnet.bybit.com/contract/usdt/public/v3',
|
|
97
|
+
},
|
|
98
|
+
private: {
|
|
99
|
+
livenet: 'useUnifiedEndpoint',
|
|
100
|
+
testnet: 'useUnifiedEndpoint',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
unifiedPerpUSDC: {
|
|
104
|
+
public: {
|
|
105
|
+
livenet: 'wss://stream.bybit.com/contract/usdc/public/v3',
|
|
106
|
+
testnet: 'wss://stream-testnet.bybit.com/contract/usdc/public/v3',
|
|
107
|
+
},
|
|
108
|
+
private: {
|
|
109
|
+
livenet: 'useUnifiedEndpoint',
|
|
110
|
+
testnet: 'useUnifiedEndpoint',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
73
113
|
};
|
|
74
114
|
exports.WS_KEY_MAP = {
|
|
75
115
|
inverse: 'inverse',
|
|
@@ -83,6 +123,10 @@ exports.WS_KEY_MAP = {
|
|
|
83
123
|
usdcOptionPublic: 'usdcOptionPublic',
|
|
84
124
|
usdcPerpPrivate: 'usdcPerpPrivate',
|
|
85
125
|
usdcPerpPublic: 'usdcPerpPublic',
|
|
126
|
+
unifiedPrivate: 'unifiedPrivate',
|
|
127
|
+
unifiedOptionPublic: 'unifiedOptionPublic',
|
|
128
|
+
unifiedPerpUSDTPublic: 'unifiedPerpUSDTPublic',
|
|
129
|
+
unifiedPerpUSDCPublic: 'unifiedPerpUSDCPublic',
|
|
86
130
|
};
|
|
87
131
|
exports.WS_AUTH_ON_CONNECT_KEYS = [
|
|
88
132
|
exports.WS_KEY_MAP.spotV3Private,
|
|
@@ -95,6 +139,9 @@ exports.PUBLIC_WS_KEYS = [
|
|
|
95
139
|
exports.WS_KEY_MAP.spotV3Public,
|
|
96
140
|
exports.WS_KEY_MAP.usdcOptionPublic,
|
|
97
141
|
exports.WS_KEY_MAP.usdcPerpPublic,
|
|
142
|
+
exports.WS_KEY_MAP.unifiedOptionPublic,
|
|
143
|
+
exports.WS_KEY_MAP.unifiedPerpUSDTPublic,
|
|
144
|
+
exports.WS_KEY_MAP.unifiedPerpUSDCPublic,
|
|
98
145
|
];
|
|
99
146
|
/** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */
|
|
100
147
|
const PRIVATE_TOPICS = [
|
|
@@ -160,12 +207,50 @@ function getWsKeyForTopic(market, topic, isPrivate) {
|
|
|
160
207
|
? exports.WS_KEY_MAP.usdcPerpPrivate
|
|
161
208
|
: exports.WS_KEY_MAP.usdcPerpPublic;
|
|
162
209
|
}
|
|
210
|
+
case 'unifiedOption': {
|
|
211
|
+
return isPrivateTopic
|
|
212
|
+
? exports.WS_KEY_MAP.unifiedPrivate
|
|
213
|
+
: exports.WS_KEY_MAP.unifiedOptionPublic;
|
|
214
|
+
}
|
|
215
|
+
case 'unifiedPerp': {
|
|
216
|
+
if (isPrivateTopic) {
|
|
217
|
+
return exports.WS_KEY_MAP.unifiedPrivate;
|
|
218
|
+
}
|
|
219
|
+
const upperTopic = topic.toUpperCase();
|
|
220
|
+
if (upperTopic.indexOf('USDT') !== -1) {
|
|
221
|
+
return exports.WS_KEY_MAP.unifiedPerpUSDTPublic;
|
|
222
|
+
}
|
|
223
|
+
if (upperTopic.indexOf('USDC') !== -1) {
|
|
224
|
+
return exports.WS_KEY_MAP.unifiedPerpUSDCPublic;
|
|
225
|
+
}
|
|
226
|
+
throw new Error(`Failed to determine wskey for unified perps topic: "${topic}`);
|
|
227
|
+
}
|
|
163
228
|
default: {
|
|
164
229
|
throw neverGuard(market, `getWsKeyForTopic(): Unhandled market`);
|
|
165
230
|
}
|
|
166
231
|
}
|
|
167
232
|
}
|
|
168
233
|
exports.getWsKeyForTopic = getWsKeyForTopic;
|
|
234
|
+
function getMaxTopicsPerSubscribeEvent(market) {
|
|
235
|
+
switch (market) {
|
|
236
|
+
case 'inverse':
|
|
237
|
+
case 'linear':
|
|
238
|
+
case 'usdcOption':
|
|
239
|
+
case 'usdcPerp':
|
|
240
|
+
case 'unifiedOption':
|
|
241
|
+
case 'unifiedPerp':
|
|
242
|
+
case 'spot': {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
case 'spotv3': {
|
|
246
|
+
return 10;
|
|
247
|
+
}
|
|
248
|
+
default: {
|
|
249
|
+
throw neverGuard(market, `getWsKeyForTopic(): Unhandled market`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.getMaxTopicsPerSubscribeEvent = getMaxTopicsPerSubscribeEvent;
|
|
169
254
|
function getUsdcWsKeyForTopic(topic, subGroup) {
|
|
170
255
|
const isPrivateTopic = PRIVATE_TOPICS.includes(topic);
|
|
171
256
|
if (subGroup === 'option') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-util.js","sourceRoot":"","sources":["../../src/util/websocket-util.ts"],"names":[],"mappings":";;;AAWa,QAAA,eAAe,GAGxB;IACF,OAAO,EAAE;QACP,MAAM,EAAE;YACN,OAAO,EAAE,iCAAiC;YAC1C,OAAO,EAAE,yCAAyC;SACnD;QACD,OAAO,EAAE;YACP,OAAO,EAAE,iCAAiC;YAC1C,OAAO,EAAE,yCAAyC;SACnD;KACF;IACD,MAAM,EAAE;QACN,MAAM,EAAE;YACN,OAAO,EAAE,wCAAwC;YACjD,QAAQ,EAAE,yCAAyC;YACnD,OAAO,EAAE,gDAAgD;SAC1D;QACD,OAAO,EAAE;YACP,OAAO,EAAE,yCAAyC;YAClD,QAAQ,EAAE,0CAA0C;YACpD,OAAO,EAAE,iDAAiD;SAC3D;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE;YACN,OAAO,EAAE,yCAAyC;YAClD,QAAQ,EAAE,yCAAyC;YACnD,OAAO,EAAE,iDAAiD;YAC1D,QAAQ,EAAE,iDAAiD;SAC5D;QACD,OAAO,EAAE;YACP,OAAO,EAAE,gCAAgC;YACzC,OAAO,EAAE,wCAAwC;SAClD;KACF;IACD,MAAM,EAAE;QACN,MAAM,EAAE;YACN,OAAO,EAAE,uCAAuC;YAChD,OAAO,EAAE,+CAA+C;SACzD;QACD,OAAO,EAAE;YACP,OAAO,EAAE,wCAAwC;YACjD,OAAO,EAAE,gDAAgD;SAC1D;KACF;IACD,UAAU,EAAE;QACV,MAAM,EAAE;YACN,OAAO,EAAE,oDAAoD;YAC7D,QAAQ,EAAE,qDAAqD;YAC/D,OAAO,EAAE,4DAA4D;SACtE;QACD,OAAO,EAAE;YACP,OAAO,EAAE,qDAAqD;YAC9D,QAAQ,EAAE,sDAAsD;YAChE,OAAO,EAAE,6DAA6D;SACvE;KACF;IACD,QAAQ,EAAE;QACR,MAAM,EAAE;YACN,OAAO,EAAE,wDAAwD;YACjE,QAAQ,EAAE,yDAAyD;YACnE,OAAO,EAAE,gEAAgE;SAC1E;QACD,OAAO,EAAE;YACP,OAAO,EAAE,qDAAqD;YAC9D,QAAQ,EAAE,sDAAsD;YAChE,OAAO,EAAE,6DAA6D;SACvE;KACF;CACF,CAAC;AAEW,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;IAC9B,YAAY,EAAE,cAAc;IAC5B,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,eAAe;IAC9B,YAAY,EAAE,cAAc;IAC5B,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;
|
|
1
|
+
{"version":3,"file":"websocket-util.js","sourceRoot":"","sources":["../../src/util/websocket-util.ts"],"names":[],"mappings":";;;AAWa,QAAA,eAAe,GAGxB;IACF,OAAO,EAAE;QACP,MAAM,EAAE;YACN,OAAO,EAAE,iCAAiC;YAC1C,OAAO,EAAE,yCAAyC;SACnD;QACD,OAAO,EAAE;YACP,OAAO,EAAE,iCAAiC;YAC1C,OAAO,EAAE,yCAAyC;SACnD;KACF;IACD,MAAM,EAAE;QACN,MAAM,EAAE;YACN,OAAO,EAAE,wCAAwC;YACjD,QAAQ,EAAE,yCAAyC;YACnD,OAAO,EAAE,gDAAgD;SAC1D;QACD,OAAO,EAAE;YACP,OAAO,EAAE,yCAAyC;YAClD,QAAQ,EAAE,0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E,sCAAsC,CAAC,CAAC;SAClE;KACF;AACH,CAAC;AApBD,sEAoBC;AAED,SAAgB,oBAAoB,CAClC,KAAa,EACb,QAA2B;IAE3B,MAAM,cAAc,GAAG,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACzB,OAAO,cAAc;YACnB,CAAC,CAAC,kBAAU,CAAC,iBAAiB;YAC9B,CAAC,CAAC,kBAAU,CAAC,gBAAgB,CAAC;KACjC;IACD,OAAO,cAAc;QACnB,CAAC,CAAC,kBAAU,CAAC,iBAAiB;QAC9B,CAAC,CAAC,kBAAU,CAAC,gBAAgB,CAAC;IAChC,wBAAwB;IACxB,iCAAiC;IACjC,iCAAiC;AACnC,CAAC;AAhBD,oDAgBC;AAEY,QAAA,aAAa,GAAG;IAC3B,yBAAyB,EAAE,OAAO;IAClC,iBAAiB,EAAE,OAAO;IAC1B,oBAAoB,EAAE,OAAO;IAC7B,uBAAuB,EAAE,SAAS;CACnC,CAAC;AAEF,SAAgB,UAAU,CAAC,CAAQ,EAAE,GAAW;IAC9C,OAAO,IAAI,KAAK,CAAC,kCAAkC,GAAG,EAAE,CAAC,CAAC;AAC5D,CAAC;AAFD,gCAEC"}
|
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import WebSocket from 'isomorphic-ws';
|
|
4
|
+
import WsStore from './util/WsStore';
|
|
4
5
|
import { KlineInterval, WSClientConfigurableOptions, WsKey, WsTopic } from './types';
|
|
5
6
|
import { DefaultLogger } from './util';
|
|
6
|
-
export declare type WsClientEvent = 'open' | 'update' | 'close' | '
|
|
7
|
+
export declare type WsClientEvent = 'open' | 'update' | 'close' | 'error' | 'reconnect' | 'reconnected' | 'response';
|
|
7
8
|
interface WebsocketClientEvents {
|
|
9
|
+
/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
|
|
8
10
|
open: (evt: {
|
|
9
11
|
wsKey: WsKey;
|
|
10
12
|
event: any;
|
|
11
13
|
}) => void;
|
|
14
|
+
/** Reconnecting a dropped connection */
|
|
12
15
|
reconnect: (evt: {
|
|
13
16
|
wsKey: WsKey;
|
|
14
17
|
event: any;
|
|
15
18
|
}) => void;
|
|
19
|
+
/** Successfully reconnected a connection that dropped */
|
|
16
20
|
reconnected: (evt: {
|
|
17
21
|
wsKey: WsKey;
|
|
18
22
|
event: any;
|
|
19
23
|
}) => void;
|
|
24
|
+
/** Connection closed */
|
|
20
25
|
close: (evt: {
|
|
21
26
|
wsKey: WsKey;
|
|
22
27
|
event: any;
|
|
23
28
|
}) => void;
|
|
29
|
+
/** Received reply to websocket command (e.g. after subscribing to topics) */
|
|
24
30
|
response: (response: any) => void;
|
|
31
|
+
/** Received data for topic */
|
|
25
32
|
update: (response: any) => void;
|
|
26
|
-
|
|
33
|
+
/** Exception from ws client OR custom listeners */
|
|
34
|
+
error: (response: any) => void;
|
|
27
35
|
}
|
|
28
36
|
export declare interface WebsocketClient {
|
|
29
37
|
on<U extends keyof WebsocketClientEvents>(event: U, listener: WebsocketClientEvents[U]): this;
|
|
@@ -36,19 +44,32 @@ export declare class WebsocketClient extends EventEmitter {
|
|
|
36
44
|
private wsStore;
|
|
37
45
|
constructor(options: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
|
|
38
46
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
47
|
+
* Subscribe to topics & track/persist them. They will be automatically resubscribed to if the connection drops/reconnects.
|
|
48
|
+
* @param wsTopics topic or list of topics
|
|
49
|
+
* @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)
|
|
50
|
+
*/
|
|
51
|
+
subscribe(wsTopics: WsTopic[] | WsTopic, isPrivateTopic?: boolean): void;
|
|
52
|
+
/**
|
|
53
|
+
* Unsubscribe from topics & remove them from memory. They won't be re-subscribed to if the connection reconnects.
|
|
54
|
+
* @param wsTopics topic or list of topics
|
|
55
|
+
* @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)
|
|
56
|
+
*/
|
|
57
|
+
unsubscribe(wsTopics: WsTopic[] | WsTopic, isPrivateTopic?: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* @private Only used if we fetch exchange time before attempting auth. Disabled by default.
|
|
41
60
|
* I've removed this for ftx and it's working great, tempted to remove this here
|
|
42
61
|
*/
|
|
43
|
-
prepareRESTClient
|
|
62
|
+
private prepareRESTClient;
|
|
63
|
+
/** Get the WsStore that tracks websockets & topics */
|
|
64
|
+
getWsStore(): WsStore;
|
|
44
65
|
isTestnet(): boolean;
|
|
45
|
-
close(wsKey: WsKey): void;
|
|
46
|
-
closeAll(): void;
|
|
66
|
+
close(wsKey: WsKey, force?: boolean): void;
|
|
67
|
+
closeAll(force?: boolean): void;
|
|
47
68
|
/**
|
|
48
69
|
* Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
|
|
49
70
|
*/
|
|
50
71
|
connectAll(): Promise<WebSocket | undefined>[];
|
|
51
|
-
connectPublic(): Promise<WebSocket | undefined
|
|
72
|
+
connectPublic(): Promise<WebSocket | undefined>[];
|
|
52
73
|
connectPrivate(): Promise<WebSocket | undefined>;
|
|
53
74
|
private connect;
|
|
54
75
|
private parseWsError;
|
|
@@ -64,11 +85,11 @@ export declare class WebsocketClient extends EventEmitter {
|
|
|
64
85
|
private clearPingTimer;
|
|
65
86
|
private clearPongTimer;
|
|
66
87
|
/**
|
|
67
|
-
* Send WS message to subscribe to topics.
|
|
88
|
+
* @private Use the `subscribe(topics)` method to subscribe to topics. Send WS message to subscribe to topics.
|
|
68
89
|
*/
|
|
69
90
|
private requestSubscribeTopics;
|
|
70
91
|
/**
|
|
71
|
-
* Send WS message to unsubscribe from topics.
|
|
92
|
+
* @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics.
|
|
72
93
|
*/
|
|
73
94
|
private requestUnsubscribeTopics;
|
|
74
95
|
tryWsSend(wsKey: WsKey, wsMessage: string): void;
|
|
@@ -81,18 +102,6 @@ export declare class WebsocketClient extends EventEmitter {
|
|
|
81
102
|
private setWsState;
|
|
82
103
|
private getWsUrl;
|
|
83
104
|
private wrongMarketError;
|
|
84
|
-
/**
|
|
85
|
-
* Add topic/topics to WS subscription list
|
|
86
|
-
* @param wsTopics topic or list of topics
|
|
87
|
-
* @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)
|
|
88
|
-
*/
|
|
89
|
-
subscribe(wsTopics: WsTopic[] | WsTopic, isPrivateTopic?: boolean): void;
|
|
90
|
-
/**
|
|
91
|
-
* Remove topic/topics from WS subscription list
|
|
92
|
-
* @param wsTopics topic or list of topics
|
|
93
|
-
* @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)
|
|
94
|
-
*/
|
|
95
|
-
unsubscribe(wsTopics: WsTopic[] | WsTopic, isPrivateTopic?: boolean): void;
|
|
96
105
|
/** @deprecated use "market: 'spotv3" client */
|
|
97
106
|
subscribePublicSpotTrades(symbol: string, binary?: boolean): void;
|
|
98
107
|
/** @deprecated use "market: 'spotv3" client */
|