mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 09:15:15 +00:00
xmaker: add metrics for delayed hedge
This commit is contained in:
parent
55e9910441
commit
8dbf6d5ea6
|
@ -2,12 +2,19 @@ package xmaker
|
||||||
|
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
import "github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
var delayHedgeCounterMetrics = prometheus.NewCounterVec(
|
var delayedHedgeCounterMetrics = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "xmaker_delay_hedge_counter",
|
Name: "xmaker_delayed_hedge_counter",
|
||||||
Help: "delay hedge counter",
|
Help: "delay hedge counter",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []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(
|
var cancelOrderDurationMetrics = prometheus.NewHistogramVec(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
Name: "xmaker_cancel_order_duration_milliseconds",
|
Name: "xmaker_cancel_order_duration_milliseconds",
|
||||||
|
@ -88,6 +95,13 @@ var configAskMarginMetrics = prometheus.NewGaugeVec(
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "symbol"})
|
}, []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() {
|
func init() {
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
openOrderBidExposureInUsdMetrics,
|
openOrderBidExposureInUsdMetrics,
|
||||||
|
@ -103,6 +117,8 @@ func init() {
|
||||||
configMaxExposureMetrics,
|
configMaxExposureMetrics,
|
||||||
configBidMarginMetrics,
|
configBidMarginMetrics,
|
||||||
configAskMarginMetrics,
|
configAskMarginMetrics,
|
||||||
delayHedgeCounterMetrics,
|
delayedHedgeCounterMetrics,
|
||||||
|
delayedHedgeMaxDurationMetrics,
|
||||||
|
netProfitMarginHistogram,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 (signal > 0 && hedgeSide == types.SideTypeSell) || (signal < 0 && hedgeSide == types.SideTypeBuy) {
|
||||||
if period < delay {
|
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
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2011,6 +2012,8 @@ func (s *Strategy) CrossRun(
|
||||||
|
|
||||||
bbgo.Notify(profit)
|
bbgo.Notify(profit)
|
||||||
|
|
||||||
|
netProfitMarginHistogram.With(s.metricsLabels).Observe(profit.NetProfitMargin.Float64())
|
||||||
|
|
||||||
s.ProfitStats.AddProfit(*profit)
|
s.ProfitStats.AddProfit(*profit)
|
||||||
s.Environment.RecordPosition(s.Position, trade, profit)
|
s.Environment.RecordPosition(s.Position, trade, profit)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user