grid2: update metrics after recovering the grid orders

This commit is contained in:
c9s 2023-02-23 11:19:10 +08:00
parent 4b4af5a09c
commit 31c9ebf34b
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -1578,6 +1578,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
if err := s.recoverGrid(ctx, session); err != nil {
log.WithError(err).Errorf("recover error")
}
}
if err := s.openGrid(ctx, session); err != nil {
@ -1596,22 +1597,24 @@ func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSessio
return err
}
s.logger.Infof("found %d open orders left on the %s order book", len(openOrders), s.Symbol)
// do recover only when openOrders > 0
if len(openOrders) > 0 {
historyService, implemented := session.Exchange.(types.ExchangeTradeHistoryService)
if !implemented {
s.logger.Warn("ExchangeTradeHistoryService is not implemented, can not recover grid")
return nil
}
if err := s.recoverGridWithOpenOrders(ctx, historyService, openOrders); err != nil {
return errors.Wrap(err, "recover grid error")
}
if len(openOrders) == 0 {
return nil
}
return nil
s.logger.Infof("found %d open orders left on the %s order book", len(openOrders), s.Symbol)
historyService, implemented := session.Exchange.(types.ExchangeTradeHistoryService)
if !implemented {
s.logger.Warn("ExchangeTradeHistoryService is not implemented, can not recover grid")
return nil
}
if err := s.recoverGridWithOpenOrders(ctx, historyService, openOrders); err != nil {
return errors.Wrap(err, "recover grid error")
}
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
}
// openOrdersMismatches verifies if the open orders are on the grid pins