bybit-api 2.4.0-beta.1 → 3.0.1

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 (45) hide show
  1. package/README.md +73 -41
  2. package/lib/index.d.ts +1 -1
  3. package/lib/index.js +1 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/inverse-client.d.ts +18 -126
  6. package/lib/inverse-client.js.map +1 -1
  7. package/lib/linear-client.d.ts +20 -142
  8. package/lib/linear-client.js.map +1 -1
  9. package/lib/spot-client-v3.d.ts +2 -6
  10. package/lib/spot-client-v3.js.map +1 -1
  11. package/lib/spot-client.js +1 -1
  12. package/lib/spot-client.js.map +1 -1
  13. package/lib/types/request/index.d.ts +2 -1
  14. package/lib/types/request/index.js +2 -1
  15. package/lib/types/request/index.js.map +1 -1
  16. package/lib/types/request/inverse.d.ts +120 -0
  17. package/lib/types/request/{usdt-perp.js → inverse.js} +1 -1
  18. package/lib/types/request/inverse.js.map +1 -0
  19. package/lib/types/request/linear.d.ts +160 -0
  20. package/lib/types/request/linear.js +3 -0
  21. package/lib/types/request/linear.js.map +1 -0
  22. package/lib/types/request/spot.d.ts +5 -0
  23. package/lib/types/shared.d.ts +4 -1
  24. package/lib/types/websockets.d.ts +6 -5
  25. package/lib/util/BaseRestClient.d.ts +4 -8
  26. package/lib/util/BaseRestClient.js +16 -23
  27. package/lib/util/BaseRestClient.js.map +1 -1
  28. package/lib/util/WsStore.d.ts +19 -16
  29. package/lib/util/WsStore.js +1 -0
  30. package/lib/util/WsStore.js.map +1 -1
  31. package/lib/util/node-support.d.ts +1 -0
  32. package/lib/util/node-support.js +1 -0
  33. package/lib/util/node-support.js.map +1 -1
  34. package/lib/util/requestUtils.d.ts +9 -5
  35. package/lib/util/requestUtils.js +21 -12
  36. package/lib/util/requestUtils.js.map +1 -1
  37. package/lib/util/websocket-util.d.ts +38 -8
  38. package/lib/util/websocket-util.js +252 -32
  39. package/lib/util/websocket-util.js.map +1 -1
  40. package/lib/websocket-client.d.ts +63 -30
  41. package/lib/websocket-client.js +343 -206
  42. package/lib/websocket-client.js.map +1 -1
  43. package/package.json +2 -2
  44. package/lib/types/request/usdt-perp.d.ts +0 -20
  45. package/lib/types/request/usdt-perp.js.map +0 -1
@@ -1,52 +1,70 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  import WebSocket from 'isomorphic-ws';
4
- import { DefaultLogger } from './util/logger';
5
4
  import { KlineInterval, WSClientConfigurableOptions, WsKey, WsTopic } from './types';
