From 0e2ddba0076969ca076ee5b207cfb6794fd0b578 Mon Sep 17 00:00:00 2001 From: meafmira Date: Wed, 8 Jun 2022 13:21:34 +0530 Subject: [PATCH] fix: get rid of new object creation for every pair config update --- src/services/OrionAggregator/ws/index.ts | 65 +++++++++++++----------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 343d6bc..27611e2 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -367,18 +367,18 @@ class OrionAggregatorWS { exchanges, vob, ] = item; - return [ - ...acc, - { - price, - amount, - exchanges, - vob: vob.map(([side, pairName]) => ({ - side, - pairName, - })), - }, - ]; + + acc.push({ + price, + amount, + exchanges, + vob: vob.map(([side, pairName]) => ({ + side, + pairName, + })), + }); + + return acc; }, []); this.subscriptions[ SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE @@ -391,13 +391,15 @@ class OrionAggregatorWS { break; case MessageType.ASSET_PAIRS_CONFIG_UPDATE: { const pairs = json; - const priceUpdates = pairs.u.reduce>>((acc, [pairName, minQty, pricePrecision]) => ({ - ...acc, - [pairName]: { + let priceUpdates: Partial> = {}; + + pairs.u.forEach(([pairName, minQty, pricePrecision]) => { + priceUpdates[pairName] = { minQty, pricePrecision, - }, - }), {}); + } + }); + this.subscriptions[ SubscriptionType.ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE ]?.default?.callback({ @@ -412,12 +414,12 @@ class OrionAggregatorWS { .reduce>>((prev, [asset, assetBalances]) => { if (!assetBalances) return prev; const [tradable, reserved, contract, wallet, allowance] = assetBalances; - return { - ...prev, - [asset]: { - tradable, reserved, contract, wallet, allowance, - }, - }; + + prev[asset] = { + tradable, reserved, contract, wallet, allowance, + } + + return prev; }, {}) : {}; switch (json.k) { // message kind @@ -425,10 +427,10 @@ class OrionAggregatorWS { const fullOrders = json.o ? json.o.reduce((prev, o) => { const fullOrder = mapFullOrder(o); - return [ - ...prev, - fullOrder, - ]; + + prev.push(fullOrder); + + return prev; }, []) : undefined; @@ -465,10 +467,11 @@ class OrionAggregatorWS { } break; case MessageType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: { - const brokerBalances = json.bb.reduce>>((acc, [asset, balance]) => ({ - ...acc, - [asset]: balance, - }), {}); + let brokerBalances: Partial> = {}; + + json.bb.forEach(([asset, balance]) => { + brokerBalances[asset] = balance + }); this.subscriptions[ SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE