bybit-api 2.3.2 → 2.4.0-beta.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.
Files changed (95) hide show
  1. package/README.md +74 -153
  2. package/lib/account-asset-client.d.ts +42 -0
  3. package/lib/account-asset-client.js +104 -0
  4. package/lib/account-asset-client.js.map +1 -0
  5. package/lib/constants/enum.d.ts +18 -0
  6. package/lib/constants/enum.js +18 -0
  7. package/lib/constants/enum.js.map +1 -1
  8. package/lib/copy-trading-client.d.ts +54 -0
  9. package/lib/copy-trading-client.js +112 -0
  10. package/lib/copy-trading-client.js.map +1 -0
  11. package/lib/index.d.ts +8 -2
  12. package/lib/index.js +8 -2
  13. package/lib/index.js.map +1 -1
  14. package/lib/inverse-client.d.ts +5 -13
  15. package/lib/inverse-client.js +6 -13
  16. package/lib/inverse-client.js.map +1 -1
  17. package/lib/inverse-futures-client.d.ts +4 -12
  18. package/lib/inverse-futures-client.js +5 -12
  19. package/lib/inverse-futures-client.js.map +1 -1
  20. package/lib/linear-client.d.ts +4 -12
  21. package/lib/linear-client.js +5 -12
  22. package/lib/linear-client.js.map +1 -1
  23. package/lib/spot-client-v3.d.ts +105 -0
  24. package/lib/spot-client-v3.js +222 -0
  25. package/lib/spot-client-v3.js.map +1 -0
  26. package/lib/spot-client.d.ts +5 -12
  27. package/lib/spot-client.js +6 -12
  28. package/lib/spot-client.js.map +1 -1
  29. package/lib/types/index.d.ts +1 -1
  30. package/lib/types/index.js +1 -1
  31. package/lib/types/index.js.map +1 -1
  32. package/lib/types/request/account-asset.d.ts +76 -0
  33. package/lib/types/request/account-asset.js +3 -0
  34. package/lib/types/request/account-asset.js.map +1 -0
  35. package/lib/types/request/copy-trading.d.ts +47 -0
  36. package/lib/types/request/copy-trading.js +3 -0
  37. package/lib/types/request/copy-trading.js.map +1 -0
  38. package/lib/types/request/index.d.ts +7 -0
  39. package/lib/types/request/index.js +7 -0
  40. package/lib/types/request/index.js.map +1 -1
  41. package/lib/types/request/spot.d.ts +72 -0
  42. package/lib/types/{spot.js → request/spot.js} +0 -0
  43. package/lib/types/{spot.js.map → request/spot.js.map} +1 -1
  44. package/lib/types/request/unified-margin.d.ts +223 -0
  45. package/lib/types/request/unified-margin.js +3 -0
  46. package/lib/types/request/unified-margin.js.map +1 -0
  47. package/lib/types/request/usdc-options.d.ts +119 -0
  48. package/lib/types/request/usdc-options.js +3 -0
  49. package/lib/types/request/usdc-options.js.map +1 -0
  50. package/lib/types/request/usdc-perp.d.ts +86 -0
  51. package/lib/types/request/usdc-perp.js +3 -0
  52. package/lib/types/request/usdc-perp.js.map +1 -0
  53. package/lib/types/request/usdc-shared.d.ts +29 -0
  54. package/lib/types/request/usdc-shared.js +3 -0
  55. package/lib/types/request/usdc-shared.js.map +1 -0
  56. package/lib/types/shared.d.ts +18 -5
  57. package/lib/types/websockets.d.ts +41 -0
  58. package/lib/types/websockets.js +3 -0
  59. package/lib/types/websockets.js.map +1 -0
  60. package/lib/unified-margin-client.d.ts +137 -0
  61. package/lib/unified-margin-client.js +269 -0
  62. package/lib/unified-margin-client.js.map +1 -0
  63. package/lib/usdc-option-client.d.ts +100 -0
  64. package/lib/usdc-option-client.js +186 -0
  65. package/lib/usdc-option-client.js.map +1 -0
  66. package/lib/usdc-perpetual-client.d.ts +88 -0
  67. package/lib/usdc-perpetual-client.js +181 -0
  68. package/lib/usdc-perpetual-client.js.map +1 -0
  69. package/lib/util/BaseRestClient.d.ts +15 -2
  70. package/lib/util/BaseRestClient.js +93 -29
  71. package/lib/util/BaseRestClient.js.map +1 -1
  72. package/lib/util/WsStore.d.ts +40 -17
  73. package/lib/util/WsStore.js +12 -3
  74. package/lib/util/WsStore.js.map +1 -1
  75. package/lib/util/index.d.ts +5 -0
  76. package/lib/util/index.js +18 -0
  77. package/lib/util/index.js.map +1 -0
  78. package/lib/{logger.d.ts → util/logger.d.ts} +0 -0
  79. package/lib/{logger.js → util/logger.js} +0 -0
  80. package/lib/util/logger.js.map +1 -0
  81. package/lib/util/node-support.d.ts +1 -0
  82. package/lib/util/node-support.js +1 -0
  83. package/lib/util/node-support.js.map +1 -1
  84. package/lib/util/requestUtils.d.ts +6 -2
  85. package/lib/util/requestUtils.js +20 -25
  86. package/lib/util/requestUtils.js.map +1 -1
  87. package/lib/util/websocket-util.d.ts +34 -0
  88. package/lib/util/websocket-util.js +194 -0
  89. package/lib/util/websocket-util.js.map +1 -0
  90. package/lib/websocket-client.d.ts +56 -82
  91. package/lib/websocket-client.js +308 -264
  92. package/lib/websocket-client.js.map +1 -1
  93. package/package.json +1 -1
  94. package/lib/logger.js.map +0 -1
  95. package/lib/types/spot.d.ts +0 -30
