mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
bbgo: fix active book order removal
This commit is contained in:
parent
3907f99e70
commit
d57f8fedfe
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user