binance 2.15.14 → 3.0.0-beta.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 (100) hide show
  1. package/README.md +5 -2
  2. package/lib/coinm-client.js.map +1 -1
  3. package/lib/index.d.ts +10 -4
  4. package/lib/index.js +10 -4
  5. package/lib/index.js.map +1 -1
  6. package/lib/main-client.d.ts +13 -2
  7. package/lib/main-client.js +15 -1
  8. package/lib/main-client.js.map +1 -1
  9. package/lib/portfolio-client.js.map +1 -1
  10. package/lib/types/futures.d.ts +1 -0
  11. package/lib/types/futures.js +3 -3
  12. package/lib/types/futures.js.map +1 -1
  13. package/lib/types/spot.js +4 -4
  14. package/lib/types/spot.js.map +1 -1
  15. package/lib/types/websockets/ws-api-requests.d.ts +7 -0
  16. package/lib/types/websockets/ws-api-requests.js +3 -0
  17. package/lib/types/websockets/ws-api-requests.js.map +1 -0
  18. package/lib/types/websockets/ws-api-responses.d.ts +8 -0
  19. package/lib/types/websockets/ws-api-responses.js +3 -0
  20. package/lib/types/websockets/ws-api-responses.js.map +1 -0
  21. package/lib/types/websockets/ws-api.d.ts +201 -0
  22. package/lib/types/websockets/ws-api.js +29 -0
  23. package/lib/types/websockets/ws-api.js.map +1 -0
  24. package/lib/types/{websockets.d.ts → websockets/ws-events-formatted.d.ts} +4 -410
  25. package/lib/types/websockets/ws-events-formatted.js +3 -0
  26. package/lib/types/websockets/ws-events-formatted.js.map +1 -0
  27. package/lib/types/websockets/ws-events-raw.d.ts +401 -0
  28. package/lib/types/{websockets.js → websockets/ws-events-raw.js} +1 -1
  29. package/lib/types/websockets/ws-events-raw.js.map +1 -0
  30. package/lib/types/websockets/ws-general.d.ts +98 -0
  31. package/lib/types/websockets/ws-general.js +11 -0
  32. package/lib/types/websockets/ws-general.js.map +1 -0
  33. package/lib/usdm-client.js.map +1 -1
  34. package/lib/util/BaseRestClient.d.ts +1 -1
  35. package/lib/util/BaseRestClient.js +1 -1
  36. package/lib/util/BaseRestClient.js.map +1 -1
  37. package/lib/util/BaseWSClient.d.ts +225 -0
  38. package/lib/util/BaseWSClient.js +729 -0
  39. package/lib/util/BaseWSClient.js.map +1 -0
  40. package/lib/util/beautifier-maps.d.ts +151 -0
  41. package/lib/util/beautifier-maps.js +198 -37
  42. package/lib/util/beautifier-maps.js.map +1 -1
  43. package/lib/util/beautifier.d.ts +7 -3
  44. package/lib/util/beautifier.js +40 -11
  45. package/lib/util/beautifier.js.map +1 -1
  46. package/lib/util/browser-support.d.ts +2 -1
  47. package/lib/util/browser-support.js +46 -28
  48. package/lib/util/browser-support.js.map +1 -1
  49. package/lib/util/logger.d.ts +8 -0
  50. package/lib/util/logger.js +17 -0
  51. package/lib/util/logger.js.map +1 -0
  52. package/lib/util/node-support.d.ts +2 -1
  53. package/lib/util/node-support.js +35 -15
  54. package/lib/util/node-support.js.map +1 -1
  55. package/lib/util/requestUtils.d.ts +19 -19
  56. package/lib/util/requestUtils.js +119 -38
  57. package/lib/util/requestUtils.js.map +1 -1
  58. package/lib/util/typeGuards.d.ts +9 -1
  59. package/lib/util/typeGuards.js +59 -34
  60. package/lib/util/typeGuards.js.map +1 -1
  61. package/lib/util/usdm/exchangeInfo.js +2 -3
  62. package/lib/util/usdm/exchangeInfo.js.map +1 -1
  63. package/lib/util/webCryptoAPI.d.ts +14 -0
  64. package/lib/util/webCryptoAPI.js +120 -0
  65. package/lib/util/webCryptoAPI.js.map +1 -0
  66. package/lib/util/websockets/WsStore.d.ts +74 -0
  67. package/lib/util/websockets/WsStore.js +279 -0
  68. package/lib/util/websockets/WsStore.js.map +1 -0
  69. package/lib/util/websockets/WsStore.types.d.ts +53 -0
  70. package/lib/util/websockets/WsStore.types.js +14 -0
  71. package/lib/util/websockets/WsStore.types.js.map +1 -0
  72. package/lib/util/websockets/listen-key-state-cache.d.ts +21 -0
  73. package/lib/util/websockets/listen-key-state-cache.js +80 -0
  74. package/lib/util/websockets/listen-key-state-cache.js.map +1 -0
  75. package/lib/util/websockets/rest-client-cache.d.ts +13 -0
  76. package/lib/util/websockets/rest-client-cache.js +56 -0
  77. package/lib/util/websockets/rest-client-cache.js.map +1 -0
  78. package/lib/util/websockets/user-data-stream-manager.d.ts +54 -0
  79. package/lib/util/websockets/user-data-stream-manager.js +256 -0
  80. package/lib/util/websockets/user-data-stream-manager.js.map +1 -0
  81. package/lib/util/websockets/websocket-util.d.ts +124 -0
  82. package/lib/util/websockets/websocket-util.js +481 -0
  83. package/lib/util/websockets/websocket-util.js.map +1 -0
  84. package/lib/websocket-client-legacy.d.ts +288 -0
  85. package/lib/websocket-client-legacy.js +1113 -0
  86. package/lib/websocket-client-legacy.js.map +1 -0
  87. package/lib/websocket-client.d.ts +228 -168
  88. package/lib/websocket-client.js +927 -834
  89. package/lib/websocket-client.js.map +1 -1
  90. package/package.json +5 -5
  91. package/lib/logger.d.ts +0 -9
  92. package/lib/logger.js +0 -23
  93. package/lib/logger.js.map +0 -1
  94. package/lib/types/websockets.js.map +0 -1
  95. package/lib/util/WsStore.d.ts +0 -57
  96. package/lib/util/WsStore.js +0 -101
  97. package/lib/util/WsStore.js.map +0 -1
  98. package/lib/util/ws-utils.d.ts +0 -7
  99. package/lib/util/ws-utils.js +0 -16
  100. package/lib/util/ws-utils.js.map +0 -1
