bbgo: add mutli symbol support to active order book

This commit is contained in:
c9s 2022-08-04 21:12:58 +08:00
parent f9fe5d7790
commit cae8bc2882
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -105,13 +105,22 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange)
// verify the current open orders via the RESTful API // verify the current open orders via the RESTful API
log.Warnf("[ActiveOrderBook] using REStful API to verify active orders...") log.Warnf("[ActiveOrderBook] using REStful API to verify active orders...")
openOrders, err := ex.QueryOpenOrders(ctx, b.Symbol)
orders = b.Orders()
var symbols = map[string]struct{}{}
for _, order := range orders {
symbols[order.Symbol] = struct{}{}
}
for symbol := range symbols {
openOrders, err := ex.QueryOpenOrders(ctx, symbol)
if err != nil { if err != nil {
log.WithError(err).Errorf("can not query %s open orders", b.Symbol) log.WithError(err).Errorf("can not query %s open orders", symbol)
continue continue
} }
openOrderStore := NewOrderStore(b.Symbol) openOrderStore := NewOrderStore(symbol)
openOrderStore.Add(openOrders...) openOrderStore.Add(openOrders...)
for _, o := range orders { for _, o := range orders {
// if it's not on the order book (open orders), we should remove it from our local side // if it's not on the order book (open orders), we should remove it from our local side
@ -120,6 +129,7 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange)
} }
} }
} }
}
log.Debugf("[ActiveOrderBook] all %s orders are cancelled successfully in %s", b.Symbol, time.Since(startTime)) log.Debugf("[ActiveOrderBook] all %s orders are cancelled successfully in %s", b.Symbol, time.Since(startTime))
return nil return nil