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) b.EmitFilled(order)
} }
case types.OrderStatusPartiallyFilled: case types.OrderStatusPartiallyFilled, types.OrderStatusNew:
b.Update(order) 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: case types.OrderStatusCanceled, types.OrderStatusRejected:
log.Debugf("[LocalActiveOrderBook] order status %s, removing order %s", order.Status, order) log.Debugf("[LocalActiveOrderBook] order status %s, removing order %s", order.Status, order)
b.Remove(order) b.Remove(order)

View File

@ -97,15 +97,14 @@ func (m *SyncOrderMap) Backup() (orders []SubmitOrder) {
} }
func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) { func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
exists = m.Exists(orderID) m.Lock()
defer m.Unlock()
exists = m.orders.Exists(orderID)
if exists { if exists {
m.Lock()
m.orders.Remove(orderID) m.orders.Remove(orderID)
m.Unlock()
} else { } else {
m.Lock()
m.pendingRemoval[orderID] = time.Now() m.pendingRemoval[orderID] = time.Now()
m.Unlock()
} }
return exists return exists