@@ -0,0 +1,201 @@
1
+ import { WS_KEY_MAP, WsKey } from '../../util/websockets/websocket-util';
2
+ import { FuturesAccountBalance, FuturesAccountInformation, FuturesExchangeInfo, NewFuturesOrderParams } from '../futures';
3
+ import { numberInString } from '../shared';
4
+ import { ExchangeInfo, NewSpotOrderParams, OrderResponse } from '../spot';
5
+ import { WSAPIRecvWindowTimestamp } from './ws-api-requests';
6
+ import { WsAPISessionStatus } from './ws-api-responses';
7
+ /**
8
+ * Standard WS commands (for consumers)
9
+ */
10
+ export type WsOperation = 'SUBSCRIBE' | 'UNSUBSCRIBE' | 'LIST_SUBSCRIPTIONS' | 'SET_PROPERTY' | 'GET_PROPERTY';
11
+ /**
12
+ * WS API commands (for sending requests via WS)
13
+ */
14
+ export declare const WS_API_Operations: readonly ["session.logon", "session.status", "session.logout", "ping", "time", "exchangeInfo", "depth", "v2/account.balance", "account.balance", "v2/account.status", "account.status", "order.place", "orderList.place", "sor.order.place"];
15
+ export type WsAPIOperation = (typeof WS_API_Operations)[number];
16
+ export interface WsRequestOperationBinance<TWSTopic extends string, TWSParams extends object = any> {
17
+ method: WsOperation | WsAPIOperation;
18
+ params?: (TWSTopic | string | number)[] | TWSParams;
19
+ id: number;
20
+ }
21
+ export interface WSAPIResponse<TResponseData extends object = object, TOperation extends WsAPIOperation = WsAPIOperation> {
22
+ /** Auto-generated */
23
+ id: string;
24
+ status: number;
25
+ result: TResponseData;
26
+ rateLimits: {
27
+ rateLimitType: 'REQUEST_WEIGHT';
28
+ interval: 'MINUTE';
29
+ intervalNum: number;
30
+ limit: number;
31
+ count: number;
32
+ }[];
33
+ wsKey: WsKey;
34
+ isWSAPIResponse: boolean;
35
+ }
36
+ export type Exact<T> = {} & {
37
+ [K in keyof T]: T[K];
38
+ };
39
+ /**
40
+ * List of operations supported for this WsKey (connection)
41
+ */
42
+ export interface WsAPIWsKeyTopicMap {
43
+ [WS_KEY_MAP.main]: WsOperation;
44
+ [WS_KEY_MAP.main2]: WsOperation;
45
+ [WS_KEY_MAP.main3]: WsOperation;
46
+ [WS_KEY_MAP.mainTestnetPublic]: WsOperation;
47
+ [WS_KEY_MAP.mainTestnetUserData]: WsOperation;
48
+ [WS_KEY_MAP.marginRiskUserData]: WsOperation;
49
+ [WS_KEY_MAP.usdm]: WsOperation;
50
+ [WS_KEY_MAP.usdmTestnet]: WsOperation;
51
+ [WS_KEY_MAP.coinm]: WsOperation;
52
+ [WS_KEY_MAP.coinm2]: WsOperation;
53
+ [WS_KEY_MAP.coinmTestnet]: WsOperation;
54
+ [WS_KEY_MAP.eoptions]: WsOperation;
55
+ [WS_KEY_MAP.portfolioMarginUserData]: WsOperation;
56
+ [WS_KEY_MAP.portfolioMarginProUserData]: WsOperation;
57
+ [WS_KEY_MAP.mainWSAPI]: WsAPIOperation;
58
+ [WS_KEY_MAP.mainWSAPI2]: WsAPIOperation;
59
+ [WS_KEY_MAP.mainWSAPITestnet]: WsAPIOperation;
60
+ [WS_KEY_MAP.usdmWSAPI]: WsAPIOperation;
61
+ [WS_KEY_MAP.usdmWSAPITestnet]: WsAPIOperation;
62
+ }
63
+ /**
64
+ * Request parameters expected per operation.
65
+ *
66
+ * - Each "key" here is the name of the command/operation.
67
+ * - Each "value" here has the parameters required for the command.
68
+ *
69
+ * Make sure to add new topics to WS_API_Operations and the response param map too.
70
+ */
71
+ export interface WsAPITopicRequestParamMap {
72
+ SUBSCRIBE: never;
73
+ UNSUBSCRIBE: never;
74
+ LIST_SUBSCRIPTIONS: never;
75
+ SET_PROPERTY: never;
76
+ GET_PROPERTY: never;
77
+ /**
78
+ * Authentication commands & parameters:
79
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/authentication-requests
80
+ */
81
+ 'session.logon': {
82
+ apiKey: string;
83
+ signature: string;
84
+ timestamp: number;
85
+ };
86
+ 'session.status': void;
87
+ 'session.logout': void;
88
+ /**
89
+ * General requests & parameters:
90
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/general-requests
91
+ */
92
+ ping: void;
93
+ time: void;
94
+ exchangeInfo: void | {
95
+ symbol?: string;
96
+ symbols?: string[];
97
+ permissions?: string[];
98
+ showPermissionSets?: boolean;
99
+ symbolStatus?: string;
100
+ };
101
+ /**
102
+ * Market data requests & parameters:
103
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/market-data-requests
104
+ */
105
+ depth: {
106
+ symbol: string;
107
+ limit: number;
108
+ };
109
+ /**
110
+ * Account requests & parameters:
111
+ * - Spot:
112
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/account-requests
113
+ *
114
+ * - Futures:
115
+ * https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api
116
+ */
117
+ /**
118
+ * Spot:
119
+ */
120
+ /**
121
+ * Futures:
122
+ */
123
+ 'v2/account.balance': WSAPIRecvWindowTimestamp;
124
+ 'account.balance': WSAPIRecvWindowTimestamp;
125
+ 'v2/account.status': WSAPIRecvWindowTimestamp;
126
+ 'account.status': WSAPIRecvWindowTimestamp;
127
+ /**
128
+ * Trading requests & parameters:
129
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/trading-requests
130
+ */
131
+ 'order.place': (NewSpotOrderParams | NewFuturesOrderParams) & {
132
+ timestamp?: number;
133
+ };
134
+ 'orderList.place': any;
135
+ 'sor.order.place': any;
136
+ }
137
+ /**
138
+ * Response structure expected for each operation
139
+ *
140
+ * - Each "key" here is a command/request supported by the WS API
141
+ * - Each "value" here is the response schema for that command.
142
+ */
143
+ export interface WsAPIOperationResponseMap {
144
+ [key: string]: unknown;
145
+ SUBSCRIBE: never;
146
+ UNSUBSCRIBE: never;
147
+ LIST_SUBSCRIPTIONS: never;
148
+ SET_PROPERTY: never;
149
+ GET_PROPERTY: never;
150
+ /**
151
+ * Session authentication responses:
152
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/session-authentication
153
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/authentication-requests
154
+ */
155
+ 'session.login': WSAPIResponse<WsAPISessionStatus>;
156
+ 'session.status': WSAPIResponse<WsAPISessionStatus>;
157
+ 'session.logout': WSAPIResponse<WsAPISessionStatus>;
158
+ /**
159
+ * General responses:
160
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/general-requests
161
+ */
162
+ ping: {};
163
+ time: WSAPIResponse<{
164
+ serverTime: number;
165
+ }>;
166
+ exchangeInfo: WSAPIResponse<FuturesExchangeInfo | ExchangeInfo>;
167
+ /**
168
+ * Market data responses
169
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/market-data-requests
170
+ */
171
+ depth: WSAPIResponse<{
172
+ lastUpdateId: number;
173
+ bids: [numberInString, numberInString][];
174
+ asks: [numberInString, numberInString][];
175
+ }>;
176
+ /**
177
+ * Account requests & parameters:
178
+ * - Spot:
179
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/account-requests
180
+ *
181
+ * - Futures:
182
+ * https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api
183
+ */
184
+ /**
185
+ * Spot:
186
+ */
187
+ /**
188
+ * Futures:
189
+ */
190
+ 'v2/account.balance': WSAPIResponse<FuturesAccountBalance>;
191
+ 'account.balance': WSAPIResponse<FuturesAccountBalance>;
192
+ 'v2/account.status': WSAPIResponse<FuturesAccountInformation>;
193
+ 'account.status': WSAPIResponse<FuturesAccountInformation>;
194
+ /**
195
+ * Trading responses
196
+ * https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/trading-requests
197
+ */
198
+ 'order.place': WSAPIResponse<OrderResponse>;
199
+ 'orderList.place': WSAPIResponse<any>;
200
+ 'sor.order.place': WSAPIResponse<any>;
201
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WS_API_Operations = void 0;
4
+ const websocket_util_1 = require("../../util/websockets/websocket-util");
5
+ /**
6
+ * WS API commands (for sending requests via WS)
7
+ */
8
+ exports.WS_API_Operations = [
9
+ 'session.logon',
10
+ 'session.status',
11
+ 'session.logout',
12
+ //// General commands
13
+ 'ping',
14
+ 'time',
15
+ 'exchangeInfo',
16
+ //// Market data commands //TODO:
17
+ 'depth',
18
+ //// Account commands
19
+ // Futures
20
+ 'v2/account.balance',
21
+ 'account.balance',
22
+ 'v2/account.status',
23
+ 'account.status',
24
+ //// Trading commands // TODO:
25
+ 'order.place',
26
+ 'orderList.place',
27
+ 'sor.order.place',
28
+ ];
29
+ //# sourceMappingURL=ws-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-api.js","sourceRoot":"","sources":["../../../src/types/websockets/ws-api.ts"],"names":[],"mappings":";;;AAAA,yEAAyE;AA2BzE;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,qBAAqB;IACrB,MAAM;IACN,MAAM;IACN,cAAc;IACd,iCAAiC;IACjC,OAAO;IACP,qBAAqB;IACrB,UAAU;IACV,oBAAoB;IACpB,iBAAiB;IACjB,mBAAmB;IACnB,gBAAgB;IAChB,8BAA8B;IAC9B,aAAa;IACb,iBAAiB;IACjB,iBAAiB;CACT,CAAC"}