From 7e65aca62ee988e5a29f49e32ccc06accf4aa6ef Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 27 Aug 2024 15:22:06 +0800 Subject: [PATCH] xmaker: add more config metrics --- pkg/strategy/xmaker/metrics.go | 15 +++++++++++---- pkg/strategy/xmaker/strategy.go | 17 +++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/strategy/xmaker/metrics.go b/pkg/strategy/xmaker/metrics.go index b61c6fc85..960a285ff 100644 --- a/pkg/strategy/xmaker/metrics.go +++ b/pkg/strategy/xmaker/metrics.go @@ -26,11 +26,17 @@ var makerBestAskPriceMetrics = prometheus.NewGaugeVec( Help: "", }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) -var numOfLayersMetrics = prometheus.NewGaugeVec( +var configNumOfLayersMetrics = prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Name: "xmaker_num_of_layers", + Name: "xmaker_config_num_of_layers", Help: "", - }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) + }, []string{"strategy_type", "strategy_id", "symbol"}) + +var configMaxExposureMetrics = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "xmaker_config_max_exposure", + Help: "", + }, []string{"strategy_type", "strategy_id", "symbol"}) func init() { prometheus.MustRegister( @@ -38,6 +44,7 @@ func init() { openOrderAskExposureInUsdMetrics, makerBestBidPriceMetrics, makerBestAskPriceMetrics, - numOfLayersMetrics, + configNumOfLayersMetrics, + configMaxExposureMetrics, ) } diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 91c21bcfd..65036dca3 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -753,6 +753,7 @@ func (s *Strategy) Defaults() error { // circuitBreakerAlertLimiter is for CircuitBreaker alerts s.circuitBreakerAlertLimiter = rate.NewLimiter(rate.Every(3*time.Minute), 2) s.reportProfitStatsRateLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1) + s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1) return nil } @@ -773,8 +774,8 @@ func (s *Strategy) Validate() error { } func (s *Strategy) quoteWorker(ctx context.Context) { - quoteTicker := time.NewTicker(util.MillisecondsJitter(s.UpdateInterval.Duration(), 200)) - defer quoteTicker.Stop() + ticker := time.NewTicker(util.MillisecondsJitter(s.UpdateInterval.Duration(), 200)) + defer ticker.Stop() defer func() { if err := s.activeMakerOrders.GracefulCancel(context.Background(), s.makerSession.Exchange); err != nil { @@ -793,7 +794,7 @@ func (s *Strategy) quoteWorker(ctx context.Context) { log.Warnf("%s maker goroutine stopped, due to the cancelled context", s.Symbol) return - case <-quoteTicker.C: + case <-ticker.C: s.updateQuote(ctx) } @@ -848,7 +849,7 @@ func (s *Strategy) CrossRun( ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession, ) error { - s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1) + instanceID := s.InstanceID() // configure sessions sourceSession, ok := sessions[s.SourceExchange] @@ -880,9 +881,6 @@ func (s *Strategy) CrossRun( } indicators := s.sourceSession.Indicators(s.Symbol) - if !ok { - return fmt.Errorf("%s standard indicator set not found", s.Symbol) - } s.boll = indicators.BOLL(types.IntervalWindow{ Interval: s.BollBandInterval, @@ -890,10 +888,13 @@ func (s *Strategy) CrossRun( }, 1.0) // restore state - instanceID := s.InstanceID() s.groupID = util.FNV32(instanceID) log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID) + configLabels := prometheus.Labels{"strategy_id": s.InstanceID(), "strategy_type": ID, "symbol": s.Symbol} + configNumOfLayersMetrics.With(configLabels).Set(float64(s.NumLayers)) + configMaxExposureMetrics.With(configLabels).Set(s.MaxExposurePosition.Float64()) + if s.Position == nil { s.Position = types.NewPositionFromMarket(s.makerMarket) s.Position.Strategy = ID