From 136c2cd36f18a35609902dd9502c1d09bc647121 Mon Sep 17 00:00:00 2001 From: chiahung Date: Wed, 11 Oct 2023 17:36:18 +0800 Subject: [PATCH] add open orders metrics --- pkg/strategy/grid2/active_order_recover.go | 2 ++ pkg/strategy/grid2/metrics.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/strategy/grid2/active_order_recover.go b/pkg/strategy/grid2/active_order_recover.go index 2b3168960..fd1a8d648 100644 --- a/pkg/strategy/grid2/active_order_recover.go +++ b/pkg/strategy/grid2/active_order_recover.go @@ -61,6 +61,8 @@ func (s *Strategy) syncActiveOrders(ctx context.Context) error { return err } + metricsNumOfOpenOrders.With(s.newPrometheusLabels()).Set(float64(len(openOrders))) + // open orders query time + 1 min means this open orders may be changed ! openOrdersExpiredTime := time.Now().Add(1 * time.Minute) diff --git a/pkg/strategy/grid2/metrics.go b/pkg/strategy/grid2/metrics.go index b72bb4b3f..747164201 100644 --- a/pkg/strategy/grid2/metrics.go +++ b/pkg/strategy/grid2/metrics.go @@ -18,6 +18,8 @@ var ( metricsGridBaseInvestment *prometheus.GaugeVec metricsGridFilledOrderPrice *prometheus.GaugeVec + + metricsNumOfOpenOrders *prometheus.GaugeVec ) func labelKeys(labels prometheus.Labels) []string { @@ -167,6 +169,18 @@ func initMetrics(extendedLabels []string) { "side", }, extendedLabels...), ) + + metricsNumOfOpenOrders = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "bbgo_grid2_num_of_open_orders", + Help: "number of open orders", + }, + append([]string{ + "exchange", // exchange name + "symbol", // symbol of the market + }, extendedLabels...), + ) + } var metricsRegistered = false @@ -193,6 +207,7 @@ func registerMetrics() { metricsGridQuoteInvestment, metricsGridBaseInvestment, metricsGridFilledOrderPrice, + metricsNumOfOpenOrders, ) metricsRegistered = true }