Skip to content

Commit d8e8cdd

Browse files
authored
Merge pull request #2386 from c9s/dboy/xalign/enrich-notification-content
2 parents 5368563 + a5365e3 commit d8e8cdd

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

pkg/strategy/xalign/slack.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type InteractiveSubmitOrder struct {
3434
delay time.Duration
3535
mentions []string
3636

37+
helpMsg string // optional help message to show in slack
38+
3739
slackEvtID string
3840
dueTime time.Time
3941
done bool
@@ -62,6 +64,10 @@ func NewInteractiveSubmitOrder(order types.SubmitOrder, delay time.Duration, men
6264
return itOrder
6365
}
6466

67+
func (itOrder *InteractiveSubmitOrder) SetHelpMessage(msg string) {
68+
itOrder.helpMsg = msg
69+
}
70+
6571
func (itOrder *InteractiveSubmitOrder) SlackBlocks() []slack.Block {
6672
// add the slack event id block
6773
// IMPORTANT: do not remove this block as it's used as a filter on upcoming interactions
@@ -98,6 +104,10 @@ On %s after delay %s (due at %s)
98104
),
99105
))
100106

107+
if itOrder.helpMsg != "" {
108+
blocks = append(blocks, buildTextBlock(itOrder.helpMsg))
109+
}
110+
101111
// add mention block
102112
if len(itOrder.mentions) > 0 {
103113
blocks = append(blocks, buildTextBlock(strings.Join(itOrder.mentions, " ")))
@@ -253,6 +263,13 @@ func setupSlackInteractionCallback(slackEvtID string, dispatcher *interact.Inter
253263
value, ok := interactOrderRegistry.Load(actionValue)
254264
if !ok {
255265
// it's already processed
266+
actionName := "unknown"
267+
switch actionID {
268+
case cancelOrderActionID:
269+
actionName = "cancel order"
270+
case confirmOrderActionID:
271+
actionName = "confirm order"
272+
}
256273
blocks := []interact.InteractionMessageUpdate{
257274
{
258275
Blocks: removeBlockByID(oriMessage.Blocks.BlockSet, interactiveButtonsBlockID),
@@ -262,7 +279,8 @@ func setupSlackInteractionCallback(slackEvtID string, dispatcher *interact.Inter
262279
{
263280
Blocks: []slack.Block{buildTextBlock(
264281
fmt.Sprintf(
265-
"*Order has been processed, cannot do any further actions.* (requested by %s at %s)",
282+
"*This order has already been processed. Your action (%s) has no effect.* (requested by %s at %s)",
283+
actionName,
266284
user.Name,
267285
time.Now().Format(time.RFC3339),
268286
))},
@@ -274,7 +292,7 @@ func setupSlackInteractionCallback(slackEvtID string, dispatcher *interact.Inter
274292
order, ok := value.(*types.Order)
275293
if ok && order != nil {
276294
blocks = append(blocks, interact.InteractionMessageUpdate{
277-
Blocks: []slack.Block{buildTextBlock("*Created Order*")},
295+
Blocks: []slack.Block{buildTextBlock("*Details of the Submitted Order*")},
278296
Attachments: []slack.Attachment{order.SlackAttachment()},
279297
PostInThread: true,
280298
})

pkg/strategy/xalign/strategy.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ func (s *Strategy) align(ctx context.Context, sessions bbgo.ExchangeSessionMap)
810810
mentions,
811811
s.slackEvtID,
812812
)
813+
itOrder.SetHelpMessage(s.interactiveOrderHelpMessage(submitOrder))
813814
itOrder.AsyncSubmit(ctx, selectedSession, s.onSubmittedOrderCallback)
814815
} else {
815816
createdOrder, err := selectedSession.Exchange.SubmitOrder(ctx, *submitOrder)
@@ -834,6 +835,27 @@ func (s *Strategy) onSubmittedOrderCallback(session *bbgo.ExchangeSession, submi
834835
}
835836
}
836837

838+
func (s *Strategy) interactiveOrderHelpMessage(submitOrder *types.SubmitOrder) string {
839+
quoteCurrency := submitOrder.Market.QuoteCurrency
840+
return fmt.Sprintf(`
841+
xalign Interactive Order Behavior Guide:
842+
- If the alignment amount is <= %.4f %s, it will be placed immediately.
843+
- If %.4f %s < alignment amount < %.4f %s, it will be placed when the deviation is larger than the configured tolerance (%s).
844+
- If the alignment amount >= %.4f %s, an interactive order notification will be sent to Slack for confirmation, and the order will be placed automatically after delay timeout (%s).
845+
`,
846+
s.InstantAlignAmount.Float64(),
847+
quoteCurrency,
848+
s.InstantAlignAmount.Float64(),
849+
quoteCurrency,
850+
s.LargeAmountAlert.Amount.Float64(),
851+
quoteCurrency,
852+
s.BalanceToleranceRange.Percentage(),
853+
s.InteractiveOrderConfig.MinAmount.Float64(),
854+
quoteCurrency,
855+
s.InteractiveOrderConfig.Delay.Duration().String(),
856+
)
857+
}
858+
837859
func (s *Strategy) calculateRefillQuantity(
838860
totalBalances types.BalanceMap, currency string, expectedBalance fixedpoint.Value,
839861
) fixedpoint.Value {

0 commit comments

Comments
 (0)