From 536a9a0605fbc9d928f891fb06a63734fb14faf1 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Wed, 7 Jun 2023 21:55:06 +0400 Subject: [PATCH] Fix resubscription --- package.json | 2 +- src/services/Aggregator/ws/index.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b578f49..a5356d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.22", + "version": "0.19.23", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Aggregator/ws/index.ts b/src/services/Aggregator/ws/index.ts index 077a037..7f5b795 100644 --- a/src/services/Aggregator/ws/index.ts +++ b/src/services/Aggregator/ws/index.ts @@ -173,6 +173,9 @@ const nonExistentMessageRegex = /Could not cancel nonexistent subscription: (.*) type Subscriptions = Partial<{ [K in keyof Subscription]: Partial> }>; + +const FUTURES_SUFFIX = 'USDF'; + class AggregatorWS { private ws?: WebSocket | undefined; @@ -331,6 +334,12 @@ class AggregatorWS { ...(details !== undefined) && { d: details }, }); + const isOrderBooksSubscription = (subId: string) => { + const isSpotPairName = subId.includes('-') && subId.split('-').length === 2; + const isFuturesPairName = subId.endsWith(FUTURES_SUFFIX); + return isSpotPairName || isFuturesPairName; + } + if (newestSubId.includes('0x')) { // is wallet address (ADDRESS_UPDATE) const auSubscriptions = this.subscriptions[SubscriptionType.ADDRESS_UPDATES_SUBSCRIBE]; if (auSubscriptions) { @@ -355,7 +364,7 @@ class AggregatorWS { delete this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[newestSubId]; delete this.subscriptions[SubscriptionType.FUTURES_TRADE_INFO_SUBSCRIBE]?.[newestSubId]; // !!! swap info subscription is uuid that contains hyphen - } else if (newestSubId.includes('-') && newestSubId.split('-').length === 2) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE) + } else if (isOrderBooksSubscription(newestSubId)) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE) const aobSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]; if (aobSubscriptions) { const targetAobSub = Object.entries(aobSubscriptions).find(([, value]) => value?.payload === newestSubId);