2023-01-10 12:15:51 +00:00
|
|
|
package grid2
|
|
|
|
|
2023-03-06 08:56:40 +00:00
|
|
|
import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
2023-01-10 12:15:51 +00:00
|
|
|
|
|
|
|
var (
|
2023-03-08 13:36:19 +00:00
|
|
|
metricsGridNum *prometheus.GaugeVec
|
|
|
|
metricsGridNumOfOrders *prometheus.GaugeVec
|
|
|
|
metricsGridNumOfOrdersWithCorrectPrice *prometheus.GaugeVec
|
|
|
|
metricsGridNumOfMissingOrders *prometheus.GaugeVec
|
|
|
|
metricsGridNumOfMissingOrdersWithCorrectPrice *prometheus.GaugeVec
|
|
|
|
metricsGridProfit *prometheus.GaugeVec
|
|
|
|
|
|
|
|
metricsGridUpperPrice *prometheus.GaugeVec
|
|
|
|
metricsGridLowerPrice *prometheus.GaugeVec
|
|
|
|
metricsGridQuoteInvestment *prometheus.GaugeVec
|
|
|
|
metricsGridBaseInvestment *prometheus.GaugeVec
|
|
|
|
|
|
|
|
metricsGridFilledOrderPrice *prometheus.GaugeVec
|
2023-10-11 09:36:18 +00:00
|
|
|
|
|
|
|
metricsNumOfOpenOrders *prometheus.GaugeVec
|
2023-01-10 12:15:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func labelKeys(labels prometheus.Labels) []string {
|
|
|
|
var keys []string
|
|
|
|
for k := range labels {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys
|
|
|
|
}
|
|
|
|
|
|
|
|
func mergeLabels(a, b prometheus.Labels) prometheus.Labels {
|
|
|
|
labels := prometheus.Labels{}
|
|
|
|
for k, v := range a {
|
|
|
|
labels[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range b {
|
|
|
|
labels[k] = v
|
|
|
|
}
|
|
|
|
return labels
|
|
|
|
}
|
|
|
|
|
|
|
|
func initMetrics(extendedLabels []string) {
|
2023-03-06 08:56:40 +00:00
|
|
|
if metricsGridNum != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-23 14:49:03 +00:00
|
|
|
metricsGridNum = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_num",
|
|
|
|
Help: "number of grids",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
2023-01-10 12:15:51 +00:00
|
|
|
metricsGridNumOfOrders = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_num_of_orders",
|
|
|
|
Help: "number of orders",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
2023-03-08 13:36:19 +00:00
|
|
|
metricsGridNumOfOrdersWithCorrectPrice = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_num_of_correct_price_orders",
|
|
|
|
Help: "number of orders with correct grid prices",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
2023-02-23 14:49:03 +00:00
|
|
|
metricsGridNumOfMissingOrders = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_num_of_missing_orders",
|
|
|
|
Help: "number of missing orders",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
2023-03-08 13:36:19 +00:00
|
|
|
metricsGridNumOfMissingOrdersWithCorrectPrice = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_num_of_missing_correct_price_orders",
|
|
|
|
Help: "number of missing orders with correct prices",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
2023-01-10 12:15:51 +00:00
|
|
|
metricsGridProfit = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2023-03-08 13:36:19 +00:00
|
|
|
Name: "bbgo_grid2_profit",
|
2023-01-10 12:15:51 +00:00
|
|
|
Help: "realized grid profit",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
2023-03-08 13:36:19 +00:00
|
|
|
|
|
|
|
metricsGridUpperPrice = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_upper_price",
|
|
|
|
Help: "the upper price of grid",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
|
|
|
metricsGridLowerPrice = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_lower_price",
|
|
|
|
Help: "the lower price of grid",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
|
|
|
metricsGridQuoteInvestment = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_quote_investment",
|
|
|
|
Help: "the quote investment of grid",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
|
|
|
metricsGridBaseInvestment = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_base_investment",
|
|
|
|
Help: "the base investment of grid",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
|
|
|
|
|
|
|
metricsGridFilledOrderPrice = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "bbgo_grid2_filled_order_price",
|
|
|
|
Help: "the price of filled grid order",
|
|
|
|
},
|
|
|
|
append([]string{
|
|
|
|
"exchange", // exchange name
|
|
|
|
"symbol", // symbol of the market
|
|
|
|
"side",
|
|
|
|
}, extendedLabels...),
|
|
|
|
)
|
2023-10-11 09:36:18 +00:00
|
|
|
|
|
|
|
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...),
|
|
|
|
)
|
|
|
|
|
2023-01-10 12:15:51 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 13:30:58 +00:00
|
|
|
var metricsRegistered = false
|
|
|
|
|
2023-01-10 12:15:51 +00:00
|
|
|
func registerMetrics() {
|
2023-01-31 13:30:58 +00:00
|
|
|
if metricsRegistered {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-23 16:44:50 +00:00
|
|
|
if metricsGridNum == nil {
|
|
|
|
// default setup
|
|
|
|
initMetrics(nil)
|
|
|
|
}
|
|
|
|
|
2023-01-10 12:15:51 +00:00
|
|
|
prometheus.MustRegister(
|
2023-02-23 14:49:03 +00:00
|
|
|
metricsGridNum,
|
2023-01-10 12:15:51 +00:00
|
|
|
metricsGridNumOfOrders,
|
2023-03-08 13:36:19 +00:00
|
|
|
metricsGridNumOfOrdersWithCorrectPrice,
|
2023-02-23 14:49:03 +00:00
|
|
|
metricsGridNumOfMissingOrders,
|
2023-03-08 13:36:19 +00:00
|
|
|
metricsGridNumOfMissingOrdersWithCorrectPrice,
|
2023-01-10 12:15:51 +00:00
|
|
|
metricsGridProfit,
|
2023-03-08 13:36:19 +00:00
|
|
|
metricsGridLowerPrice,
|
|
|
|
metricsGridUpperPrice,
|
|
|
|
metricsGridQuoteInvestment,
|
|
|
|
metricsGridBaseInvestment,
|
|
|
|
metricsGridFilledOrderPrice,
|
2023-10-11 09:36:18 +00:00
|
|
|
metricsNumOfOpenOrders,
|
2023-01-10 12:15:51 +00:00
|
|
|
)
|
2023-01-31 13:30:58 +00:00
|
|
|
metricsRegistered = true
|
2023-05-25 06:01:22 +00:00
|
|
|
}
|