@medievalrain/binance-ts 0.1.0 → 0.2.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 (2) hide show
  1. package/dist/index.js +29 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1112,6 +1112,35 @@ var BinanceWebsocketClient = class {
1112
1112
  }
1113
1113
  async unsubscribe(...channels) {
1114
1114
  await this.connect();
1115
+ const id = this.subscriptionId;
1116
+ const pendingChannels = [];
1117
+ for (const channel of channels) if (this.subscriptions.get(channel) !== "PENDING_UNSUBSCRIPTION") {
1118
+ pendingChannels.push(channel);
1119
+ this.subscriptions.set(channel, "PENDING_UNSUBSCRIPTION");
1120
+ }
1121
+ const data = {
1122
+ method: "UNSUBSCRIBE",
1123
+ params: pendingChannels,
1124
+ id
1125
+ };
1126
+ this.subscriptionId += 1;
1127
+ this.sendMessage(data);
1128
+ return new Promise((resolve, reject) => {
1129
+ const controller = new AbortController();
1130
+ const handler = (data$1) => {
1131
+ if (data$1.id !== id) return;
1132
+ controller.abort();
1133
+ if ("error" in data$1) {
1134
+ for (const channel of pendingChannels) if (this.subscriptions.get(channel) === "PENDING_UNSUBSCRIPTION") this.subscriptions.set(channel, "SUBSCRIBED");
1135
+ this.emitter.emit("error", data$1);
1136
+ reject(/* @__PURE__ */ new Error(`Unsubscription ${id} failed`));
1137
+ } else {
1138
+ pendingChannels.forEach((channel) => this.subscriptions.delete(channel));
1139
+ resolve();
1140
+ }
1141
+ };
1142
+ this.emitter.addEventListener("connectionMessage", handler, { signal: controller.signal });
1143
+ });
1115
1144
  }
1116
1145
  async reconnect() {
1117
1146
  this.socket = this.createSocket();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medievalrain/binance-ts",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Binance API SDK",
5
5
  "access": "public",
6
6
  "type": "module",