fix: insert buy side depth updates correctly (#775)
This commit is contained in:
parent
936f849cef
commit
5ddab41e18
@ -49,7 +49,8 @@ const updateLevels = (
|
|||||||
| MarketDepthSubscription_marketDepthUpdate_buy
|
| MarketDepthSubscription_marketDepthUpdate_buy
|
||||||
| MarketDepthSubscription_marketDepthUpdate_sell
|
| MarketDepthSubscription_marketDepthUpdate_sell
|
||||||
)[],
|
)[],
|
||||||
decimalPlaces: number
|
decimalPlaces: number,
|
||||||
|
reverse = false
|
||||||
) => {
|
) => {
|
||||||
updates.forEach((update) => {
|
updates.forEach((update) => {
|
||||||
const updateLevel = formatLevel(update, decimalPlaces);
|
const updateLevel = formatLevel(update, decimalPlaces);
|
||||||
@ -61,7 +62,11 @@ const updateLevels = (
|
|||||||
Object.assign(levels[index], updateLevel);
|
Object.assign(levels[index], updateLevel);
|
||||||
}
|
}
|
||||||
} else if (update.volume !== '0') {
|
} 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) {
|
if (index !== -1) {
|
||||||
levels.splice(index, 0, updateLevel);
|
levels.splice(index, 0, updateLevel);
|
||||||
} else {
|
} else {
|
||||||
@ -104,7 +109,8 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
|
|||||||
? updateLevels(
|
? updateLevels(
|
||||||
dataRef.current.data.buy,
|
dataRef.current.data.buy,
|
||||||
delta.buy,
|
delta.buy,
|
||||||
decimalPlacesRef.current
|
decimalPlacesRef.current,
|
||||||
|
true
|
||||||
)
|
)
|
||||||
: dataRef.current.data.buy,
|
: dataRef.current.data.buy,
|
||||||
sell: delta.sell
|
sell: delta.sell
|
||||||
|
Loading…
Reference in New Issue
Block a user