bbgo: check order exists

This commit is contained in:
c9s 2023-08-17 16:28:42 +08:00
parent dda3f25c61
commit 2669c3a5db
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -233,17 +233,6 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
} }
func (b *ActiveOrderBook) orderUpdateHandler(order types.Order) { func (b *ActiveOrderBook) orderUpdateHandler(order types.Order) {
hasSymbol := len(b.Symbol) > 0
if hasSymbol && order.Symbol != b.Symbol {
return
}
if !b.orders.Exists(order.OrderID) {
b.pendingOrderUpdates.Add(order)
return
}
b.Update(order) b.Update(order)
} }
@ -279,6 +268,17 @@ func (b *ActiveOrderBook) update(orders ...types.Order) {
// When order is New or PartiallyFilled, the internal order will be updated according to the latest order update. // When order is New or PartiallyFilled, the internal order will be updated according to the latest order update.
// When the order is cancelled, it will be removed from the internal order storage. // When the order is cancelled, it will be removed from the internal order storage.
func (b *ActiveOrderBook) Update(order types.Order) { func (b *ActiveOrderBook) Update(order types.Order) {
hasSymbol := len(b.Symbol) > 0
if hasSymbol && order.Symbol != b.Symbol {
return
}
if !b.orders.Exists(order.OrderID) {
b.pendingOrderUpdates.Add(order)
return
}
switch order.Status { switch order.Status {
case types.OrderStatusFilled: case types.OrderStatusFilled:
// make sure we have the order and we remove it // make sure we have the order and we remove it