Skip to content

Commit 70846da

Browse files
committed
🔧 fix(xalign): enhance cbd comments with start time
1 parent 81daf8d commit 70846da

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

pkg/strategy/xalign/alert_cbd.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,31 @@ func (m *CriticalBalanceDiscrepancyAlert) ObjectID() string {
136136
}
137137

138138
func (m *CriticalBalanceDiscrepancyAlert) Comment() *livenote.OptionComment {
139+
startTime := time.Now().Add(-m.SustainedDuration)
139140
return livenote.Comment(
140141
fmt.Sprintf(
141-
"%s %s sustained for %s (~= %f %s > %f %s)",
142+
"%s %s sustained for %s, starting from %s (~= %f %s > %f %s)",
142143
m.BaseCurrency,
143144
m.Delta,
144145
m.SustainedDuration,
146+
startTime.Format(time.RFC3339),
147+
m.Amount.Float64(),
148+
m.QuoteCurrency,
149+
m.AlertAmount.Float64(),
150+
m.QuoteCurrency,
151+
),
152+
)
153+
}
154+
155+
func (m *CriticalBalanceDiscrepancyAlert) WarnComment() *livenote.OptionComment {
156+
startTime := time.Now().Add(-m.SustainedDuration)
157+
return livenote.Comment(
158+
fmt.Sprintf(
159+
"[Critical Balance Warn] %s %s sustained for %s, starting from %s (~= %f %s > %f %s)",
160+
m.BaseCurrency,
161+
m.Delta,
162+
m.SustainedDuration,
163+
startTime.Format(time.RFC3339),
145164
m.Amount.Float64(),
146165
m.QuoteCurrency,
147166
m.AlertAmount.Float64(),

pkg/strategy/xalign/strategy.go

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -694,29 +694,27 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap)
694694
}
695695

696696
if s.WarningDuration > 0 && sustainedDuration >= s.WarningDuration.Duration() {
697-
if s.LargeAmountAlert != nil && price.Sign() > 0 {
698-
if amount.Compare(s.LargeAmountAlert.Amount) > 0 {
699-
cbd := &CriticalBalanceDiscrepancyAlert{
700-
Warning: true,
701-
SlackAlert: s.LargeAmountAlert.Slack,
702-
QuoteCurrency: s.LargeAmountAlert.QuoteCurrency,
703-
AlertAmount: s.LargeAmountAlert.Amount,
704-
BaseCurrency: currency,
705-
SustainedDuration: sustainedDuration,
706-
707-
Side: s.selectAdjustmentOrderSide(q),
708-
Price: price,
709-
Delta: q,
710-
Quantity: quantity,
711-
Amount: amount,
712-
}
713-
bbgo.PostLiveNote(
714-
cbd,
715-
livenote.Channel(s.LargeAmountAlert.Slack.Channel),
716-
livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...),
717-
cbd.Comment(),
718-
)
697+
if s.LargeAmountAlert != nil && price.Sign() > 0 && amount.Compare(s.LargeAmountAlert.Amount) > 0 {
698+
cbd := &CriticalBalanceDiscrepancyAlert{
699+
Warning: true,
700+
SlackAlert: s.LargeAmountAlert.Slack,
701+
QuoteCurrency: s.LargeAmountAlert.QuoteCurrency,
702+
AlertAmount: s.LargeAmountAlert.Amount,
703+
BaseCurrency: currency,
704+
SustainedDuration: sustainedDuration,
705+
706+
Side: s.selectAdjustmentOrderSide(q),
707+
Price: price,
708+
Delta: q,
709+
Quantity: quantity,
710+
Amount: amount,
719711
}
712+
bbgo.PostLiveNote(
713+
cbd,
714+
livenote.Channel(s.LargeAmountAlert.Slack.Channel),
715+
livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...),
716+
cbd.WarnComment(),
717+
)
720718
}
721719
}
722720

@@ -725,28 +723,26 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap)
725723
}
726724
}
727725

728-
if s.LargeAmountAlert != nil && price.Sign() > 0 {
729-
if amount.Compare(s.LargeAmountAlert.Amount) > 0 {
730-
cbd := &CriticalBalanceDiscrepancyAlert{
731-
SlackAlert: s.LargeAmountAlert.Slack,
732-
QuoteCurrency: s.LargeAmountAlert.QuoteCurrency,
733-
AlertAmount: s.LargeAmountAlert.Amount,
734-
BaseCurrency: currency,
735-
SustainedDuration: s.Duration.Duration(),
736-
737-
Side: s.selectAdjustmentOrderSide(q),
738-
Price: price,
739-
Delta: q,
740-
Quantity: quantity,
741-
Amount: amount,
742-
}
743-
bbgo.PostLiveNote(
744-
cbd,
745-
livenote.Channel(s.LargeAmountAlert.Slack.Channel),
746-
livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...),
747-
cbd.Comment(),
748-
)
726+
if s.LargeAmountAlert != nil && price.Sign() > 0 && amount.Compare(s.LargeAmountAlert.Amount) > 0 {
727+
cbd := &CriticalBalanceDiscrepancyAlert{
728+
SlackAlert: s.LargeAmountAlert.Slack,
729+
QuoteCurrency: s.LargeAmountAlert.QuoteCurrency,
730+
AlertAmount: s.LargeAmountAlert.Amount,
731+
BaseCurrency: currency,
732+
SustainedDuration: s.Duration.Duration(),
733+
734+
Side: s.selectAdjustmentOrderSide(q),
735+
Price: price,
736+
Delta: q,
737+
Quantity: quantity,
738+
Amount: amount,
749739
}
740+
bbgo.PostLiveNote(
741+
cbd,
742+
livenote.Channel(s.LargeAmountAlert.Slack.Channel),
743+
livenote.OneTimeMention(s.LargeAmountAlert.Slack.Mentions...),
744+
cbd.Comment(),
745+
)
750746
}
751747

752748
selectedSession, submitOrder := s.selectSessionForCurrency(ctx, sessions, currency, q)

0 commit comments

Comments
 (0)