Merge pull request #1207 from c9s/bhwu/grid2/delete-order-price-metrics

This commit is contained in:
c9s 2023-06-23 21:47:59 +08:00 committed by GitHub
commit 6741f8b22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 57 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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
}