mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
fix: get rid of new object creation for every pair config update
This commit is contained in:
@@ -367,18 +367,18 @@ class OrionAggregatorWS {
|
|||||||
exchanges,
|
exchanges,
|
||||||
vob,
|
vob,
|
||||||
] = item;
|
] = item;
|
||||||
return [
|
|
||||||
...acc,
|
acc.push({
|
||||||
{
|
price,
|
||||||
price,
|
amount,
|
||||||
amount,
|
exchanges,
|
||||||
exchanges,
|
vob: vob.map(([side, pairName]) => ({
|
||||||
vob: vob.map(([side, pairName]) => ({
|
side,
|
||||||
side,
|
pairName,
|
||||||
pairName,
|
})),
|
||||||
})),
|
});
|
||||||
},
|
|
||||||
];
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
this.subscriptions[
|
this.subscriptions[
|
||||||
SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE
|
SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE
|
||||||
@@ -391,13 +391,15 @@ class OrionAggregatorWS {
|
|||||||
break;
|
break;
|
||||||
case MessageType.ASSET_PAIRS_CONFIG_UPDATE: {
|
case MessageType.ASSET_PAIRS_CONFIG_UPDATE: {
|
||||||
const pairs = json;
|
const pairs = json;
|
||||||
const priceUpdates = pairs.u.reduce<Partial<Record<string, AssetPairUpdate>>>((acc, [pairName, minQty, pricePrecision]) => ({
|
let priceUpdates: Partial<Record<string, AssetPairUpdate>> = {};
|
||||||
...acc,
|
|
||||||
[pairName]: {
|
pairs.u.forEach(([pairName, minQty, pricePrecision]) => {
|
||||||
|
priceUpdates[pairName] = {
|
||||||
minQty,
|
minQty,
|
||||||
pricePrecision,
|
pricePrecision,
|
||||||
},
|
}
|
||||||
}), {});
|
});
|
||||||
|
|
||||||
this.subscriptions[
|
this.subscriptions[
|
||||||
SubscriptionType.ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE
|
SubscriptionType.ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE
|
||||||
]?.default?.callback({
|
]?.default?.callback({
|
||||||
@@ -412,12 +414,12 @@ class OrionAggregatorWS {
|
|||||||
.reduce<Partial<Record<string, Balance>>>((prev, [asset, assetBalances]) => {
|
.reduce<Partial<Record<string, Balance>>>((prev, [asset, assetBalances]) => {
|
||||||
if (!assetBalances) return prev;
|
if (!assetBalances) return prev;
|
||||||
const [tradable, reserved, contract, wallet, allowance] = assetBalances;
|
const [tradable, reserved, contract, wallet, allowance] = assetBalances;
|
||||||
return {
|
|
||||||
...prev,
|
prev[asset] = {
|
||||||
[asset]: {
|
tradable, reserved, contract, wallet, allowance,
|
||||||
tradable, reserved, contract, wallet, allowance,
|
}
|
||||||
},
|
|
||||||
};
|
return prev;
|
||||||
}, {})
|
}, {})
|
||||||
: {};
|
: {};
|
||||||
switch (json.k) { // message kind
|
switch (json.k) { // message kind
|
||||||
@@ -425,10 +427,10 @@ class OrionAggregatorWS {
|
|||||||
const fullOrders = json.o
|
const fullOrders = json.o
|
||||||
? json.o.reduce<FullOrder[]>((prev, o) => {
|
? json.o.reduce<FullOrder[]>((prev, o) => {
|
||||||
const fullOrder = mapFullOrder(o);
|
const fullOrder = mapFullOrder(o);
|
||||||
return [
|
|
||||||
...prev,
|
prev.push(fullOrder);
|
||||||
fullOrder,
|
|
||||||
];
|
return prev;
|
||||||
}, [])
|
}, [])
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
@@ -465,10 +467,11 @@ class OrionAggregatorWS {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MessageType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: {
|
case MessageType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATE: {
|
||||||
const brokerBalances = json.bb.reduce<Partial<Record<string, number>>>((acc, [asset, balance]) => ({
|
let brokerBalances: Partial<Record<string, number>> = {};
|
||||||
...acc,
|
|
||||||
[asset]: balance,
|
json.bb.forEach(([asset, balance]) => {
|
||||||
}), {});
|
brokerBalances[asset] = balance
|
||||||
|
});
|
||||||
|
|
||||||
this.subscriptions[
|
this.subscriptions[
|
||||||
SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE
|
SubscriptionType.BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE
|
||||||
|
|||||||
Reference in New Issue
Block a user