diff --git a/pkg/strategy/xmaker/metrics.go b/pkg/strategy/xmaker/metrics.go index bd898e184..c4acef245 100644 --- a/pkg/strategy/xmaker/metrics.go +++ b/pkg/strategy/xmaker/metrics.go @@ -2,12 +2,19 @@ package xmaker import "github.com/prometheus/client_golang/prometheus" -var delayHedgeCounterMetrics = prometheus.NewCounterVec( +var delayedHedgeCounterMetrics = prometheus.NewCounterVec( prometheus.CounterOpts{ - Name: "xmaker_delay_hedge_counter", + Name: "xmaker_delayed_hedge_counter", Help: "delay hedge counter", }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) +var delayedHedgeMaxDurationMetrics = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "xmaker_delayed_hedge_max_duration", + Help: "delay hedge max duration in milliseconds", + Buckets: prometheus.ExponentialBuckets(50, 2.0, 13), + }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) + var cancelOrderDurationMetrics = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "xmaker_cancel_order_duration_milliseconds", @@ -88,6 +95,13 @@ var configAskMarginMetrics = prometheus.NewGaugeVec( Help: "", }, []string{"strategy_type", "strategy_id", "symbol"}) +var netProfitMarginHistogram = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "xmaker_net_profit_margin", + Help: "net profit", + Buckets: prometheus.ExponentialBuckets(0.001, 2.0, 10), + }, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) + func init() { prometheus.MustRegister( openOrderBidExposureInUsdMetrics, @@ -103,6 +117,8 @@ func init() { configMaxExposureMetrics, configBidMarginMetrics, configAskMarginMetrics, - delayHedgeCounterMetrics, + delayedHedgeCounterMetrics, + delayedHedgeMaxDurationMetrics, + netProfitMarginHistogram, ) } diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 86d9e0e6c..c1f41db9b 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -1331,9 +1331,10 @@ func (s *Strategy) canDelayHedge(hedgeSide types.SideType, pos fixedpoint.Value) if (signal > 0 && hedgeSide == types.SideTypeSell) || (signal < 0 && hedgeSide == types.SideTypeBuy) { if period < delay { - s.logger.Infof("delay hedge enabled, signal %f is strong enough, waiting for the next tick to hedge %s quantity (max period %s)", signal, pos, s.MaxDelayHedgeDuration.Duration().String()) + s.logger.Infof("delay hedge enabled, signal %f is strong enough, waiting for the next tick to hedge %s quantity (max delay %s)", signal, pos, delay) - delayHedgeCounterMetrics.With(s.metricsLabels).Inc() + delayedHedgeCounterMetrics.With(s.metricsLabels).Inc() + delayedHedgeMaxDurationMetrics.With(s.metricsLabels).Observe(float64(delay.Milliseconds())) return true } } @@ -2011,6 +2012,8 @@ func (s *Strategy) CrossRun( bbgo.Notify(profit) + netProfitMarginHistogram.With(s.metricsLabels).Observe(profit.NetProfitMargin.Float64()) + s.ProfitStats.AddProfit(*profit) s.Environment.RecordPosition(s.Position, trade, profit) }