mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
xmaker: add more config metrics
This commit is contained in:
parent
199b86df86
commit
7e65aca62e
|
@ -26,11 +26,17 @@ var makerBestAskPriceMetrics = prometheus.NewGaugeVec(
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
||||||
|
|
||||||
var numOfLayersMetrics = prometheus.NewGaugeVec(
|
var configNumOfLayersMetrics = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "xmaker_num_of_layers",
|
Name: "xmaker_config_num_of_layers",
|
||||||
Help: "",
|
Help: "",
|
||||||
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
|
}, []string{"strategy_type", "strategy_id", "symbol"})
|
||||||
|
|
||||||
|
var configMaxExposureMetrics = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "xmaker_config_max_exposure",
|
||||||
|
Help: "",
|
||||||
|
}, []string{"strategy_type", "strategy_id", "symbol"})
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
|
@ -38,6 +44,7 @@ func init() {
|
||||||
openOrderAskExposureInUsdMetrics,
|
openOrderAskExposureInUsdMetrics,
|
||||||
makerBestBidPriceMetrics,
|
makerBestBidPriceMetrics,
|
||||||
makerBestAskPriceMetrics,
|
makerBestAskPriceMetrics,
|
||||||
numOfLayersMetrics,
|
configNumOfLayersMetrics,
|
||||||
|
configMaxExposureMetrics,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -753,6 +753,7 @@ func (s *Strategy) Defaults() error {
|
||||||
// circuitBreakerAlertLimiter is for CircuitBreaker alerts
|
// circuitBreakerAlertLimiter is for CircuitBreaker alerts
|
||||||
s.circuitBreakerAlertLimiter = rate.NewLimiter(rate.Every(3*time.Minute), 2)
|
s.circuitBreakerAlertLimiter = rate.NewLimiter(rate.Every(3*time.Minute), 2)
|
||||||
s.reportProfitStatsRateLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1)
|
s.reportProfitStatsRateLimiter = rate.NewLimiter(rate.Every(5*time.Minute), 1)
|
||||||
|
s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,8 +774,8 @@ func (s *Strategy) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) quoteWorker(ctx context.Context) {
|
func (s *Strategy) quoteWorker(ctx context.Context) {
|
||||||
quoteTicker := time.NewTicker(util.MillisecondsJitter(s.UpdateInterval.Duration(), 200))
|
ticker := time.NewTicker(util.MillisecondsJitter(s.UpdateInterval.Duration(), 200))
|
||||||
defer quoteTicker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := s.activeMakerOrders.GracefulCancel(context.Background(), s.makerSession.Exchange); err != nil {
|
if err := s.activeMakerOrders.GracefulCancel(context.Background(), s.makerSession.Exchange); err != nil {
|
||||||
|
@ -793,7 +794,7 @@ func (s *Strategy) quoteWorker(ctx context.Context) {
|
||||||
log.Warnf("%s maker goroutine stopped, due to the cancelled context", s.Symbol)
|
log.Warnf("%s maker goroutine stopped, due to the cancelled context", s.Symbol)
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-quoteTicker.C:
|
case <-ticker.C:
|
||||||
s.updateQuote(ctx)
|
s.updateQuote(ctx)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -848,7 +849,7 @@ func (s *Strategy) CrossRun(
|
||||||
ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession,
|
ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession,
|
||||||
) error {
|
) error {
|
||||||
|
|
||||||
s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1)
|
instanceID := s.InstanceID()
|
||||||
|
|
||||||
// configure sessions
|
// configure sessions
|
||||||
sourceSession, ok := sessions[s.SourceExchange]
|
sourceSession, ok := sessions[s.SourceExchange]
|
||||||
|
@ -880,9 +881,6 @@ func (s *Strategy) CrossRun(
|
||||||
}
|
}
|
||||||
|
|
||||||
indicators := s.sourceSession.Indicators(s.Symbol)
|
indicators := s.sourceSession.Indicators(s.Symbol)
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("%s standard indicator set not found", s.Symbol)
|
|
||||||
}
|
|
||||||
|
|
||||||
s.boll = indicators.BOLL(types.IntervalWindow{
|
s.boll = indicators.BOLL(types.IntervalWindow{
|
||||||
Interval: s.BollBandInterval,
|
Interval: s.BollBandInterval,
|
||||||
|
@ -890,10 +888,13 @@ func (s *Strategy) CrossRun(
|
||||||
}, 1.0)
|
}, 1.0)
|
||||||
|
|
||||||
// restore state
|
// restore state
|
||||||
instanceID := s.InstanceID()
|
|
||||||
s.groupID = util.FNV32(instanceID)
|
s.groupID = util.FNV32(instanceID)
|
||||||
log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID)
|
log.Infof("using group id %d from fnv(%s)", s.groupID, instanceID)
|
||||||
|
|
||||||
|
configLabels := prometheus.Labels{"strategy_id": s.InstanceID(), "strategy_type": ID, "symbol": s.Symbol}
|
||||||
|
configNumOfLayersMetrics.With(configLabels).Set(float64(s.NumLayers))
|
||||||
|
configMaxExposureMetrics.With(configLabels).Set(s.MaxExposurePosition.Float64())
|
||||||
|
|
||||||
if s.Position == nil {
|
if s.Position == nil {
|
||||||
s.Position = types.NewPositionFromMarket(s.makerMarket)
|
s.Position = types.NewPositionFromMarket(s.makerMarket)
|
||||||
s.Position.Strategy = ID
|
s.Position.Strategy = ID
|
||||||
|
|
Loading…
Reference in New Issue
Block a user