xmaker: add metrics for delayed hedge
Some checks are pending
Go / build (1.21, 6.2) (push) Waiting to run
golang-lint / lint (push) Waiting to run

This commit is contained in:
c9s 2024-11-22 17:26:17 +08:00
parent 55e9910441
commit 8dbf6d5ea6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 24 additions and 5 deletions

View File

@ -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,
)
}

View File

@ -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)
}