From 5ddab41e18f3228153d240b8fb8154a8add1552c Mon Sep 17 00:00:00 2001 From: John Walley Date: Mon, 18 Jul 2022 14:17:56 +0100 Subject: [PATCH] fix: insert buy side depth updates correctly (#775) --- libs/market-depth/src/lib/depth-chart.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/market-depth/src/lib/depth-chart.tsx b/libs/market-depth/src/lib/depth-chart.tsx index 5868ebd61..74098064a 100644 --- a/libs/market-depth/src/lib/depth-chart.tsx +++ b/libs/market-depth/src/lib/depth-chart.tsx @@ -49,7 +49,8 @@ const updateLevels = ( | MarketDepthSubscription_marketDepthUpdate_buy | MarketDepthSubscription_marketDepthUpdate_sell )[], - decimalPlaces: number + decimalPlaces: number, + reverse = false ) => { updates.forEach((update) => { const updateLevel = formatLevel(update, decimalPlaces); @@ -61,7 +62,11 @@ const updateLevels = ( Object.assign(levels[index], updateLevel); } } else if (update.volume !== '0') { - index = levels.findIndex((level) => level.price > updateLevel.price); + index = levels.findIndex((level) => + reverse + ? level.price < updateLevel.price + : level.price > updateLevel.price + ); if (index !== -1) { levels.splice(index, 0, updateLevel); } else { @@ -104,7 +109,8 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => { ? updateLevels( dataRef.current.data.buy, delta.buy, - decimalPlacesRef.current + decimalPlacesRef.current, + true ) : dataRef.current.data.buy, sell: delta.sell