From 8e64b5293e45539cd195bf02421645e924143b55 Mon Sep 17 00:00:00 2001 From: gx578007 Date: Fri, 23 Jun 2023 21:30:32 +0800 Subject: [PATCH] MINOR: [grid2] delete order prices metric --- pkg/strategy/grid2/metrics.go | 15 ------------- pkg/strategy/grid2/recover.go | 1 - pkg/strategy/grid2/strategy.go | 41 ---------------------------------- 3 files changed, 57 deletions(-) diff --git a/pkg/strategy/grid2/metrics.go b/pkg/strategy/grid2/metrics.go index ed4f849cd..b72bb4b3f 100644 --- a/pkg/strategy/grid2/metrics.go +++ b/pkg/strategy/grid2/metrics.go @@ -10,7 +10,6 @@ var ( metricsGridNumOfOrdersWithCorrectPrice *prometheus.GaugeVec metricsGridNumOfMissingOrders *prometheus.GaugeVec metricsGridNumOfMissingOrdersWithCorrectPrice *prometheus.GaugeVec - metricsGridOrderPrices *prometheus.GaugeVec metricsGridProfit *prometheus.GaugeVec metricsGridUpperPrice *prometheus.GaugeVec @@ -102,19 +101,6 @@ func initMetrics(extendedLabels []string) { }, extendedLabels...), ) - metricsGridOrderPrices = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "bbgo_grid2_order_prices", - Help: "order prices", - }, - append([]string{ - "exchange", // exchange name - "symbol", // symbol of the market - "ith", - "side", - }, extendedLabels...), - ) - metricsGridProfit = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "bbgo_grid2_profit", @@ -202,7 +188,6 @@ func registerMetrics() { metricsGridNumOfMissingOrders, metricsGridNumOfMissingOrdersWithCorrectPrice, metricsGridProfit, - metricsGridOrderPrices, metricsGridLowerPrice, metricsGridUpperPrice, metricsGridQuoteInvestment, diff --git a/pkg/strategy/grid2/recover.go b/pkg/strategy/grid2/recover.go index d0ce99f70..d48eab1bb 100644 --- a/pkg/strategy/grid2/recover.go +++ b/pkg/strategy/grid2/recover.go @@ -16,7 +16,6 @@ import ( func (s *Strategy) recoverByScanningTrades(ctx context.Context, session *bbgo.ExchangeSession) error { defer func() { s.updateGridNumOfOrdersMetricsWithLock() - s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) }() historyService, implemented := session.Exchange.(types.ExchangeTradeHistoryService) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index e007369ce..044b3a5a4 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -894,7 +894,6 @@ func (s *Strategy) newOrderUpdateHandler(ctx context.Context, session *bbgo.Exch bbgo.Sync(ctx, s) s.updateGridNumOfOrdersMetricsWithLock() - s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) } } @@ -1170,7 +1169,6 @@ func (s *Strategy) openGrid(ctx context.Context, session *bbgo.ExchangeSession) s.logger.Infof("ALL GRID ORDERS SUBMITTED") s.updateGridNumOfOrdersMetrics(grid) - s.updateOpenOrderPricesMetrics(createdOrders) return nil } @@ -1219,41 +1217,6 @@ func (s *Strategy) updateGridNumOfOrdersMetrics(grid *Grid) { } } -func (s *Strategy) updateOpenOrderPricesMetrics(orders []types.Order) { - orders = sortOrdersByPriceAscending(orders) - num := len(orders) - s.deleteOpenOrderPricesMetrics() - for idx, order := range orders { - labels := s.newPrometheusLabels() - labels["side"] = order.Side.String() - labels["ith"] = strconv.Itoa(num - idx) - metricsGridOrderPrices.With(labels).Set(order.Price.Float64()) - } -} - -func (s *Strategy) deleteOpenOrderPricesMetrics() { - for i := 1; i <= int(s.GridNum); i++ { - ithStr := strconv.Itoa(i) - labels := s.newPrometheusLabels() - labels["side"] = "BUY" - labels["ith"] = ithStr - metricsGridOrderPrices.Delete(labels) - labels = s.newPrometheusLabels() - labels["side"] = "SELL" - labels["ith"] = ithStr - metricsGridOrderPrices.Delete(labels) - } -} - -func sortOrdersByPriceAscending(orders []types.Order) []types.Order { - sort.Slice(orders, func(i, j int) bool { - a := orders[i] - b := orders[j] - return a.Price.Compare(b.Price) < 0 - }) - return orders -} - func (s *Strategy) debugGridOrders(submitOrders []types.SubmitOrder, lastPrice fixedpoint.Value) { if !s.Debug { return @@ -1538,7 +1501,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService s.setGrid(grid) s.EmitGridReady() s.updateGridNumOfOrdersMetricsWithLock() - s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) return nil } else { s.logger.Infof("GRID RECOVER: found missing prices: %v", missingPrices) @@ -1585,7 +1547,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService s.setGrid(grid) s.EmitGridReady() s.updateGridNumOfOrdersMetricsWithLock() - s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) return nil } @@ -1612,7 +1573,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService s.setGrid(grid) s.EmitGridReady() s.updateGridNumOfOrdersMetricsWithLock() - s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) for i := range filledOrders { // avoid using the iterator @@ -1629,7 +1589,6 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService debugGrid(s.logger, grid, s.orderExecutor.ActiveMakerOrders()) s.updateGridNumOfOrdersMetricsWithLock() - s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) return nil }