bbgo: fix active book order removal

This commit is contained in:
c9s 2022-01-10 12:29:19 +08:00
parent 3907f99e70
commit d57f8fedfe
2 changed files with 6 additions and 15 deletions

View File

@ -102,17 +102,9 @@ func (b *LocalActiveOrderBook) orderUpdateHandler(order types.Order) {
b.EmitFilled(order)
}
case types.OrderStatusPartiallyFilled:
case types.OrderStatusPartiallyFilled, types.OrderStatusNew:
b.Update(order)
case types.OrderStatusNew:
if order.Quantity == 0 {
log.Debugf("[LocalActiveOrderBook] order status %s, removing order %s", order.Status, order)
b.Remove(order)
} else {
b.Update(order)
}
case types.OrderStatusCanceled, types.OrderStatusRejected:
log.Debugf("[LocalActiveOrderBook] order status %s, removing order %s", order.Status, order)
b.Remove(order)

View File

@ -72,7 +72,7 @@ func (m OrderMap) Orders() (orders OrderSlice) {
}
type SyncOrderMap struct {
orders OrderMap
orders OrderMap
// pendingRemoval is for recording the order remove message for unknown orders.
// the order removal message might arrive before the order update, so if we found there is a pending removal,
@ -97,15 +97,14 @@ func (m *SyncOrderMap) Backup() (orders []SubmitOrder) {
}
func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
exists = m.Exists(orderID)
m.Lock()
defer m.Unlock()
exists = m.orders.Exists(orderID)
if exists {
m.Lock()
m.orders.Remove(orderID)
m.Unlock()
} else {
m.Lock()
m.pendingRemoval[orderID] = time.Now()
m.Unlock()
}
return exists