From 4ae8ad77b357eb681bd6102ca0658b7a09cfe9ec Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 27 Aug 2024 15:53:48 +0800 Subject: [PATCH] xmaker: add profit changed flag for notification --- pkg/strategy/xmaker/strategy.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index ba279cfd3..9f434c7c1 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -750,7 +750,7 @@ func (s *Strategy) Defaults() error { // circuitBreakerAlertLimiter is for CircuitBreaker alerts 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(3*time.Minute), 1) s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1) return nil } @@ -803,6 +803,9 @@ func (s *Strategy) hedgeWorker(ctx context.Context) { ticker := time.NewTicker(util.MillisecondsJitter(s.HedgeInterval.Duration(), 200)) defer ticker.Stop() + profitChanged := false + reportTicker := time.NewTicker(5 * time.Minute) + for { select { case <-ctx.Done(): @@ -836,8 +839,15 @@ func (s *Strategy) hedgeWorker(ctx context.Context) { s.Hedge(ctx, uncoverPosition.Neg()) } - if s.reportProfitStatsRateLimiter.Allow() { - bbgo.Notify(s.ProfitStats) + profitChanged = true + + case <-reportTicker.C: + if profitChanged { + if s.reportProfitStatsRateLimiter.Allow() { + bbgo.Notify(s.ProfitStats) + } + + profitChanged = false } } }