mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
xmaker: remove report ticker and
isolate rate limiter for each different instance
This commit is contained in:
parent
e8bd370aa2
commit
9f01dc28c8
|
@ -22,9 +22,6 @@ import (
|
||||||
var defaultMargin = fixedpoint.NewFromFloat(0.003)
|
var defaultMargin = fixedpoint.NewFromFloat(0.003)
|
||||||
var Two = fixedpoint.NewFromInt(2)
|
var Two = fixedpoint.NewFromInt(2)
|
||||||
|
|
||||||
// circuitBreakerAlertLimiter is for CircuitBreaker alerts
|
|
||||||
var circuitBreakerAlertLimiter = rate.NewLimiter(rate.Every(3*time.Minute), 2)
|
|
||||||
|
|
||||||
const priceUpdateTimeout = 30 * time.Second
|
const priceUpdateTimeout = 30 * time.Second
|
||||||
|
|
||||||
const ID = "xmaker"
|
const ID = "xmaker"
|
||||||
|
@ -124,6 +121,9 @@ type Strategy struct {
|
||||||
groupID uint32
|
groupID uint32
|
||||||
|
|
||||||
stopC chan struct{}
|
stopC chan struct{}
|
||||||
|
|
||||||
|
reportProfitStatsRateLimiter *rate.Limiter
|
||||||
|
circuitBreakerAlertLimiter *rate.Limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) ID() string {
|
func (s *Strategy) ID() string {
|
||||||
|
@ -198,7 +198,7 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or
|
||||||
if reason, halted := s.CircuitBreaker.IsHalted(now); halted {
|
if reason, halted := s.CircuitBreaker.IsHalted(now); halted {
|
||||||
log.Warnf("[arbWorker] strategy is halted, reason: %s", reason)
|
log.Warnf("[arbWorker] strategy is halted, reason: %s", reason)
|
||||||
|
|
||||||
if circuitBreakerAlertLimiter.AllowN(now, 1) {
|
if s.circuitBreakerAlertLimiter.AllowN(now, 1) {
|
||||||
bbgo.Notify("Strategy is halted, reason: %s", reason)
|
bbgo.Notify("Strategy is halted, reason: %s", reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,6 +669,9 @@ func (s *Strategy) Defaults() error {
|
||||||
s.CircuitBreaker = circuitbreaker.NewBasicCircuitBreaker(ID, s.InstanceID())
|
s.CircuitBreaker = circuitbreaker.NewBasicCircuitBreaker(ID, s.InstanceID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -876,15 +879,12 @@ func (s *Strategy) CrossRun(
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
posTicker := time.NewTicker(util.MillisecondsJitter(s.HedgeInterval.Duration(), 200))
|
hedgeTicker := time.NewTicker(util.MillisecondsJitter(s.HedgeInterval.Duration(), 200))
|
||||||
defer posTicker.Stop()
|
defer hedgeTicker.Stop()
|
||||||
|
|
||||||
quoteTicker := time.NewTicker(util.MillisecondsJitter(s.UpdateInterval.Duration(), 200))
|
quoteTicker := time.NewTicker(util.MillisecondsJitter(s.UpdateInterval.Duration(), 200))
|
||||||
defer quoteTicker.Stop()
|
defer quoteTicker.Stop()
|
||||||
|
|
||||||
reportTicker := time.NewTicker(time.Hour)
|
|
||||||
defer reportTicker.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 {
|
||||||
log.WithError(err).Errorf("can not cancel %s orders", s.Symbol)
|
log.WithError(err).Errorf("can not cancel %s orders", s.Symbol)
|
||||||
|
@ -905,10 +905,7 @@ func (s *Strategy) CrossRun(
|
||||||
case <-quoteTicker.C:
|
case <-quoteTicker.C:
|
||||||
s.updateQuote(ctx, orderExecutionRouter)
|
s.updateQuote(ctx, orderExecutionRouter)
|
||||||
|
|
||||||
case <-reportTicker.C:
|
case <-hedgeTicker.C:
|
||||||
bbgo.Notify(s.ProfitStats)
|
|
||||||
|
|
||||||
case <-posTicker.C:
|
|
||||||
// For positive position and positive covered position:
|
// For positive position and positive covered position:
|
||||||
// uncover position = +5 - +3 (covered position) = 2
|
// uncover position = +5 - +3 (covered position) = 2
|
||||||
//
|
//
|
||||||
|
@ -935,6 +932,10 @@ func (s *Strategy) CrossRun(
|
||||||
|
|
||||||
s.Hedge(ctx, uncoverPosition.Neg())
|
s.Hedge(ctx, uncoverPosition.Neg())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.reportProfitStatsRateLimiter.Allow() {
|
||||||
|
bbgo.Notify(s.ProfitStats)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user