grid2: fix metrics for tests

This commit is contained in:
c9s 2023-02-24 00:44:50 +08:00
parent d89d0cf0ff
commit 59ff86e4bb
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 18 additions and 4 deletions

View File

@ -3,8 +3,8 @@ package grid2
import "github.com/prometheus/client_golang/prometheus"
var (
metricsGridNumOfOrders *prometheus.GaugeVec
metricsGridNum *prometheus.GaugeVec
metricsGridNumOfOrders *prometheus.GaugeVec
metricsGridNumOfMissingOrders *prometheus.GaugeVec
metricsGridOrderPrices *prometheus.GaugeVec
metricsGridProfit *prometheus.GaugeVec
@ -97,6 +97,11 @@ func registerMetrics() {
return
}
if metricsGridNum == nil {
// default setup
initMetrics(nil)
}
prometheus.MustRegister(
metricsGridNum,
metricsGridNumOfOrders,

View File

@ -435,8 +435,6 @@ func (s *Strategy) processFilledOrder(o types.Order) {
s.logger.Infof("GRID REVERSE ORDER IS CREATED: %+v", createdOrders)
}
s.updateGridNumOfOrdersMetrics()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
}
// handleOrderFilled is called when an order status is FILLED
@ -735,6 +733,9 @@ func (s *Strategy) newOrderUpdateHandler(ctx context.Context, session *bbgo.Exch
return func(o types.Order) {
s.handleOrderFilled(o)
bbgo.Sync(ctx, s)
s.updateGridNumOfOrdersMetrics()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
}
}
@ -1439,10 +1440,14 @@ func scanMissingPinPrices(orderBook *bbgo.ActiveOrderBook, pins []Pin) PriceMap
func (s *Strategy) newPrometheusLabels() prometheus.Labels {
labels := prometheus.Labels{
"exchange": s.session.Name,
"exchange": "default",
"symbol": s.Symbol,
}
if s.session != nil {
labels["exchange"] = s.session.Name
}
if s.PrometheusLabels == nil {
return labels
}

View File

@ -20,6 +20,10 @@ import (
gridmocks "github.com/c9s/bbgo/pkg/strategy/grid2/mocks"
)
func init() {
registerMetrics()
}
func TestStrategy_checkRequiredInvestmentByQuantity(t *testing.T) {
s := &Strategy{
logger: logrus.NewEntry(logrus.New()),