mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
xmaker: add profit changed flag for notification
This commit is contained in:
parent
3819feacf3
commit
4ae8ad77b3
|
@ -750,7 +750,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(3*time.Minute), 1)
|
||||||
s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1)
|
s.hedgeErrorLimiter = rate.NewLimiter(rate.Every(1*time.Minute), 1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -803,6 +803,9 @@ func (s *Strategy) hedgeWorker(ctx context.Context) {
|
||||||
ticker := time.NewTicker(util.MillisecondsJitter(s.HedgeInterval.Duration(), 200))
|
ticker := time.NewTicker(util.MillisecondsJitter(s.HedgeInterval.Duration(), 200))
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
profitChanged := false
|
||||||
|
reportTicker := time.NewTicker(5 * time.Minute)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -836,9 +839,16 @@ func (s *Strategy) hedgeWorker(ctx context.Context) {
|
||||||
s.Hedge(ctx, uncoverPosition.Neg())
|
s.Hedge(ctx, uncoverPosition.Neg())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profitChanged = true
|
||||||
|
|
||||||
|
case <-reportTicker.C:
|
||||||
|
if profitChanged {
|
||||||
if s.reportProfitStatsRateLimiter.Allow() {
|
if s.reportProfitStatsRateLimiter.Allow() {
|
||||||
bbgo.Notify(s.ProfitStats)
|
bbgo.Notify(s.ProfitStats)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profitChanged = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user