@@ -0,0 +1,194 @@
1
+ "use strict";
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;
4
+ exports.WS_BASE_URL_MAP = {
5
+ inverse: {
6
+ public: {
7
+ livenet: 'wss://stream.bybit.com/realtime',
8
+ testnet: 'wss://stream-testnet.bybit.com/realtime',
9
+ },
10
+ private: {
11
+ livenet: 'wss://stream.bybit.com/realtime',
12
+ testnet: 'wss://stream-testnet.bybit.com/realtime',
13
+ },
14
+ },
15
+ linear: {
16
+ public: {
17
+ livenet: 'wss://stream.bybit.com/realtime_public',
18
+ livenet2: 'wss://stream.bytick.com/realtime_public',
19
+ testnet: 'wss://stream-testnet.bybit.com/realtime_public',
20
+ },
21
+ private: {
22
+ livenet: 'wss://stream.bybit.com/realtime_private',
23
+ livenet2: 'wss://stream.bytick.com/realtime_private',
24
+ testnet: 'wss://stream-testnet.bybit.com/realtime_private',
25
+ },
26
+ },
27
+ spot: {
28
+ public: {
29
+ livenet: 'wss://stream.bybit.com/spot/quote/ws/v1',
30
+ livenet2: 'wss://stream.bybit.com/spot/quote/ws/v2',
31
+ testnet: 'wss://stream-testnet.bybit.com/spot/quote/ws/v1',
32
+ testnet2: 'wss://stream-testnet.bybit.com/spot/quote/ws/v2',
33
+ },
34
+ private: {
35
+ livenet: 'wss://stream.bybit.com/spot/ws',
36
+ testnet: 'wss://stream-testnet.bybit.com/spot/ws',
37
+ },
38
+ },
39
+ spotv3: {
40
+ public: {
41
+ livenet: 'wss://stream.bybit.com/spot/public/v3',
42
+ testnet: 'wss://stream-testnet.bybit.com/spot/public/v3',
43
+ },
44
+ private: {
45
+ livenet: 'wss://stream.bybit.com/spot/private/v3',
46
+ testnet: 'wss://stream-testnet.bybit.com/spot/private/v3',
47
+ },
48
+ },
49
+ usdcOption: {
50
+ public: {
51
+ livenet: 'wss://stream.bybit.com/trade/option/usdc/public/v1',
52
+ livenet2: 'wss://stream.bytick.com/trade/option/usdc/public/v1',
53
+ testnet: 'wss://stream-testnet.bybit.com/trade/option/usdc/public/v1',
54
+ },
55
+ private: {
56
+ livenet: 'wss://stream.bybit.com/trade/option/usdc/private/v1',
57
+ livenet2: 'wss://stream.bytick.com/trade/option/usdc/private/v1',
58
+ testnet: 'wss://stream-testnet.bybit.com/trade/option/usdc/private/v1',
59
+ },
60
+ },
61
+ usdcPerp: {
62
+ public: {
63
+ livenet: 'wss://stream.bybit.com/perpetual/ws/v1/realtime_public',
64
+ livenet2: 'wss://stream.bytick.com/perpetual/ws/v1/realtime_public',
65
+ testnet: 'wss://stream-testnet.bybit.com/perpetual/ws/v1/realtime_public',
66
+ },
67
+ private: {
68
+ livenet: 'wss://stream.bybit.com/trade/option/usdc/private/v1',
69
+ livenet2: 'wss://stream.bytick.com/trade/option/usdc/private/v1',
70
+ testnet: 'wss://stream-testnet.bybit.com/trade/option/usdc/private/v1',
71
+ },
72
+ },
73
+ };
74
+ exports.WS_KEY_MAP = {
75
+ inverse: 'inverse',
76
+ linearPrivate: 'linearPrivate',
77
+ linearPublic: 'linearPublic',
78
+ spotPrivate: 'spotPrivate',
79
+ spotPublic: 'spotPublic',
80
+ spotV3Private: 'spotV3Private',
81
+ spotV3Public: 'spotV3Public',
82
+ usdcOptionPrivate: 'usdcOptionPrivate',
83
+ usdcOptionPublic: 'usdcOptionPublic',
84
+ usdcPerpPrivate: 'usdcPerpPrivate',
85
+ usdcPerpPublic: 'usdcPerpPublic',
86
+ };
87
+ exports.WS_AUTH_ON_CONNECT_KEYS = [
88
+ exports.WS_KEY_MAP.spotV3Private,
89
+ exports.WS_KEY_MAP.usdcOptionPrivate,
90
+ exports.WS_KEY_MAP.usdcPerpPrivate,
91
+ ];
92
+ exports.PUBLIC_WS_KEYS = [
93
+ exports.WS_KEY_MAP.linearPublic,
94
+ exports.WS_KEY_MAP.spotPublic,
95
+ exports.WS_KEY_MAP.spotV3Public,
96
+ exports.WS_KEY_MAP.usdcOptionPublic,
97
+ exports.WS_KEY_MAP.usdcPerpPublic,
98
+ ];
99
+ /** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */
100
+ const PRIVATE_TOPICS = [
101
+ 'position',
102
+ 'execution',
103
+ 'order',
104
+ 'stop_order',
105
+ 'wallet',
106
+ 'outboundAccountInfo',
107
+ 'executionReport',
108
+ 'ticketInfo',
109
+ // copy trading apis
110
+ 'copyTradePosition',
111
+ 'copyTradeOrder',
112
+ 'copyTradeExecution',
113
+ 'copyTradeWallet',
114
+ // usdc options
115
+ 'user.openapi.option.position',
116
+ 'user.openapi.option.trade',
117
+ 'user.order',
118
+ 'user.openapi.option.order',
119
+ 'user.service',
120
+ 'user.openapi.greeks',
121
+ 'user.mmp.event',
122
+ // usdc perps
123
+ 'user.openapi.perp.position',
124
+ 'user.openapi.perp.trade',
125
+ 'user.openapi.perp.order',
126
+ 'user.service',
127
+ // unified margin
128
+ 'user.position.unifiedAccount',
129
+ 'user.execution.unifiedAccount',
130
+ 'user.order.unifiedAccount',
131
+ 'user.wallet.unifiedAccount',
132
+ 'user.greeks.unifiedAccount',
133
+ ];
134
+ function getWsKeyForTopic(market, topic, isPrivate) {
135
+ const isPrivateTopic = isPrivate === true || PRIVATE_TOPICS.includes(topic);
136
+ switch (market) {
137
+ case 'inverse': {
138
+ return exports.WS_KEY_MAP.inverse;
139
+ }
140
+ case 'linear': {
141
+ return isPrivateTopic
142
+ ? exports.WS_KEY_MAP.linearPrivate
143
+ : exports.WS_KEY_MAP.linearPublic;
144
+ }
145
+ case 'spot': {
146
+ return isPrivateTopic ? exports.WS_KEY_MAP.spotPrivate : exports.WS_KEY_MAP.spotPublic;
147
+ }
148
+ case 'spotv3': {
149
+ return isPrivateTopic
150
+ ? exports.WS_KEY_MAP.spotV3Private
151
+ : exports.WS_KEY_MAP.spotV3Public;
152
+ }
153
+ case 'usdcOption': {
154
+ return isPrivateTopic
155
+ ? exports.WS_KEY_MAP.usdcOptionPrivate
156
+ : exports.WS_KEY_MAP.usdcOptionPublic;
157
+ }
158
+ case 'usdcPerp': {
159
+ return isPrivateTopic
160
+ ? exports.WS_KEY_MAP.usdcPerpPrivate
161
+ : exports.WS_KEY_MAP.usdcPerpPublic;
162
+ }
163
+ default: {
164
+ throw neverGuard(market, `getWsKeyForTopic(): Unhandled market`);
165
+ }
166
+ }
167
+ }
168
+ exports.getWsKeyForTopic = getWsKeyForTopic;
169
+ function getUsdcWsKeyForTopic(topic, subGroup) {
170
+ const isPrivateTopic = PRIVATE_TOPICS.includes(topic);
171
+ if (subGroup === 'option') {
172
+ return isPrivateTopic
173
+ ? exports.WS_KEY_MAP.usdcOptionPrivate
174
+ : exports.WS_KEY_MAP.usdcOptionPublic;
175
+ }
176
+ return isPrivateTopic
177
+ ? exports.WS_KEY_MAP.usdcOptionPrivate
178
+ : exports.WS_KEY_MAP.usdcOptionPublic;
179
+ // return isPrivateTopic
180
+ // ? WS_KEY_MAP.usdcPerpPrivate
181
+ // : WS_KEY_MAP.usdcPerpPublic;
182
+ }
183
+ exports.getUsdcWsKeyForTopic = getUsdcWsKeyForTopic;
184
+ exports.WS_ERROR_ENUM = {
185
+ NOT_AUTHENTICATED_SPOT_V3: '-1004',
186
+ API_ERROR_GENERIC: '10001',
187
+ API_SIGN_AUTH_FAILED: '10003',
188
+ USDC_OPTION_AUTH_FAILED: '3303006',
189
+ };
190
+ function neverGuard(x, msg) {
191
+ return new Error(`Unhandled value exception "x", ${msg}`);
192
+ }
193
+ exports.neverGuard = neverGuard;
194
+ //# sourceMappingURL=websocket-util.js.map
@@ -0,0 +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;YAC7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;YACP,MAAM,UAAU,CAAC,MAAM,EAAE,sCAAsC,CAAC,CAAC;SAClE;KACF;AACH,CAAC;AArCD,4CAqCC;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,103 +1,63 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  import WebSocket from 'isomorphic-ws';
4
- import { DefaultLogger } from './logger';
5
- import { KlineInterval } from './types/shared';
6
- import { RestClientOptions } from './util/requestUtils';
7
- export declare enum WsConnectionState {
8
- READY_STATE_INITIAL = 0,
9
- READY_STATE_CONNECTING = 1,
10
- READY_STATE_CONNECTED = 2,
11
- READY_STATE_CLOSING = 3,
12
- READY_STATE_RECONNECTING = 4
13
- }
14
- export declare type APIMarket = 'inverse' | 'linear' | 'spot';
15
- export declare type WsPublicInverseTopic = 'orderBookL2_25' | 'orderBookL2_200' | 'trade' | 'insurance' | 'instrument_info' | 'klineV2';
16
- export declare type WsPublicUSDTPerpTopic = 'orderBookL2_25' | 'orderBookL2_200' | 'trade' | 'insurance' | 'instrument_info' | 'kline';
17
- export declare type WsPublicSpotV1Topic = 'trade' | 'realtimes' | 'kline' | 'depth' | 'mergedDepth' | 'diffDepth';
18
- export declare type WsPublicSpotV2Topic = 'depth' | 'kline' | 'trade' | 'bookTicker' | 'realtimes';
19
- export declare type WsPublicTopics = WsPublicInverseTopic | WsPublicUSDTPerpTopic | WsPublicSpotV1Topic | WsPublicSpotV2Topic | string;
20
- export declare type WsPrivateInverseTopic = 'position' | 'execution' | 'order' | 'stop_order';
21
- export declare type WsPrivateUSDTPerpTopic = 'position' | 'execution' | 'order' | 'stop_order' | 'wallet';
22
- export declare type WsPrivateSpotTopic = 'outboundAccountInfo' | 'executionReport' | 'ticketInfo';
23
- export declare type WsPrivateTopic = WsPrivateInverseTopic | WsPrivateUSDTPerpTopic | WsPrivateSpotTopic | string;
24
- export declare type WsTopic = WsPublicTopics | WsPrivateTopic;
25
- export interface WSClientConfigurableOptions {
26
- key?: string;
27
- secret?: string;
28
- livenet?: boolean;
29
- /**
30
- * @deprecated Use the property { market: 'linear' } instead
31
- */
32
- linear?: boolean;
33
- market?: APIMarket;
34
- pongTimeout?: number;
35
- pingInterval?: number;
36
- reconnectTimeout?: number;
37
- restOptions?: RestClientOptions;
38
- requestOptions?: any;
39
- wsUrl?: string;
40
- /** If true, fetch server time before trying to authenticate (disabled by default) */
41
- fetchTimeOffsetBeforeAuth?: boolean;
42
- }
43
- export interface WebsocketClientOptions extends WSClientConfigurableOptions {
44
- livenet: boolean;
45
- /**
46
- * @deprecated Use the property { market: 'linear' } instead
47
- */
48
- linear?: boolean;
49
- market?: APIMarket;
50
- pongTimeout: number;
51
- pingInterval: number;
52
- reconnectTimeout: number;
4
+ import { KlineInterval, WSClientConfigurableOptions, WsKey, WsTopic } from './types';
5
+ import { DefaultLogger } from './util';
6
+ export declare type WsClientEvent = 'open' | 'update' | 'close' | 'errorEvent' | 'reconnect' | 'reconnected' | 'response';
7
+ interface WebsocketClientEvents {
8
+ open: (evt: {
9
+ wsKey: WsKey;
10
+ event: any;
11
+ }) => void;
12
+ reconnect: (evt: {
13
+ wsKey: WsKey;
14
+ event: any;
15
+ }) => void;
16
+ reconnected: (evt: {
17
+ wsKey: WsKey;
18
+ event: any;
19
+ }) => void;
20
+ close: (evt: {
21
+ wsKey: WsKey;
22
+ event: any;
23
+ }) => void;
24
+ response: (response: any) => void;
25
+ update: (response: any) => void;
26
+ errorEvent: (response: any) => void;
53
27
  }
54
- export declare const wsKeyInverse = "inverse";
55
- export declare const wsKeyLinearPrivate = "linearPrivate";
56
- export declare const wsKeyLinearPublic = "linearPublic";
57
- export declare const wsKeySpotPrivate = "spotPrivate";
58
- export declare const wsKeySpotPublic = "spotPublic";
59
- export declare type WsKey = 'inverse' | 'linearPrivate' | 'linearPublic' | 'spotPrivate' | 'spotPublic';
60
28
  export declare interface WebsocketClient {
61
- on(event: 'open' | 'reconnected', listener: ({ wsKey: WsKey, event: any }: {
62
- wsKey: any;
63
- event: any;
64
- }) => void): this;
65
- on(event: 'response' | 'update' | 'error', listener: (response: any) => void): this;
66
- on(event: 'reconnect' | 'close', listener: ({ wsKey: WsKey }: {
67
- wsKey: any;
68
- }) => void): this;
29
+ on<U extends keyof WebsocketClientEvents>(event: U, listener: WebsocketClientEvents[U]): this;
30
+ emit<U extends keyof WebsocketClientEvents>(event: U, ...args: Parameters<WebsocketClientEvents[U]>): boolean;
69
31
  }
70
32
  export declare class WebsocketClient extends EventEmitter {
71
33
  private logger;
72
- private restClient;
34
+ private restClient?;
73
35
  private options;
74
36
  private wsStore;
75
37
  constructor(options: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
76
- isLivenet(): boolean;
77
- isLinear(): boolean;
78
- isSpot(): boolean;
79
- isInverse(): boolean;
80
38
  /**
81
- * Add topic/topics to WS subscription list
39
+ * Only used if we fetch exchange time before attempting auth.
40
+ * Disabled by default.
41
+ * I've removed this for ftx and it's working great, tempted to remove this here
82
42
  */
83
- subscribe(wsTopics: WsTopic[] | WsTopic): void;
84
- /**
85
- * Remove topic/topics from WS subscription list
86
- */
87
- unsubscribe(wsTopics: WsTopic[] | WsTopic): void;
43
+ prepareRESTClient(): void;
44
+ isTestnet(): boolean;
88
45
  close(wsKey: WsKey): void;
46
+ closeAll(): void;
89
47
  /**
90
- * Request connection of all dependent websockets, instead of waiting for automatic connection by library
48
+ * Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
91
49
  */
92
- connectAll(): Promise<WebSocket | undefined>[] | undefined;
93
- connectPublic(): Promise<WebSocket | undefined> | undefined;
94
- connectPrivate(): Promise<WebSocket | undefined> | undefined;
50
+ connectAll(): Promise<WebSocket | undefined>[];
51
+ connectPublic(): Promise<WebSocket | undefined>;
52
+ connectPrivate(): Promise<WebSocket | undefined>;
95
53
  private connect;
96
54
  private parseWsError;
97
55
  /**
98
56
  * Return params required to make authorized request
99
57
  */
100
58
  private getAuthParams;
59
+ private sendAuthRequest;
60
+ private getWsAuthSignature;
101
61
  private reconnectWithDelay;
102
62
  private ping;
103
63
  private clearTimers;
@@ -111,21 +71,35 @@ export declare class WebsocketClient extends EventEmitter {
111
71
  * Send WS message to unsubscribe from topics.
112
72
  */
113
73
  private requestUnsubscribeTopics;
114
- private tryWsSend;
74
+ tryWsSend(wsKey: WsKey, wsMessage: string): void;
115
75
  private connectToWsUrl;
116
76
  private onWsOpen;
117
77
  private onWsMessage;
118
78
  private onWsError;
119
79
  private onWsClose;
120
- private onWsMessageResponse;
121
- private onWsMessageUpdate;
122
80
  private getWs;
123
81
  private setWsState;
124
82
  private getWsUrl;
125
- private getWsKeyForTopic;
126
83
  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
+ /** @deprecated use "market: 'spotv3" client */
127
97
  subscribePublicSpotTrades(symbol: string, binary?: boolean): void;
98
+ /** @deprecated use "market: 'spotv3" client */
128
99
  subscribePublicSpotTradingPair(symbol: string, binary?: boolean): void;
100
+ /** @deprecated use "market: 'spotv3" client */
129
101
  subscribePublicSpotV1Kline(symbol: string, candleSize: KlineInterval, binary?: boolean): void;
102
+ /** @deprecated use "market: 'spotv3" client */
130
103
  subscribePublicSpotOrderbook(symbol: string, depth: 'full' | 'merge' | 'delta', dumpScale?: number, binary?: boolean): void;
131
104
  }
105
+ export {};