6
- export declare interface WebsocketClient {
7
- on(event: 'open' | 'reconnected', listener: ({ wsKey: WsKey, event: any }: {
8
- wsKey: any;
5
+ import { DefaultLogger } from './util';
6
+ export declare type WsClientEvent = 'open' | 'update' | 'close' | 'error' | 'reconnect' | 'reconnected' | 'response';
7
+ interface WebsocketClientEvents {
8
+ /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
9
+ open: (evt: {
10
+ wsKey: WsKey;
11
+ event: any;
12
+ }) => void;
13
+ /** Reconnecting a dropped connection */
14
+ reconnect: (evt: {
15
+ wsKey: WsKey;
16
+ event: any;
17
+ }) => void;
18
+ /** Successfully reconnected a connection that dropped */
19
+ reconnected: (evt: {
20
+ wsKey: WsKey;
21
+ event: any;
22
+ }) => void;
23
+ /** Connection closed */
24
+ close: (evt: {
25
+ wsKey: WsKey;
9
26
  event: any;
10
- }) => void): this;
11
- on(event: 'response' | 'update' | 'error', listener: (response: any) => void): this;
12
- on(event: 'reconnect' | 'close', listener: ({ wsKey: WsKey }: {
13
- wsKey: any;
14
- }) => void): this;
27
+ }) => void;
28
+ /** Received reply to websocket command (e.g. after subscribing to topics) */
29
+ response: (response: any) => void;
30
+ /** Received data for topic */
31
+ update: (response: any) => void;
32
+ /** Exception from ws client OR custom listeners */
33
+ error: (response: any) => void;
34
+ }
35
+ export declare interface WebsocketClient {
36
+ on<U extends keyof WebsocketClientEvents>(event: U, listener: WebsocketClientEvents[U]): this;
37
+ emit<U extends keyof WebsocketClientEvents>(event: U, ...args: Parameters<WebsocketClientEvents[U]>): boolean;
15
38
  }
16
39
  export declare class WebsocketClient extends EventEmitter {
17
40
  private logger;
18
- /** Purely used */
19
- private restClient;
41
+ private restClient?;
20
42
  private options;
21
43
  private wsStore;
22
44
  constructor(options: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
23
- isLivenet(): boolean;
24
- isLinear(): boolean;
25
- isSpot(): boolean;
26
- isInverse(): boolean;
27
- /** USDC, spot v3, unified margin, account asset */
28
- isV3(): boolean;
29
- /**
30
- * Add topic/topics to WS subscription list
31
- */
32
- subscribe(wsTopics: WsTopic[] | WsTopic): void;
33
45
  /**
34
- * Remove topic/topics from WS subscription list
46
+ * Only used if we fetch exchange time before attempting auth.
47
+ * Disabled by default.
48
+ * I've removed this for ftx and it's working great, tempted to remove this here
35
49
  */
36
- unsubscribe(wsTopics: WsTopic[] | WsTopic): void;
37
- close(wsKey: WsKey): void;
50
+ prepareRESTClient(): void;
51
+ isTestnet(): boolean;
52
+ close(wsKey: WsKey, force?: boolean): void;
53
+ closeAll(force?: boolean): void;
38
54
  /**
39
55
  * Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library
40
56
  */
41
- connectAll(): Promise<WebSocket | undefined>[] | undefined;
42
- connectPublic(): Promise<WebSocket | undefined> | undefined;
43
- connectPrivate(): Promise<WebSocket | undefined> | undefined;
57
+ connectAll(): Promise<WebSocket | undefined>[];
58
+ connectPublic(): Promise<WebSocket | undefined>[];
59
+ connectPrivate(): Promise<WebSocket | undefined>;
44
60
  private connect;
45
61
  private parseWsError;
46
62
  /**
47
63
  * Return params required to make authorized request
48
64
  */
49
65
  private getAuthParams;
66
+ private sendAuthRequest;
67
+ private getWsAuthSignature;
50
68
  private reconnectWithDelay;
51
69
  private ping;
52
70
  private clearTimers;
@@ -60,20 +78,35 @@ export declare class WebsocketClient extends EventEmitter {
60
78
  * Send WS message to unsubscribe from topics.
61
79
  */
62
80
  private requestUnsubscribeTopics;
63
- private tryWsSend;
81
+ tryWsSend(wsKey: WsKey, wsMessage: string): void;
64
82
  private connectToWsUrl;
65
83
  private onWsOpen;
66
84
  private onWsMessage;
67
85
  private onWsError;
68
86
  private onWsClose;
69
- private onWsMessageResponse;
70
87
  private getWs;
71
88
  private setWsState;
72
89
  private getWsUrl;
73
- private getWsKeyForTopic;
74
90
  private wrongMarketError;
91
+ /**
92
+ * Add topic/topics to WS subscription list
93
+ * @param wsTopics topic or list of topics
94
+ * @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)
95
+ */
96
+ subscribe(wsTopics: WsTopic[] | WsTopic, isPrivateTopic?: boolean): void;
97
+ /**
98
+ * Remove topic/topics from WS subscription list
99
+ * @param wsTopics topic or list of topics
100
+ * @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)
101
+ */
102
+ unsubscribe(wsTopics: WsTopic[] | WsTopic, isPrivateTopic?: boolean): void;
103
+ /** @deprecated use "market: 'spotv3" client */
75
104
  subscribePublicSpotTrades(symbol: string, binary?: boolean): void;
105
+ /** @deprecated use "market: 'spotv3" client */
76
106
  subscribePublicSpotTradingPair(symbol: string, binary?: boolean): void;
107
+ /** @deprecated use "market: 'spotv3" client */
77
108
  subscribePublicSpotV1Kline(symbol: string, candleSize: KlineInterval, binary?: boolean): void;
109
+ /** @deprecated use "market: 'spotv3" client */
78
110
  subscribePublicSpotOrderbook(symbol: string, depth: 'full' | 'merge' | 'delta', dumpScale?: number, binary?: boolean): void;
79
111
  }
112
+ export {};