mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: fix metrics for tests
This commit is contained in:
parent
d89d0cf0ff
commit
59ff86e4bb
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
|
|
Loading…
Reference in New Issue
Block a user