From 2669c3a5dbf59bb7fdd3490ff467413472ff274b Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 17 Aug 2023 16:28:42 +0800 Subject: [PATCH] bbgo: check order exists --- pkg/bbgo/activeorderbook.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/bbgo/activeorderbook.go b/pkg/bbgo/activeorderbook.go index fbd391a8d..104c9f349 100644 --- a/pkg/bbgo/activeorderbook.go +++ b/pkg/bbgo/activeorderbook.go @@ -233,17 +233,6 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange, } 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) } @@ -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 the order is cancelled, it will be removed from the internal order storage. 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 { case types.OrderStatusFilled: // make sure we have the order and we remove it