@binance/common 1.0.3 → 1.0.4
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/dist/index.d.mts +23 -21
- package/dist/index.d.ts +23 -21
- package/dist/index.js +27 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -569,25 +569,6 @@ function replaceWebsocketStreamsPlaceholders(str, variables) {
|
|
|
569
569
|
return "";
|
|
570
570
|
});
|
|
571
571
|
}
|
|
572
|
-
function createStreamHandler(websocketBase, stream, id) {
|
|
573
|
-
websocketBase.subscribe(stream, id);
|
|
574
|
-
let registeredCallback;
|
|
575
|
-
return {
|
|
576
|
-
on: (event, callback) => {
|
|
577
|
-
if (event === "message") {
|
|
578
|
-
registeredCallback = (data) => callback(data);
|
|
579
|
-
const callbackSet = websocketBase.streamCallbackMap.get(stream) ?? /* @__PURE__ */ new Set();
|
|
580
|
-
callbackSet.add(registeredCallback);
|
|
581
|
-
websocketBase.streamCallbackMap.set(stream, callbackSet);
|
|
582
|
-
}
|
|
583
|
-
},
|
|
584
|
-
unsubscribe: () => {
|
|
585
|
-
if (registeredCallback)
|
|
586
|
-
websocketBase.streamCallbackMap.get(stream)?.delete(registeredCallback);
|
|
587
|
-
websocketBase.unsubscribe(stream, id);
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
572
|
|
|
592
573
|
// src/websocket.ts
|
|
593
574
|
import { EventEmitter } from "events";
|
|
@@ -1047,6 +1028,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1047
1028
|
constructor(configuration, connectionPool = []) {
|
|
1048
1029
|
super(configuration, connectionPool);
|
|
1049
1030
|
this.isConnecting = false;
|
|
1031
|
+
this.streamCallbackMap = /* @__PURE__ */ new Map();
|
|
1050
1032
|
this.logger = Logger.getInstance();
|
|
1051
1033
|
this.configuration = configuration;
|
|
1052
1034
|
}
|
|
@@ -1087,6 +1069,10 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1087
1069
|
};
|
|
1088
1070
|
request?.resolve(response);
|
|
1089
1071
|
}
|
|
1072
|
+
} else if ("event" in message && "e" in message["event"] && this.streamCallbackMap.size > 0) {
|
|
1073
|
+
this.streamCallbackMap.forEach(
|
|
1074
|
+
(callbacks) => callbacks.forEach((callback) => callback(message["event"]))
|
|
1075
|
+
);
|
|
1090
1076
|
} else {
|
|
1091
1077
|
this.logger.warn("Received response for unknown or timed-out request:", message);
|
|
1092
1078
|
}
|
|
@@ -1156,7 +1142,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1156
1142
|
return this.send(JSON.stringify(data), id, true, this.configuration?.timeout);
|
|
1157
1143
|
}
|
|
1158
1144
|
};
|
|
1159
|
-
var
|
|
1145
|
+
var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
1160
1146
|
constructor(configuration, connectionPool = []) {
|
|
1161
1147
|
super(configuration, connectionPool);
|
|
1162
1148
|
this.streamConnectionMap = /* @__PURE__ */ new Map();
|
|
@@ -1362,6 +1348,26 @@ var WebsocketStreamsBase2 = class extends WebsocketCommon {
|
|
|
1362
1348
|
return this.streamConnectionMap.has(stream);
|
|
1363
1349
|
}
|
|
1364
1350
|
};
|
|
1351
|
+
function createStreamHandler(websocketBase, streamOrId, id) {
|
|
1352
|
+
if (websocketBase instanceof WebsocketStreamsBase) websocketBase.subscribe(streamOrId, id);
|
|
1353
|
+
let registeredCallback;
|
|
1354
|
+
return {
|
|
1355
|
+
on: (event, callback) => {
|
|
1356
|
+
if (event === "message") {
|
|
1357
|
+
registeredCallback = (data) => callback(data);
|
|
1358
|
+
const callbackSet = websocketBase.streamCallbackMap.get(streamOrId) ?? /* @__PURE__ */ new Set();
|
|
1359
|
+
callbackSet.add(registeredCallback);
|
|
1360
|
+
websocketBase.streamCallbackMap.set(streamOrId, callbackSet);
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1363
|
+
unsubscribe: () => {
|
|
1364
|
+
if (registeredCallback)
|
|
1365
|
+
websocketBase.streamCallbackMap.get(streamOrId)?.delete(registeredCallback);
|
|
1366
|
+
if (websocketBase instanceof WebsocketStreamsBase)
|
|
1367
|
+
websocketBase.unsubscribe(streamOrId, id);
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1365
1371
|
export {
|
|
1366
1372
|
ALGO_REST_API_PROD_URL,
|
|
1367
1373
|
AUTO_INVEST_REST_API_PROD_URL,
|
|
@@ -1427,7 +1433,7 @@ export {
|
|
|
1427
1433
|
WebsocketAPIBase,
|
|
1428
1434
|
WebsocketCommon,
|
|
1429
1435
|
WebsocketEventEmitter,
|
|
1430
|
-
|
|
1436
|
+
WebsocketStreamsBase,
|
|
1431
1437
|
assertParamExists,
|
|
1432
1438
|
buildQueryString,
|
|
1433
1439
|
createStreamHandler,
|