book: handle volume == 0

This commit is contained in:
c9s 2020-10-02 21:18:50 +08:00
parent d29725119f
commit 26674effa1

View File

@ -103,13 +103,21 @@ type OrderBook struct {
func (b *OrderBook) UpdateAsks(pvs PriceVolumePairSlice) {
for _, pv := range pvs {
b.Asks.UpdateOrInsert(pv, false)
if pv.Volume == 0 {
b.Asks.RemoveByPrice(pv.Price, false)
} else {
b.Asks.UpdateOrInsert(pv, false)
}
}
}
func (b *OrderBook) UpdateBids(pvs PriceVolumePairSlice) {
for _, pv := range pvs {
b.Bids.UpdateOrInsert(pv, true)
if pv.Volume == 0 {
b.Bids.RemoveByPrice(pv.Price, true)
} else {
b.Bids.UpdateOrInsert(pv, true)
}
}
}