coinbase-api 0.3.2 → 0.5.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.
Files changed (218) hide show
  1. package/README.md +438 -14
  2. package/dist/cjs/CBAdvancedTradeClient.d.ts +559 -0
  3. package/dist/cjs/CBAdvancedTradeClient.js +574 -0
  4. package/dist/cjs/CBAdvancedTradeClient.js.map +1 -0
  5. package/dist/cjs/CBAppClient.d.ts +359 -0
  6. package/dist/cjs/CBAppClient.js +336 -0
  7. package/dist/cjs/CBAppClient.js.map +1 -0
  8. package/dist/cjs/CBCommerceClient.d.ts +110 -0
  9. package/dist/cjs/CBCommerceClient.js +105 -0
  10. package/dist/cjs/CBCommerceClient.js.map +1 -0
  11. package/dist/cjs/CBExchangeClient.d.ts +640 -0
  12. package/dist/cjs/CBExchangeClient.js +751 -0
  13. package/dist/cjs/CBExchangeClient.js.map +1 -0
  14. package/dist/cjs/CBInternationalClient.d.ts +381 -0
  15. package/dist/cjs/CBInternationalClient.js +437 -0
  16. package/dist/cjs/CBInternationalClient.js.map +1 -0
  17. package/dist/cjs/CBPrimeClient.d.ts +363 -0
  18. package/dist/cjs/CBPrimeClient.js +451 -0
  19. package/dist/cjs/CBPrimeClient.js.map +1 -0
  20. package/dist/cjs/WebsocketClient.d.ts +78 -0
  21. package/dist/cjs/WebsocketClient.js +534 -0
  22. package/dist/cjs/WebsocketClient.js.map +1 -0
  23. package/dist/cjs/index.d.ts +13 -0
  24. package/dist/cjs/index.js +30 -0
  25. package/dist/cjs/index.js.map +1 -0
  26. package/dist/cjs/lib/BaseRestClient.d.ts +66 -0
  27. package/dist/cjs/lib/BaseRestClient.js +436 -0
  28. package/dist/cjs/lib/BaseRestClient.js.map +1 -0
  29. package/dist/cjs/lib/BaseWSClient.d.ts +169 -0
  30. package/dist/cjs/lib/BaseWSClient.js +638 -0
  31. package/dist/cjs/lib/BaseWSClient.js.map +1 -0
  32. package/dist/cjs/lib/jwtNode.d.ts +13 -0
  33. package/dist/cjs/lib/jwtNode.js +52 -0
  34. package/dist/cjs/lib/jwtNode.js.map +1 -0
  35. package/dist/cjs/lib/misc-util.d.ts +1 -0
  36. package/dist/cjs/lib/misc-util.js +7 -0
  37. package/dist/cjs/lib/misc-util.js.map +1 -0
  38. package/dist/cjs/lib/requestUtils.d.ts +98 -0
  39. package/dist/cjs/lib/requestUtils.js +75 -0
  40. package/dist/cjs/lib/requestUtils.js.map +1 -0
  41. package/dist/cjs/lib/webCryptoAPI.d.ts +10 -0
  42. package/dist/cjs/lib/webCryptoAPI.js +83 -0
  43. package/dist/cjs/lib/webCryptoAPI.js.map +1 -0
  44. package/dist/cjs/lib/websocket/WsStore.d.ts +63 -0
  45. package/dist/cjs/lib/websocket/WsStore.js +254 -0
  46. package/dist/cjs/lib/websocket/WsStore.js.map +1 -0
  47. package/dist/cjs/lib/websocket/WsStore.types.d.ts +49 -0
  48. package/dist/cjs/lib/websocket/WsStore.types.js +14 -0
  49. package/dist/cjs/lib/websocket/WsStore.types.js.map +1 -0
  50. package/dist/cjs/lib/websocket/logger.d.ts +6 -0
  51. package/dist/cjs/lib/websocket/logger.js +16 -0
  52. package/dist/cjs/lib/websocket/logger.js.map +1 -0
  53. package/dist/cjs/lib/websocket/typeGuards.d.ts +27 -0
  54. package/dist/cjs/lib/websocket/typeGuards.js +86 -0
  55. package/dist/cjs/lib/websocket/typeGuards.js.map +1 -0
  56. package/dist/cjs/lib/websocket/websocket-util.d.ts +120 -0
  57. package/dist/cjs/lib/websocket/websocket-util.js +173 -0
  58. package/dist/cjs/lib/websocket/websocket-util.js.map +1 -0
  59. package/dist/cjs/package.json +3 -0
  60. package/dist/cjs/types/request/advanced-trade-client.d.ts +194 -0
  61. package/dist/cjs/types/request/advanced-trade-client.js +18 -0
  62. package/dist/cjs/types/request/advanced-trade-client.js.map +1 -0
  63. package/dist/cjs/types/request/coinbase-app-client.d.ts +80 -0
  64. package/dist/cjs/types/request/coinbase-app-client.js +28 -0
  65. package/dist/cjs/types/request/coinbase-app-client.js.map +1 -0
  66. package/dist/cjs/types/request/coinbase-exchange.d.ts +332 -0
  67. package/dist/cjs/types/request/coinbase-exchange.js +3 -0
  68. package/dist/cjs/types/request/coinbase-exchange.js.map +1 -0
  69. package/dist/cjs/types/request/coinbase-international.d.ts +160 -0
  70. package/dist/cjs/types/request/coinbase-international.js +13 -0
  71. package/dist/cjs/types/request/coinbase-international.js.map +1 -0
  72. package/dist/cjs/types/request/coinbase-prime.d.ts +298 -0
  73. package/dist/cjs/types/request/coinbase-prime.js +8 -0
  74. package/dist/cjs/types/request/coinbase-prime.js.map +1 -0
  75. package/dist/cjs/types/response/advanced-trade-client.d.ts +759 -0
  76. package/dist/cjs/types/response/advanced-trade-client.js +8 -0
  77. package/dist/cjs/types/response/advanced-trade-client.js.map +1 -0
  78. package/dist/cjs/types/response/coinbase-app-client.d.ts +168 -0
  79. package/dist/cjs/types/response/coinbase-app-client.js +18 -0
  80. package/dist/cjs/types/response/coinbase-app-client.js.map +1 -0
  81. package/dist/cjs/types/response/coinbase-exchange.d.ts +80 -0
  82. package/dist/cjs/types/response/coinbase-exchange.js +82 -0
  83. package/dist/cjs/types/response/coinbase-exchange.js.map +1 -0
  84. package/dist/cjs/types/response/coinbase-international.d.ts +40 -0
  85. package/dist/cjs/types/response/coinbase-international.js +42 -0
  86. package/dist/cjs/types/response/coinbase-international.js.map +1 -0
  87. package/dist/cjs/types/response/coinbase-prime.d.ts +70 -0
  88. package/dist/cjs/types/response/coinbase-prime.js +72 -0
  89. package/dist/cjs/types/response/coinbase-prime.js.map +1 -0
  90. package/dist/cjs/types/response/ws.d.ts +7 -0
  91. package/dist/cjs/types/response/ws.js +3 -0
  92. package/dist/cjs/types/response/ws.js.map +1 -0
  93. package/dist/cjs/types/shared.types.d.ts +60 -0
  94. package/dist/cjs/types/shared.types.js +3 -0
  95. package/dist/cjs/types/shared.types.js.map +1 -0
  96. package/dist/cjs/types/websockets/client.d.ts +73 -0
  97. package/dist/cjs/types/websockets/client.js +3 -0
  98. package/dist/cjs/types/websockets/client.js.map +1 -0
  99. package/dist/cjs/types/websockets/events.d.ts +40 -0
  100. package/dist/cjs/types/websockets/events.js +3 -0
  101. package/dist/cjs/types/websockets/events.js.map +1 -0
  102. package/dist/cjs/types/websockets/requests.d.ts +76 -0
  103. package/dist/cjs/types/websockets/requests.js +3 -0
  104. package/dist/cjs/types/websockets/requests.js.map +1 -0
  105. package/dist/cjs/types/websockets/wsAPI.d.ts +9 -0
  106. package/dist/cjs/types/websockets/wsAPI.js +3 -0
  107. package/dist/cjs/types/websockets/wsAPI.js.map +1 -0
  108. package/dist/mjs/CBAdvancedTradeClient.d.ts +559 -0
  109. package/dist/mjs/CBAdvancedTradeClient.js +570 -0
  110. package/dist/mjs/CBAdvancedTradeClient.js.map +1 -0
  111. package/dist/mjs/CBAppClient.d.ts +359 -0
  112. package/dist/mjs/CBAppClient.js +332 -0
  113. package/dist/mjs/CBAppClient.js.map +1 -0
  114. package/dist/mjs/CBCommerceClient.d.ts +110 -0
  115. package/dist/mjs/CBCommerceClient.js +101 -0
  116. package/dist/mjs/CBCommerceClient.js.map +1 -0
  117. package/dist/mjs/CBExchangeClient.d.ts +640 -0
  118. package/dist/mjs/CBExchangeClient.js +747 -0
  119. package/dist/mjs/CBExchangeClient.js.map +1 -0
  120. package/dist/mjs/CBInternationalClient.d.ts +381 -0
  121. package/dist/mjs/CBInternationalClient.js +433 -0
  122. package/dist/mjs/CBInternationalClient.js.map +1 -0
  123. package/dist/mjs/CBPrimeClient.d.ts +363 -0
  124. package/dist/mjs/CBPrimeClient.js +447 -0
  125. package/dist/mjs/CBPrimeClient.js.map +1 -0
  126. package/dist/mjs/WebsocketClient.d.ts +78 -0
  127. package/dist/mjs/WebsocketClient.js +530 -0
  128. package/dist/mjs/WebsocketClient.js.map +1 -0
  129. package/dist/mjs/index.d.ts +13 -0
  130. package/dist/mjs/index.js +14 -0
  131. package/dist/mjs/index.js.map +1 -0
  132. package/dist/mjs/lib/BaseRestClient.d.ts +66 -0
  133. package/dist/mjs/lib/BaseRestClient.js +429 -0
  134. package/dist/mjs/lib/BaseRestClient.js.map +1 -0
  135. package/dist/mjs/lib/BaseWSClient.d.ts +169 -0
  136. package/dist/mjs/lib/BaseWSClient.js +631 -0
  137. package/dist/mjs/lib/BaseWSClient.js.map +1 -0
  138. package/dist/mjs/lib/jwtNode.d.ts +13 -0
  139. package/dist/mjs/lib/jwtNode.js +45 -0
  140. package/dist/mjs/lib/jwtNode.js.map +1 -0
  141. package/dist/mjs/lib/misc-util.d.ts +1 -0
  142. package/dist/mjs/lib/misc-util.js +4 -0
  143. package/dist/mjs/lib/misc-util.js.map +1 -0
  144. package/dist/mjs/lib/requestUtils.d.ts +98 -0
  145. package/dist/mjs/lib/requestUtils.js +69 -0
  146. package/dist/mjs/lib/requestUtils.js.map +1 -0
  147. package/dist/mjs/lib/webCryptoAPI.d.ts +10 -0
  148. package/dist/mjs/lib/webCryptoAPI.js +79 -0
  149. package/dist/mjs/lib/webCryptoAPI.js.map +1 -0
  150. package/dist/mjs/lib/websocket/WsStore.d.ts +63 -0
  151. package/dist/mjs/lib/websocket/WsStore.js +249 -0
  152. package/dist/mjs/lib/websocket/WsStore.js.map +1 -0
  153. package/dist/mjs/lib/websocket/WsStore.types.d.ts +49 -0
  154. package/dist/mjs/lib/websocket/WsStore.types.js +11 -0
  155. package/dist/mjs/lib/websocket/WsStore.types.js.map +1 -0
  156. package/dist/mjs/lib/websocket/logger.d.ts +6 -0
  157. package/dist/mjs/lib/websocket/logger.js +13 -0
  158. package/dist/mjs/lib/websocket/logger.js.map +1 -0
  159. package/dist/mjs/lib/websocket/typeGuards.d.ts +27 -0
  160. package/dist/mjs/lib/websocket/typeGuards.js +78 -0
  161. package/dist/mjs/lib/websocket/typeGuards.js.map +1 -0
  162. package/dist/mjs/lib/websocket/websocket-util.d.ts +120 -0
  163. package/dist/mjs/lib/websocket/websocket-util.js +164 -0
  164. package/dist/mjs/lib/websocket/websocket-util.js.map +1 -0
  165. package/dist/mjs/package.json +3 -0
  166. package/dist/mjs/types/request/advanced-trade-client.d.ts +194 -0
  167. package/dist/mjs/types/request/advanced-trade-client.js +17 -0
  168. package/dist/mjs/types/request/advanced-trade-client.js.map +1 -0
  169. package/dist/mjs/types/request/coinbase-app-client.d.ts +80 -0
  170. package/dist/mjs/types/request/coinbase-app-client.js +27 -0
  171. package/dist/mjs/types/request/coinbase-app-client.js.map +1 -0
  172. package/dist/mjs/types/request/coinbase-exchange.d.ts +332 -0
  173. package/dist/mjs/types/request/coinbase-exchange.js +2 -0
  174. package/dist/mjs/types/request/coinbase-exchange.js.map +1 -0
  175. package/dist/mjs/types/request/coinbase-international.d.ts +160 -0
  176. package/dist/mjs/types/request/coinbase-international.js +12 -0
  177. package/dist/mjs/types/request/coinbase-international.js.map +1 -0
  178. package/dist/mjs/types/request/coinbase-prime.d.ts +298 -0
  179. package/dist/mjs/types/request/coinbase-prime.js +7 -0
  180. package/dist/mjs/types/request/coinbase-prime.js.map +1 -0
  181. package/dist/mjs/types/response/advanced-trade-client.d.ts +759 -0
  182. package/dist/mjs/types/response/advanced-trade-client.js +7 -0
  183. package/dist/mjs/types/response/advanced-trade-client.js.map +1 -0
  184. package/dist/mjs/types/response/coinbase-app-client.d.ts +168 -0
  185. package/dist/mjs/types/response/coinbase-app-client.js +17 -0
  186. package/dist/mjs/types/response/coinbase-app-client.js.map +1 -0
  187. package/dist/mjs/types/response/coinbase-exchange.d.ts +80 -0
  188. package/dist/mjs/types/response/coinbase-exchange.js +82 -0
  189. package/dist/mjs/types/response/coinbase-exchange.js.map +1 -0
  190. package/dist/mjs/types/response/coinbase-international.d.ts +40 -0
  191. package/dist/mjs/types/response/coinbase-international.js +42 -0
  192. package/dist/mjs/types/response/coinbase-international.js.map +1 -0
  193. package/dist/mjs/types/response/coinbase-prime.d.ts +70 -0
  194. package/dist/mjs/types/response/coinbase-prime.js +72 -0
  195. package/dist/mjs/types/response/coinbase-prime.js.map +1 -0
  196. package/dist/mjs/types/response/ws.d.ts +7 -0
  197. package/dist/mjs/types/response/ws.js +2 -0
  198. package/dist/mjs/types/response/ws.js.map +1 -0
  199. package/dist/mjs/types/shared.types.d.ts +60 -0
  200. package/dist/mjs/types/shared.types.js +2 -0
  201. package/dist/mjs/types/shared.types.js.map +1 -0
  202. package/dist/mjs/types/websockets/client.d.ts +73 -0
  203. package/dist/mjs/types/websockets/client.js +2 -0
  204. package/dist/mjs/types/websockets/client.js.map +1 -0
  205. package/dist/mjs/types/websockets/events.d.ts +40 -0
  206. package/dist/mjs/types/websockets/events.js +2 -0
  207. package/dist/mjs/types/websockets/events.js.map +1 -0
  208. package/dist/mjs/types/websockets/requests.d.ts +76 -0
  209. package/dist/mjs/types/websockets/requests.js +2 -0
  210. package/dist/mjs/types/websockets/requests.js.map +1 -0
  211. package/dist/mjs/types/websockets/wsAPI.d.ts +9 -0
  212. package/dist/mjs/types/websockets/wsAPI.js +2 -0
  213. package/dist/mjs/types/websockets/wsAPI.js.map +1 -0
  214. package/package.json +42 -30
  215. package/index.js +0 -1
  216. package/lib/index.d.ts +0 -1
  217. package/lib/index.js +0 -16
  218. package/lib/index.js.map +0 -1
