diff --git a/pkg/strategy/xalign/alert_cbd.go b/pkg/strategy/xalign/alert_cbd.go index 4f909c7d44..baa3256d8a 100644 --- a/pkg/strategy/xalign/alert_cbd.go +++ b/pkg/strategy/xalign/alert_cbd.go @@ -136,12 +136,31 @@ func (m *CriticalBalanceDiscrepancyAlert) ObjectID() string { } func (m *CriticalBalanceDiscrepancyAlert) Comment() *livenote.OptionComment { + startTime := time.Now().Add(-m.SustainedDuration) return livenote.Comment( fmt.Sprintf( - "%s %s sustained for %s (~= %f %s > %f %s)", + "%s %s sustained for %s, starting from %s (~= %f %s > %f %s)", m.BaseCurrency, m.Delta, m.SustainedDuration, + startTime.Format(time.RFC3339), + m.Amount.Float64(), + m.QuoteCurrency, + m.AlertAmount.Float64(), + m.QuoteCurrency, + ), + ) +} + +func (m *CriticalBalanceDiscrepancyAlert) WarnComment() *livenote.OptionComment { + startTime := time.Now().Add(-m.SustainedDuration) + return livenote.Comment( + fmt.Sprintf( + "[Critical Balance Warn] %s %s sustained for %s, starting from %s (~= %f %s > %f %s)", + m.BaseCurrency, + m.Delta, + m.SustainedDuration, + startTime.Format(time.RFC3339), m.Amount.Float64(), m.QuoteCurrency, m.AlertAmount.Float64(), diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index e8db267d0a..e97fa9f8fd 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -694,29 +694,27 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap) } if s.WarningDuration > 0 && sustainedDuration >= s.WarningDuration.Duration() { - if s.LargeAmountAlert != nil && price.Sign() > 0 { - if amount.Compare(s.LargeAmountAlert.Amount) > 0 { - cbd := &CriticalBalanceDiscrepancyAlert{ - Warning: true, - SlackAlert: s.LargeAmountAlert.Slack, - QuoteCurrency: s.LargeAmountAlert.QuoteCurrency, - AlertAmount: s.LargeAmountAlert.Amount, - BaseCurrency: currency, - SustainedDuration: sustainedDuration, - - Side: s.selectAdjustmentOrderSide(q), - Price: price, - Delta: q, - Quantity: quantity, - Amount: amount, - } - bbgo.PostLiveNote( - cbd, - livenote.Channel(s.LargeAmountAlert.Slack.Channel), - livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...), - cbd.Comment(), - ) + if s.LargeAmountAlert != nil && price.Sign() > 0 && amount.Compare(s.LargeAmountAlert.Amount) > 0 { + cbd := &CriticalBalanceDiscrepancyAlert{ + Warning: true, + SlackAlert: s.LargeAmountAlert.Slack, + QuoteCurrency: s.LargeAmountAlert.QuoteCurrency, + AlertAmount: s.LargeAmountAlert.Amount, + BaseCurrency: currency, + SustainedDuration: sustainedDuration, + + Side: s.selectAdjustmentOrderSide(q), + Price: price, + Delta: q, + Quantity: quantity, + Amount: amount, } + bbgo.PostLiveNote( + cbd, + livenote.Channel(s.LargeAmountAlert.Slack.Channel), + livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...), + cbd.WarnComment(), + ) } } @@ -725,28 +723,26 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap) } } - if s.LargeAmountAlert != nil && price.Sign() > 0 { - if amount.Compare(s.LargeAmountAlert.Amount) > 0 { - cbd := &CriticalBalanceDiscrepancyAlert{ - SlackAlert: s.LargeAmountAlert.Slack, - QuoteCurrency: s.LargeAmountAlert.QuoteCurrency, - AlertAmount: s.LargeAmountAlert.Amount, - BaseCurrency: currency, - SustainedDuration: s.Duration.Duration(), - - Side: s.selectAdjustmentOrderSide(q), - Price: price, - Delta: q, - Quantity: quantity, - Amount: amount, - } - bbgo.PostLiveNote( - cbd, - livenote.Channel(s.LargeAmountAlert.Slack.Channel), - livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...), - cbd.Comment(), - ) + if s.LargeAmountAlert != nil && price.Sign() > 0 && amount.Compare(s.LargeAmountAlert.Amount) > 0 { + cbd := &CriticalBalanceDiscrepancyAlert{ + SlackAlert: s.LargeAmountAlert.Slack, + QuoteCurrency: s.LargeAmountAlert.QuoteCurrency, + AlertAmount: s.LargeAmountAlert.Amount, + BaseCurrency: currency, + SustainedDuration: s.Duration.Duration(), + + Side: s.selectAdjustmentOrderSide(q), + Price: price, + Delta: q, + Quantity: quantity, + Amount: amount, } + bbgo.PostLiveNote( + cbd, + livenote.Channel(s.LargeAmountAlert.Slack.Channel), + livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...), + cbd.Comment(), + ) } selectedSession, submitOrder := s.selectSessionForCurrency(ctx, sessions, currency, q)