mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 19:13:52 +00:00
xmaker: add delayHedgeCounterMetrics counter
This commit is contained in:
parent
8fcd76cb59
commit
e55676abab
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user