xmaker: add delayHedgeCounterMetrics counter

This commit is contained in:
c9s 2024-10-16 15:40:50 +08:00
parent 8fcd76cb59
commit e55676abab
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 22 additions and 7 deletions

View File

@ -2,6 +2,12 @@ package xmaker
import "github.com/prometheus/client_golang/prometheus"
var delayHedgeCounterMetrics = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "xmaker_delay_hedge_counter",
Help: "delay hedge counter",
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var cancelOrderDurationMetrics = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "xmaker_cancel_order_duration_milliseconds",
@ -97,5 +103,6 @@ func init() {
configMaxExposureMetrics,
configBidMarginMetrics,
configAskMarginMetrics,
delayHedgeCounterMetrics,
)
}

View File

@ -1174,14 +1174,22 @@ func (s *Strategy) canDelayHedge(side types.SideType, pos fixedpoint.Value) bool
signal := s.lastAggregatedSignal.Get()
if math.Abs(signal) < s.DelayHedgeSignalThreshold {
return false
}
// if the signal is strong enough, we can delay the hedge and wait for the next tick
if math.Abs(signal) > s.DelayHedgeSignalThreshold {
period, ok := s.getPositionHoldingPeriod(time.Now())
if ok && (signal > 0 && side == types.SideTypeSell) || (signal < 0 && side == types.SideTypeBuy) {
if period < s.MaxDelayHedgeDuration.Duration() {
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())
return true
}
period, ok := s.getPositionHoldingPeriod(time.Now())
if !ok {
return false
}
if (signal > 0 && side == types.SideTypeSell) || (signal < 0 && side == types.SideTypeBuy) {
if period < s.MaxDelayHedgeDuration.Duration() {
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())
delayHedgeCounterMetrics.With(s.metricsLabels).Inc()
return true
}
}