From cae8bc2882dafa87a6781e6bb5d79d57726063a5 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 4 Aug 2022 21:12:58 +0800 Subject: [PATCH] bbgo: add mutli symbol support to active order book --- pkg/bbgo/activeorderbook.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pkg/bbgo/activeorderbook.go b/pkg/bbgo/activeorderbook.go index ba13b6293..75d28ecc7 100644 --- a/pkg/bbgo/activeorderbook.go +++ b/pkg/bbgo/activeorderbook.go @@ -105,18 +105,28 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange) // verify the current open orders via the RESTful API log.Warnf("[ActiveOrderBook] using REStful API to verify active orders...") - openOrders, err := ex.QueryOpenOrders(ctx, b.Symbol) - if err != nil { - log.WithError(err).Errorf("can not query %s open orders", b.Symbol) - continue + + orders = b.Orders() + var symbols = map[string]struct{}{} + for _, order := range orders { + symbols[order.Symbol] = struct{}{} + } - openOrderStore := NewOrderStore(b.Symbol) - openOrderStore.Add(openOrders...) - for _, o := range orders { - // if it's not on the order book (open orders), we should remove it from our local side - if !openOrderStore.Exists(o.OrderID) { - b.Remove(o) + for symbol := range symbols { + openOrders, err := ex.QueryOpenOrders(ctx, symbol) + if err != nil { + log.WithError(err).Errorf("can not query %s open orders", symbol) + continue + } + + openOrderStore := NewOrderStore(symbol) + openOrderStore.Add(openOrders...) + for _, o := range orders { + // if it's not on the order book (open orders), we should remove it from our local side + if !openOrderStore.Exists(o.OrderID) { + b.Remove(o) + } } } }