grid2: add the missing metrics update

This commit is contained in:
c9s 2023-02-23 22:39:47 +08:00
parent f453a22972
commit 5e2add8765
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -434,6 +434,9 @@ func (s *Strategy) processFilledOrder(o types.Order) {
} else {
s.logger.Infof("GRID REVERSE ORDER IS CREATED: %+v", createdOrders)
}
s.updateGridNumOfOrdersMetrics()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
}
// handleOrderFilled is called when an order status is FILLED
@ -732,8 +735,6 @@ func (s *Strategy) newOrderUpdateHandler(ctx context.Context, session *bbgo.Exch
return func(o types.Order) {
s.handleOrderFilled(o)
bbgo.Sync(ctx, s)
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
}
}
@ -809,6 +810,7 @@ func (s *Strategy) CloseGrid(ctx context.Context) error {
// free the grid object
s.setGrid(nil)
s.updateGridNumOfOrdersMetrics()
return nil
}
@ -947,6 +949,11 @@ func (s *Strategy) openGrid(ctx context.Context, session *bbgo.ExchangeSession)
return nil
}
func (s *Strategy) updateGridNumOfOrdersMetrics() {
baseLabels := s.newPrometheusLabels()
metricsGridNumOfOrders.With(baseLabels).Set(float64(s.orderExecutor.ActiveMakerOrders().NumOfOrders()))
}
func (s *Strategy) updateOpenOrderPricesMetrics(orders []types.Order) {
orders = sortOrdersByPriceAscending(orders)
num := len(orders)
@ -1273,6 +1280,9 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
s.logger.Infof("GRID RECOVER COMPLETE")
debugGrid(s.logger, grid, s.orderExecutor.ActiveMakerOrders())
s.updateGridNumOfOrdersMetrics()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
return nil
}
@ -1614,7 +1624,6 @@ func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSessio
return errors.Wrap(err, "recover grid error")
}
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
return nil
}