@binance/common 1.2.2 → 1.2.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 +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +43 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -440,7 +440,8 @@ var ConfigurationRestAPI = class {
|
|
|
440
440
|
proxy: param.proxy && {
|
|
441
441
|
host: param.proxy.host,
|
|
442
442
|
port: param.proxy.port,
|
|
443
|
-
|
|
443
|
+
...param.proxy.protocol && { protocol: param.proxy.protocol },
|
|
444
|
+
...param.proxy.auth && { auth: param.proxy.auth }
|
|
444
445
|
},
|
|
445
446
|
httpsAgent: param.httpsAgent ?? false,
|
|
446
447
|
headers: {
|
|
@@ -777,10 +778,24 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
777
778
|
* @returns Timer handle
|
|
778
779
|
*/
|
|
779
780
|
scheduleTimer(connection, callback, delay2, type = "timeout") {
|
|
780
|
-
|
|
781
|
-
if (!
|
|
782
|
-
|
|
783
|
-
|
|
781
|
+
let timers = this.connectionTimers.get(connection);
|
|
782
|
+
if (!timers) {
|
|
783
|
+
timers = /* @__PURE__ */ new Set();
|
|
784
|
+
this.connectionTimers.set(connection, timers);
|
|
785
|
+
}
|
|
786
|
+
const timerRecord = { type };
|
|
787
|
+
const wrappedTimeout = () => {
|
|
788
|
+
try {
|
|
789
|
+
callback();
|
|
790
|
+
} finally {
|
|
791
|
+
timers.delete(timerRecord);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
let timer;
|
|
795
|
+
if (type === "timeout") timer = setTimeout(wrappedTimeout, delay2);
|
|
796
|
+
else timer = setInterval(callback, delay2);
|
|
797
|
+
timerRecord.timer = timer;
|
|
798
|
+
timers.add(timerRecord);
|
|
784
799
|
return timer;
|
|
785
800
|
}
|
|
786
801
|
/**
|
|
@@ -1042,13 +1057,13 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1042
1057
|
this.onMessage(data.toString(), targetConnection);
|
|
1043
1058
|
});
|
|
1044
1059
|
ws.on("ping", () => {
|
|
1045
|
-
this.logger.
|
|
1060
|
+
this.logger.debug("Received PING from server");
|
|
1046
1061
|
this.emit("ping");
|
|
1047
1062
|
ws.pong();
|
|
1048
|
-
this.logger.
|
|
1063
|
+
this.logger.debug("Responded PONG to server's PING message");
|
|
1049
1064
|
});
|
|
1050
1065
|
ws.on("pong", () => {
|
|
1051
|
-
this.logger.
|
|
1066
|
+
this.logger.debug("Received PONG from server");
|
|
1052
1067
|
this.emit("pong");
|
|
1053
1068
|
});
|
|
1054
1069
|
ws.on("error", (err) => {
|
|
@@ -1128,7 +1143,7 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1128
1143
|
this.logger.warn("Ping only can be sent when connection is ready.");
|
|
1129
1144
|
return;
|
|
1130
1145
|
}
|
|
1131
|
-
this.logger.
|
|
1146
|
+
this.logger.debug("Sending PING to all connected Websocket servers.");
|
|
1132
1147
|
connectedConnections.forEach((connection) => {
|
|
1133
1148
|
if (connection.ws) {
|
|
1134
1149
|
connection.ws.ping();
|
|
@@ -1150,7 +1165,7 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1150
1165
|
*/
|
|
1151
1166
|
send(payload, id, promiseBased = true, timeout = 5e3, connection) {
|
|
1152
1167
|
if (!this.isConnected(connection)) {
|
|
1153
|
-
const errorMsg = "
|
|
1168
|
+
const errorMsg = "Unable to send message \u2014 connection is not available.";
|
|
1154
1169
|
this.logger.warn(errorMsg);
|
|
1155
1170
|
if (promiseBased) return Promise.reject(new Error(errorMsg));
|
|
1156
1171
|
else throw new Error(errorMsg);
|
|
@@ -1166,17 +1181,22 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1166
1181
|
if (promiseBased) {
|
|
1167
1182
|
return new Promise((resolve, reject) => {
|
|
1168
1183
|
if (!id) return reject(new Error("id is required for promise-based sending."));
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1184
|
+
const timeoutHandle = setTimeout(() => {
|
|
1185
|
+
if (connectionToUse.pendingRequests.has(id)) {
|
|
1186
|
+
connectionToUse.pendingRequests.delete(id);
|
|
1187
|
+
reject(new Error(`Request timeout for id: ${id}`));
|
|
1188
|
+
}
|
|
1189
|
+
}, timeout);
|
|
1190
|
+
connectionToUse.pendingRequests.set(id, {
|
|
1191
|
+
resolve: (v) => {
|
|
1192
|
+
clearTimeout(timeoutHandle);
|
|
1193
|
+
resolve(v);
|
|
1177
1194
|
},
|
|
1178
|
-
|
|
1179
|
-
|
|
1195
|
+
reject: (e) => {
|
|
1196
|
+
clearTimeout(timeoutHandle);
|
|
1197
|
+
reject(e);
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1180
1200
|
});
|
|
1181
1201
|
}
|
|
1182
1202
|
}
|
|
@@ -1256,13 +1276,13 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1256
1276
|
reject(new Error("Websocket connection timed out"));
|
|
1257
1277
|
}, 1e4);
|
|
1258
1278
|
this.connectPool(this.prepareURL(this.configuration.wsURL)).then(() => {
|
|
1259
|
-
clearTimeout(timeout);
|
|
1260
1279
|
this.isConnecting = false;
|
|
1261
1280
|
resolve();
|
|
1262
1281
|
}).catch((error) => {
|
|
1263
|
-
clearTimeout(timeout);
|
|
1264
1282
|
this.isConnecting = false;
|
|
1265
1283
|
reject(error);
|
|
1284
|
+
}).finally(() => {
|
|
1285
|
+
clearTimeout(timeout);
|
|
1266
1286
|
});
|
|
1267
1287
|
});
|
|
1268
1288
|
}
|
|
@@ -1433,13 +1453,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
|
1433
1453
|
const timeout = setTimeout(() => {
|
|
1434
1454
|
reject(new Error("Websocket connection timed out"));
|
|
1435
1455
|
}, 1e4);
|
|
1436
|
-
this.connectPool(this.prepareURL(streams)).then(() =>
|
|
1437
|
-
clearTimeout(timeout);
|
|
1438
|
-
resolve();
|
|
1439
|
-
}).catch((error) => {
|
|
1440
|
-
clearTimeout(timeout);
|
|
1441
|
-
reject(error);
|
|
1442
|
-
});
|
|
1456
|
+
this.connectPool(this.prepareURL(streams)).then(() => resolve()).catch((error) => reject(error)).finally(() => clearTimeout(timeout));
|
|
1443
1457
|
});
|
|
1444
1458
|
}
|
|
1445
1459
|
/**
|