Skip to content

Commit 9d053ab

Browse files
author
Evgeniya Tsybrenko
committed
DEX-849 fixed orderbook bug
1 parent 4d66837 commit 9d053ab

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

dex/src/main/scala/com/wavesplatform/dex/api/ws/state/WsOrderBookState.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,21 @@ case class WsOrderBookState(
8686

8787
def updatePrevTickState(asks: Map[Price, Amount], bids: Map[Price, Amount], lt: Option[LastTrade], lc: Option[Double]): WsState =
8888
prevTickState.copy(
89-
asks = applyLevelChanges(prevTickState.asks, asks),
90-
bids = applyLevelChanges(prevTickState.bids, bids),
89+
asks = (prevTickState.asks ++ asks).filter(_._2 != 0),
90+
bids = (prevTickState.bids ++ bids).filter(_._2 != 0),
9191
lastTrade = if (lt.isEmpty) prevTickState.lastTrade else lt,
9292
tickSize = if (lc.isEmpty) prevTickState.tickSize else lc
9393
)
9494

95-
def applyLevelChanges(m1: TreeMap[Price, Amount], m2: Map[Price, Amount]): TreeMap[Price, Amount] = (m1 ++ m2.map {
95+
def updatePrevTickStateFromDiff(asks: Map[Price, Amount], bids: Map[Price, Amount], lt: Option[LastTrade], lc: Option[Double]): WsState =
96+
prevTickState.copy(
97+
asks = applyLevelDiff(prevTickState.asks, asks),
98+
bids = applyLevelDiff(prevTickState.bids, bids),
99+
lastTrade = if (lt.isEmpty) prevTickState.lastTrade else lt,
100+
tickSize = if (lc.isEmpty) prevTickState.tickSize else lc
101+
)
102+
103+
def applyLevelDiff(m1: TreeMap[Price, Amount], m2: Map[Price, Amount]): TreeMap[Price, Amount] = (m1 ++ m2.map {
96104
case (pr, am) =>
97105
(pr, m1.get(pr).fold(am)(_ + am))
98106
}).filter(_._2 != 0)
@@ -123,7 +131,7 @@ case class WsOrderBookState(
123131
)(this)
124132
else
125133
copy(
126-
prevTickState = updatePrevTickState(lc.asks, lc.bids, lt, ts)
134+
prevTickState = updatePrevTickStateFromDiff(lc.asks, lc.bids, lt, ts)
127135
)
128136

129137
}

0 commit comments

Comments
 (0)