@@ -0,0 +1,631 @@
1
+ import EventEmitter from 'events';
2
+ import WebSocket from 'isomorphic-ws';
3
+ import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js';
4
+ import { DefaultLogger } from './websocket/logger.js';
5
+ import { isMessageEvent, } from './websocket/websocket-util.js';
6
+ import { WsStore } from './websocket/WsStore.js';
7
+ import { WsConnectionStateEnum, } from './websocket/WsStore.types.js';
8
+ /**
9
+ * Users can conveniently pass topics as strings or objects (object has topic name + optional params).
10
+ *
11
+ * This method normalises topics into objects (object has topic name + optional params).
12
+ */
13
+ function getNormalisedTopicRequests(wsTopicRequests) {
14
+ const normalisedTopicRequests = [];
15
+ for (const wsTopicRequest of wsTopicRequests) {
16
+ // passed as string, convert to object
17
+ if (typeof wsTopicRequest === 'string') {
18
+ const topicRequest = {
19
+ topic: wsTopicRequest,
20
+ payload: undefined,
21
+ };
22
+ normalisedTopicRequests.push(topicRequest);
23
+ continue;
24
+ }
25
+ // already a normalised object, thanks to user
26
+ normalisedTopicRequests.push(wsTopicRequest);
27
+ }
28
+ return normalisedTopicRequests;
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
31
+ export class BaseWebsocketClient extends EventEmitter {
32
+ wsStore;
33
+ logger;
34
+ options;
35
+ wsApiRequestId = 0;
36
+ constructor(options, logger) {
37
+ super();
38
+ this.logger = logger || DefaultLogger;
39
+ this.wsStore = new WsStore(this.logger);
40
+ this.options = {
41
+ pongTimeout: 1000,
42
+ pingInterval: 10000,
43
+ reconnectTimeout: 500,
44
+ useSandbox: false,
45
+ recvWindow: 0,
46
+ // Requires a confirmation "response" from the ws connection before assuming it is ready
47
+ requireConnectionReadyConfirmation: false,
48
+ // Automatically auth after opening a connection?
49
+ authPrivateConnectionsOnConnect: false,
50
+ // Automatically include auth/sign with every WS request
51
+ authPrivateRequests: true,
52
+ // Automatically re-auth WS API, if we were auth'd before and get reconnected
53
+ reauthWSAPIOnReconnect: false,
54
+ ...options,
55
+ };
56
+ }
57
+ isPrivateWsKey(wsKey) {
58
+ return this.getPrivateWSKeys().includes(wsKey);
59
+ }
60
+ /** Returns auto-incrementing request ID, used to track promise references for async requests */
61
+ getNewRequestId() {
62
+ return `${++this.wsApiRequestId}`;
63
+ }
64
+ /**
65
+ * Subscribe to one or more topics on a WS connection (identified by WS Key).
66
+ *
67
+ * - Topics are automatically cached
68
+ * - Connections are automatically opened, if not yet connected
69
+ * - Authentication is automatically handled
70
+ * - Topics are automatically resubscribed to, if something happens to the connection, unless you call unsubsribeTopicsForWsKey(topics, key).
71
+ *
72
+ * @param wsTopicRequests array of topics to subscribe to
73
+ * @param wsKey ws key referring to the ws connection these topics should be subscribed on
74
+ */
75
+ subscribeTopicsForWsKey(wsTopicRequests, wsKey) {
76
+ const normalisedTopicRequests = getNormalisedTopicRequests(wsTopicRequests);
77
+ // Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically
78
+ for (const topic of normalisedTopicRequests) {
79
+ this.wsStore.addTopic(wsKey, topic);
80
+ }
81
+ const isConnected = this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTED);
82
+ const isConnectionInProgress = this.wsStore.isConnectionAttemptInProgress(wsKey);
83
+ // start connection process if it hasn't yet begun. Topics are automatically subscribed to on-connect
84
+ if (!isConnected && !isConnectionInProgress) {
85
+ return this.connect(wsKey);
86
+ }
87
+ // Subscribe should happen automatically once connected, nothing to do here after topics are added to wsStore.
88
+ if (!isConnected) {
89
+ /**
90
+ * Are we in the process of connection? Nothing to send yet.
91
+ */
92
+ this.logger.trace(`WS not connected - requests queued for retry once connected.`, {
93
+ ...WS_LOGGER_CATEGORY,
94
+ wsKey,
95
+ wsTopicRequests,
96
+ });
97
+ return;
98
+ }
99
+ // We're connected. Check if auth is needed and if already authenticated
100
+ const isPrivateConnection = this.isPrivateWsKey(wsKey);
101
+ const isAuthenticated = this.wsStore.get(wsKey)?.isAuthenticated;
102
+ if (isPrivateConnection && !isAuthenticated) {
103
+ /**
104
+ * If not authenticated yet and auth is required, don't request topics yet.
105
+ *
106
+ * Auth should already automatically be in progress, so no action needed from here. Topics will automatically subscribe post-auth success.
107
+ */
108
+ this.logger.trace(`WS connected but not authenticated yet - awaiting auth before subscribing`);
109
+ return false;
110
+ }
111
+ // Finally, request subscription to topics if the connection is healthy and ready
112
+ this.requestSubscribeTopics(wsKey, normalisedTopicRequests);
113
+ }
114
+ unsubscribeTopicsForWsKey(wsTopicRequests, wsKey) {
115
+ const normalisedTopicRequests = getNormalisedTopicRequests(wsTopicRequests);
116
+ // Store topics, so future automation (post-auth, post-reconnect) has everything needed to resubscribe automatically
117
+ for (const topic of normalisedTopicRequests) {
118
+ this.wsStore.addTopic(wsKey, topic);
119
+ }
120
+ const isConnected = this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTED);
121
+ // If not connected, don't need to do anything.
122
+ // Removing the topic from the store is enough to stop it from being resubscribed to on reconnect.
123
+ if (!isConnected) {
124
+ return;
125
+ }
126
+ // We're connected. Check if auth is needed and if already authenticated
127
+ const isPrivateConnection = this.isPrivateWsKey(wsKey);
128
+ const isAuthenticated = this.wsStore.get(wsKey)?.isAuthenticated;
129
+ if (isPrivateConnection && !isAuthenticated) {
130
+ /**
131
+ * If not authenticated yet and auth is required, don't need to do anything.
132
+ * We don't subscribe to topics until auth is complete anyway.
133
+ */
134
+ return;
135
+ }
136
+ // Finally, request subscription to topics if the connection is healthy and ready
137
+ this.requestUnsubscribeTopics(wsKey, normalisedTopicRequests);
138
+ }
139
+ /**
140
+ * Splits topic requests into two groups, public & private topic requests
141
+ */
142
+ sortTopicRequestsIntoPublicPrivate(wsTopicRequests, wsKey) {
143
+ const publicTopicRequests = [];
144
+ const privateTopicRequests = [];
145
+ for (const topic of wsTopicRequests) {
146
+ if (this.isPrivateTopicRequest(topic, wsKey)) {
147
+ privateTopicRequests.push(topic);
148
+ }
149
+ else {
150
+ publicTopicRequests.push(topic);
151
+ }
152
+ }
153
+ return {
154
+ publicReqs: publicTopicRequests,
155
+ privateReqs: privateTopicRequests,
156
+ };
157
+ }
158
+ /** Get the WsStore that tracks websockets & topics */
159
+ getWsStore() {
160
+ return this.wsStore;
161
+ }
162
+ close(wsKey, force) {
163
+ this.logger.info('Closing connection', { ...WS_LOGGER_CATEGORY, wsKey });
164
+ this.setWsState(wsKey, WsConnectionStateEnum.CLOSING);
165
+ this.clearTimers(wsKey);
166
+ const ws = this.getWs(wsKey);
167
+ ws?.close();
168
+ if (force) {
169
+ ws?.terminate();
170
+ }
171
+ }
172
+ closeAll(force) {
173
+ this.wsStore.getKeys().forEach((key) => {
174
+ this.close(key, force);
175
+ });
176
+ }
177
+ isConnected(wsKey) {
178
+ return this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTED);
179
+ }
180
+ /**
181
+ * Request connection to a specific websocket, instead of waiting for automatic connection.
182
+ */
183
+ async connect(wsKey) {
184
+ try {
185
+ if (this.wsStore.isWsOpen(wsKey)) {
186
+ this.logger.error('Refused to connect to ws with existing active connection', { ...WS_LOGGER_CATEGORY, wsKey });
187
+ return { wsKey };
188
+ }
189
+ if (this.wsStore.isConnectionAttemptInProgress(wsKey)) {
190
+ this.logger.error('Refused to connect to ws, connection attempt already active', { ...WS_LOGGER_CATEGORY, wsKey });
191
+ return;
192
+ }
193
+ if (!this.wsStore.getConnectionState(wsKey) ||
194
+ this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.INITIAL)) {
195
+ this.setWsState(wsKey, WsConnectionStateEnum.CONNECTING);
196
+ }
197
+ if (!this.wsStore.getConnectionInProgressPromise(wsKey)) {
198
+ this.wsStore.createConnectionInProgressPromise(wsKey, false);
199
+ }
200
+ try {
201
+ const url = await this.getWsUrl(wsKey);
202
+ const ws = this.connectToWsUrl(url, wsKey);
203
+ this.wsStore.setWs(wsKey, ws);
204
+ }
205
+ catch (e) {
206
+ this.logger.error(`Exception fetching WS URL`, e);
207
+ throw e;
208
+ }
209
+ return this.wsStore.getConnectionInProgressPromise(wsKey)?.promise;
210
+ }
211
+ catch (err) {
212
+ this.parseWsError('Connection failed', err, wsKey);
213
+ this.reconnectWithDelay(wsKey, this.options.reconnectTimeout);
214
+ }
215
+ }
216
+ connectToWsUrl(url, wsKey) {
217
+ this.logger.trace(`Opening WS connection to URL: ${url}`, {
218
+ ...WS_LOGGER_CATEGORY,
219
+ wsKey,
220
+ });
221
+ const ws = new WebSocket(url, undefined);
222
+ ws.onopen = (event) => this.onWsOpen(event, wsKey);
223
+ ws.onmessage = (event) => this.onWsMessage(event, wsKey, ws);
224
+ ws.onerror = (event) => this.parseWsError('websocket error', event, wsKey);
225
+ ws.onclose = (event) => this.onWsClose(event, wsKey);
226
+ if (typeof ws.on === 'function') {
227
+ ws.on('ping', (event) => this.onWsPing(event, wsKey, ws, 'event'));
228
+ ws.on('pong', (event) => this.onWsPong(event, wsKey, 'event'));
229
+ }
230
+ return ws;
231
+ }
232
+ parseWsError(context, error, wsKey) {
233
+ if (this.wsStore.isConnectionAttemptInProgress(wsKey)) {
234
+ this.setWsState(wsKey, WsConnectionStateEnum.ERROR_RECONNECTING);
235
+ }
236
+ if (!error.message) {
237
+ this.logger.error(`${context} due to unexpected error: `, error);
238
+ this.emit('response', { ...error, wsKey });
239
+ this.emit('exception', { ...error, wsKey });
240
+ return;
241
+ }
242
+ switch (error.message) {
243
+ case 'Unexpected server response: 401':
244
+ this.logger.error(`${context} due to 401 authorization failure.`, {
245
+ ...WS_LOGGER_CATEGORY,
246
+ wsKey,
247
+ });
248
+ break;
249
+ default:
250
+ if (error?.code === 'ENOTFOUND') {
251
+ this.logger.error(`${context} due to lookup exception: "${error?.msg || error?.message || error}"`, {
252
+ ...WS_LOGGER_CATEGORY,
253
+ wsKey,
254
+ error,
255
+ connectionState: this.wsStore.getConnectionState(wsKey),
256
+ });
257
+ break;
258
+ }
259
+ this.logger.error(`${context} due to unexpected response error: "${error?.msg || error?.message || error}"`, { ...WS_LOGGER_CATEGORY, wsKey, error });
260
+ break;
261
+ }
262
+ this.emit('exception', { ...error, wsKey });
263
+ }
264
+ /** Get a signature, build the auth request and send it */
265
+ async sendAuthRequest(wsKey) {
266
+ try {
267
+ this.logger.info(`Sending auth request...`, {
268
+ ...WS_LOGGER_CATEGORY,
269
+ wsKey,
270
+ });
271
+ const request = await this.getWsAuthRequestEvent(wsKey);
272
+ return this.tryWsSend(wsKey, JSON.stringify(request));
273
+ }
274
+ catch (e) {
275
+ this.logger.trace(e, { ...WS_LOGGER_CATEGORY, wsKey });
276
+ }
277
+ }
278
+ reconnectWithDelay(wsKey, connectionDelayMs) {
279
+ this.clearTimers(wsKey);
280
+ this.wsStore.get(wsKey, true).activeReconnectTimer = setTimeout(() => {
281
+ this.logger.info('Reconnecting to websocket', {
282
+ ...WS_LOGGER_CATEGORY,
283
+ wsKey,
284
+ });
285
+ this.connect(wsKey);
286
+ }, connectionDelayMs);
287
+ }
288
+ ping(wsKey) {
289
+ if (this.wsStore.get(wsKey, true).activePongTimer) {
290
+ return;
291
+ }
292
+ this.clearPongTimer(wsKey);
293
+ this.logger.trace('Sending ping', { ...WS_LOGGER_CATEGORY, wsKey });
294
+ const ws = this.wsStore.get(wsKey, true).ws;
295
+ if (!ws) {
296
+ this.logger.error(`Unable to send ping for wsKey "${wsKey}" - no connection found`);
297
+ return;
298
+ }
299
+ this.sendPingEvent(wsKey, ws);
300
+ this.wsStore.get(wsKey, true).activePongTimer = setTimeout(() => {
301
+ this.logger.info('Pong timeout - closing socket to reconnect', {
302
+ ...WS_LOGGER_CATEGORY,
303
+ wsKey,
304
+ });
305
+ this.clearPongTimer(wsKey);
306
+ this.getWs(wsKey)?.terminate();
307
+ }, this.options.pongTimeout);
308
+ }
309
+ clearTimers(wsKey) {
310
+ this.clearPingTimer(wsKey);
311
+ this.clearPongTimer(wsKey);
312
+ const wsState = this.wsStore.get(wsKey);
313
+ if (wsState?.activeReconnectTimer) {
314
+ clearTimeout(wsState.activeReconnectTimer);
315
+ }
316
+ }
317
+ // Send a ping at intervals
318
+ clearPingTimer(wsKey) {
319
+ const wsState = this.wsStore.get(wsKey);
320
+ if (wsState?.activePingTimer) {
321
+ clearInterval(wsState.activePingTimer);
322
+ wsState.activePingTimer = undefined;
323
+ }
324
+ }
325
+ // Expect a pong within a time limit
326
+ clearPongTimer(wsKey) {
327
+ const wsState = this.wsStore.get(wsKey);
328
+ if (wsState?.activePongTimer) {
329
+ clearTimeout(wsState.activePongTimer);
330
+ wsState.activePongTimer = undefined;
331
+ // this.logger.trace(`Cleared pong timeout for "${wsKey}"`);
332
+ }
333
+ else {
334
+ // this.logger.trace(`No active pong timer for "${wsKey}"`);
335
+ }
336
+ }
337
+ /**
338
+ * Simply builds and sends subscribe events for a list of topics for a ws key
339
+ *
340
+ * @private Use the `subscribe(topics)` or `subscribeTopicsForWsKey(topics, wsKey)` method to subscribe to topics. Send WS message to subscribe to topics.
341
+ */
342
+ async requestSubscribeTopics(wsKey, topics) {
343
+ if (!topics.length) {
344
+ return;
345
+ }
346
+ // Automatically splits requests into smaller batches, if needed
347
+ const subscribeWsMessages = await this.getWsOperationEventsForTopics(topics, wsKey, 'subscribe');
348
+ this.logger.trace(`Subscribing to ${topics.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches. Events: "${JSON.stringify(topics)}"`);
349
+ for (const wsMessage of subscribeWsMessages) {
350
+ this.logger.trace(`Sending batch via message: "${wsMessage}"`);
351
+ this.tryWsSend(wsKey, wsMessage);
352
+ }
353
+ this.logger.trace(`Finished subscribing to ${topics.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches.`);
354
+ }
355
+ /**
356
+ * Simply builds and sends unsubscribe events for a list of topics for a ws key
357
+ *
358
+ * @private Use the `unsubscribe(topics)` method to unsubscribe from topics. Send WS message to unsubscribe from topics.
359
+ */
360
+ async requestUnsubscribeTopics(wsKey, wsTopicRequests) {
361
+ if (!wsTopicRequests.length) {
362
+ return;
363
+ }
364
+ const subscribeWsMessages = await this.getWsOperationEventsForTopics(wsTopicRequests, wsKey, 'unsubscribe');
365
+ this.logger.trace(`Unsubscribing to ${wsTopicRequests.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches. Events: "${JSON.stringify(wsTopicRequests)}"`);
366
+ for (const wsMessage of subscribeWsMessages) {
367
+ this.logger.trace(`Sending batch via message: "${wsMessage}"`);
368
+ this.tryWsSend(wsKey, wsMessage);
369
+ }
370
+ this.logger.trace(`Finished unsubscribing to ${wsTopicRequests.length} "${wsKey}" topics in ${subscribeWsMessages.length} batches.`);
371
+ }
372
+ /**
373
+ * Try sending a string event on a WS connection (identified by the WS Key)
374
+ */
375
+ tryWsSend(wsKey, wsMessage) {
376
+ try {
377
+ this.logger.trace(`Sending upstream ws message: `, {
378
+ ...WS_LOGGER_CATEGORY,
379
+ wsMessage,
380
+ wsKey,
381
+ });
382
+ if (!wsKey) {
383
+ throw new Error('Cannot send message due to no known websocket for this wsKey');
384
+ }
385
+ const ws = this.getWs(wsKey);
386
+ if (!ws) {
387
+ throw new Error(`${wsKey} socket not connected yet, call "connectAll()" first then try again when the "open" event arrives`);
388
+ }
389
+ ws.send(wsMessage);
390
+ }
391
+ catch (e) {
392
+ this.logger.error(`Failed to send WS message`, {
393
+ ...WS_LOGGER_CATEGORY,
394
+ wsMessage,
395
+ wsKey,
396
+ exception: e,
397
+ });
398
+ }
399
+ }
400
+ async onWsOpen(event, wsKey) {
401
+ const didReconnectSuccessfully = this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.RECONNECTING) ||
402
+ this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.ERROR_RECONNECTING);
403
+ if (this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTING)) {
404
+ this.logger.info('Websocket connected', {
405
+ ...WS_LOGGER_CATEGORY,
406
+ wsKey,
407
+ });
408
+ this.emit('open', { wsKey, event });
409
+ }
410
+ else {
411
+ this.logger.info('Websocket reconnected', {
412
+ ...WS_LOGGER_CATEGORY,
413
+ wsKey,
414
+ didReconnectSuccessfully,
415
+ });
416
+ this.emit('reconnected', {
417
+ wsKey,
418
+ event,
419
+ didReconnectSuccessfully,
420
+ });
421
+ }
422
+ this.setWsState(wsKey, WsConnectionStateEnum.CONNECTED);
423
+ this.logger.trace(`Enabled ping timer`, { ...WS_LOGGER_CATEGORY, wsKey });
424
+ this.wsStore.get(wsKey, true).activePingTimer = setInterval(() => this.ping(wsKey), this.options.pingInterval);
425
+ if (!this.options.requireConnectionReadyConfirmation) {
426
+ await this.onWsReadyForEvents(wsKey);
427
+ }
428
+ }
429
+ onWsPing(_event, wsKey, ws, source) {
430
+ this.logger.trace('Received ping, sending pong frame', {
431
+ ...WS_LOGGER_CATEGORY,
432
+ wsKey,
433
+ source,
434
+ });
435
+ ws.pong();
436
+ }
437
+ onWsPong(_event, wsKey, source) {
438
+ this.logger.trace('Received pong, clearing pong timer', {
439
+ ...WS_LOGGER_CATEGORY,
440
+ wsKey,
441
+ source,
442
+ });
443
+ this.clearPongTimer(wsKey);
444
+ }
445
+ /**
446
+ * Called automatically once a connection is ready.
447
+ * - Some exchanges are ready immediately after the connections open.
448
+ * - Some exchanges send an event to confirm the connection is ready for us.
449
+ *
450
+ * This method is called to act when the connection is ready. Use `requireConnectionReadyConfirmation` to control how this is called.
451
+ */
452
+ async onWsReadyForEvents(wsKey) {
453
+ try {
454
+ // Resolve & cleanup deferred "connection attempt in progress" promise
455
+ const connectionInProgressPromise = this.wsStore.getConnectionInProgressPromise(wsKey);
456
+ if (connectionInProgressPromise?.resolve) {
457
+ connectionInProgressPromise.resolve({
458
+ wsKey,
459
+ });
460
+ }
461
+ }
462
+ catch (e) {
463
+ this.logger.error(`Exception trying to resolve "connectionInProgress" promise`);
464
+ }
465
+ // Remove before resolving, in case there's more requests queued
466
+ this.wsStore.removeConnectingInProgressPromise(wsKey);
467
+ // Some websockets require an auth packet to be sent after opening the connection
468
+ if (this.isPrivateWsKey(wsKey) &&
469
+ this.options.authPrivateConnectionsOnConnect) {
470
+ await this.sendAuthRequest(wsKey);
471
+ }
472
+ // Reconnect to topics known before it connected
473
+ const { privateReqs, publicReqs } = this.sortTopicRequestsIntoPublicPrivate([...this.wsStore.getTopics(wsKey)], wsKey);
474
+ // Request sub to public topics, if any
475
+ this.requestSubscribeTopics(wsKey, publicReqs);
476
+ // Request sub to private topics, if auth on connect isn't needed
477
+ if (!this.options.authPrivateConnectionsOnConnect) {
478
+ this.requestSubscribeTopics(wsKey, privateReqs);
479
+ }
480
+ }
481
+ /**
482
+ * Handle subscription to private topics _after_ authentication successfully completes asynchronously.
483
+ *
484
+ * Only used for exchanges that require auth before sending private topic subscription requests
485
+ */
486
+ onWsAuthenticated(wsKey, event) {
487
+ const wsState = this.wsStore.get(wsKey, true);
488
+ wsState.isAuthenticated = true;
489
+ if (this.options.authPrivateConnectionsOnConnect) {
490
+ const topics = [...this.wsStore.getTopics(wsKey)];
491
+ const privateTopics = topics.filter((topic) => this.isPrivateTopicRequest(topic, wsKey));
492
+ if (privateTopics.length) {
493
+ this.subscribeTopicsForWsKey(privateTopics, wsKey);
494
+ }
495
+ }
496
+ if (event?.isWSAPI && event?.WSAPIAuthChannel) {
497
+ wsState.didAuthWSAPI = true;
498
+ wsState.WSAPIAuthChannel = event.WSAPIAuthChannel;
499
+ }
500
+ }
501
+ onWsMessage(event, wsKey, ws) {
502
+ try {
503
+ // any message can clear the pong timer - wouldn't get a message if the ws wasn't working
504
+ this.clearPongTimer(wsKey);
505
+ if (this.isWsPong(event)) {
506
+ return this.onWsPong(event, wsKey, 'onWsMessage');
507
+ }
508
+ if (this.isWsPing(event)) {
509
+ this.logger.trace('Received ping', {
510
+ ...WS_LOGGER_CATEGORY,
511
+ wsKey,
512
+ event,
513
+ });
514
+ this.sendPongEvent(wsKey, ws);
515
+ return;
516
+ }
517
+ if (isMessageEvent(event)) {
518
+ const data = event.data;
519
+ const dataType = event.type;
520
+ const emittableEvents = this.resolveEmittableEvents(wsKey, event);
521
+ if (!emittableEvents.length) {
522
+ // console.log(`raw event: `, { data, dataType, emittableEvents });
523
+ this.logger.error('Unhandled/unrecognised ws event message - returned no emittable data', {
524
+ ...WS_LOGGER_CATEGORY,
525
+ message: data || 'no message',
526
+ dataType,
527
+ event,
528
+ wsKey,
529
+ });
530
+ return this.emit('update', { ...event, wsKey });
531
+ }
532
+ for (const emittable of emittableEvents) {
533
+ if (this.isWsPong(emittable)) {
534
+ this.logger.trace('Received pong', {
535
+ ...WS_LOGGER_CATEGORY,
536
+ wsKey,
537
+ data,
538
+ });
539
+ continue;
540
+ }
541
+ if (emittable.eventType === 'connectionReady') {
542
+ this.logger.trace(`Successfully connected - connection ready for events`, {
543
+ ...WS_LOGGER_CATEGORY,
544
+ wsKey,
545
+ });
546
+ const wsState = this.wsStore.get(wsKey);
547
+ if (this.isPrivateWsKey(wsKey) &&
548
+ wsState &&
549
+ !this.options.authPrivateConnectionsOnConnect) {
550
+ wsState.isAuthenticated = true;
551
+ }
552
+ this.emit('response', { ...emittable.event, wsKey });
553
+ this.onWsReadyForEvents(wsKey);
554
+ continue;
555
+ }
556
+ if (emittable.eventType === 'authenticated') {
557
+ this.logger.trace(`Successfully authenticated`, {
558
+ ...WS_LOGGER_CATEGORY,
559
+ wsKey,
560
+ });
561
+ this.emit(emittable.eventType, { ...emittable.event, wsKey });
562
+ this.onWsAuthenticated(wsKey, emittable.event);
563
+ continue;
564
+ }
565
+ this.emit(emittable.eventType, { ...emittable.event, wsKey });
566
+ }
567
+ return;
568
+ }
569
+ this.logger.error('Unhandled/unrecognised ws event message - unexpected message format', {
570
+ ...WS_LOGGER_CATEGORY,
571
+ message: event || 'no message',
572
+ event,
573
+ wsKey,
574
+ });
575
+ }
576
+ catch (e) {
577
+ this.logger.error('Failed to parse ws event message', {
578
+ ...WS_LOGGER_CATEGORY,
579
+ error: e,
580
+ event,
581
+ wsKey,
582
+ });
583
+ }
584
+ }
585
+ onWsClose(event, wsKey) {
586
+ this.logger.info('Websocket connection closed', {
587
+ ...WS_LOGGER_CATEGORY,
588
+ wsKey,
589
+ });
590
+ if (this.wsStore.getConnectionState(wsKey) !== WsConnectionStateEnum.CLOSING) {
591
+ // clean up any pending promises for this connection
592
+ this.getWsStore().rejectAllDeferredPromises(wsKey, 'connection lost, reconnecting');
593
+ this.setWsState(wsKey, WsConnectionStateEnum.INITIAL);
594
+ this.reconnectWithDelay(wsKey, this.options.reconnectTimeout);
595
+ this.emit('reconnect', { wsKey, event });
596
+ }
597
+ else {
598
+ // clean up any pending promises for this connection
599
+ this.getWsStore().rejectAllDeferredPromises(wsKey, 'disconnected');
600
+ this.setWsState(wsKey, WsConnectionStateEnum.INITIAL);
601
+ this.emit('close', { wsKey, event });
602
+ }
603
+ }
604
+ getWs(wsKey) {
605
+ return this.wsStore.getWs(wsKey);
606
+ }
607
+ setWsState(wsKey, state) {
608
+ this.wsStore.setConnectionState(wsKey, state);
609
+ }
610
+ /**
611
+ * Promise-driven method to assert that a ws has successfully connected (will await until connection is open)
612
+ */
613
+ async assertIsConnected(wsKey) {
614
+ const isConnected = this.getWsStore().isConnectionState(wsKey, WsConnectionStateEnum.CONNECTED);
615
+ if (!isConnected) {
616
+ const inProgressPromise = this.getWsStore().getConnectionInProgressPromise(wsKey);
617
+ // Already in progress? Await shared promise and retry
618
+ if (inProgressPromise) {
619
+ this.logger.trace(`sendWSAPIRequest(): Awaiting EXISTING connection promise...`);
620
+ await inProgressPromise.promise;
621
+ this.logger.trace(`sendWSAPIRequest(): EXISTING connection promise resolved!`);
622
+ return;
623
+ }
624
+ // Start connection, it should automatically store/return a promise.
625
+ this.logger.trace(`sendWSAPIRequest(): Not connected yet...queue await connection...`);
626
+ await this.connect(wsKey);
627
+ this.logger.trace(`sendWSAPIRequest(): New connection promise resolved! `);
628
+ }
629
+ }
630
+ }
631
+ //# sourceMappingURL=BaseWSClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseWSClient.js","sourceRoot":"","sources":["../../../src/lib/BaseWSClient.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,SAAS,MAAM,eAAe,CAAC;AAOtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EACL,cAAc,GAIf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAEL,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AA6CtC;;;;GAIG;AACH,SAAS,0BAA0B,CACjC,eAAsD;IAEtD,MAAM,uBAAuB,GAA6B,EAAE,CAAC;IAE7D,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,sCAAsC;QACtC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;YACvC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