add open orders metrics

This commit is contained in:
chiahung 2023-10-11 17:36:18 +08:00
parent c6d4ebf57b
commit 136c2cd36f
2 changed files with 17 additions and 0 deletions

View File

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

View File

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