fix: insert buy side depth updates correctly (#775)

This commit is contained in:
John Walley 2022-07-18 14:17:56 +01:00 committed by GitHub
parent 936f849cef
commit 5ddab41e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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