Skip to content

Commit cbfa80a

Browse files
authored
Merge pull request #2381 from c9s/dboy/order/amount-slack-field
REFACTOR: [order] extract amount field logic and add it to order slack notification
2 parents bbb4cab + 367151d commit cbfa80a

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

pkg/types/order.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,8 @@ func (o *SubmitOrder) SlackAttachment() slack.Attachment {
264264
{Title: "Quantity", Value: o.Quantity.String(), Short: true},
265265
}
266266

267-
if o.Price.Sign() > 0 && o.Quantity.Sign() > 0 && len(o.Market.QuoteCurrency) > 0 {
268-
if currency.IsFiatCurrency(o.Market.QuoteCurrency) {
269-
fields = append(fields, slack.AttachmentField{
270-
Title: "Amount",
271-
Value: currency.USD.FormatMoney(o.Price.Mul(o.Quantity)),
272-
Short: true,
273-
})
274-
} else {
275-
fields = append(fields, slack.AttachmentField{
276-
Title: "Amount",
277-
Value: fmt.Sprintf("%s %s", o.Price.Mul(o.Quantity).String(), o.Market.QuoteCurrency),
278-
Short: true,
279-
})
280-
}
267+
if amountField := o.amountField(); amountField != nil {
268+
fields = append(fields, *amountField)
281269
}
282270

283271
if len(o.ClientOrderID) > 0 {
@@ -296,6 +284,24 @@ func (o *SubmitOrder) SlackAttachment() slack.Attachment {
296284
}
297285
}
298286

287+
func (o *SubmitOrder) amountField() *slack.AttachmentField {
288+
if o.Price.Sign() < 0 || o.Quantity.Sign() < 0 || len(o.Market.QuoteCurrency) == 0 {
289+
return nil
290+
}
291+
if currency.IsFiatCurrency(o.Market.QuoteCurrency) {
292+
return &slack.AttachmentField{
293+
Title: "Amount",
294+
Value: currency.USD.FormatMoney(o.Price.Mul(o.Quantity)),
295+
Short: true,
296+
}
297+
}
298+
return &slack.AttachmentField{
299+
Title: "Amount",
300+
Value: fmt.Sprintf("%s %s", o.Price.Mul(o.Quantity).String(), o.Market.QuoteCurrency),
301+
Short: true,
302+
}
303+
}
304+
299305
type OrderQuery struct {
300306
Symbol string
301307
OrderID string
@@ -574,6 +580,10 @@ func (o Order) SlackAttachment() slack.Attachment {
574580
Short: true,
575581
})
576582

583+
if amountField := o.SubmitOrder.amountField(); amountField != nil {
584+
fields = append(fields, *amountField)
585+
}
586+
577587
footerIcon := ExchangeFooterIcon(o.Exchange)
578588
fillRatio := o.ExecutedQuantity.Div(o.Quantity)
579589
orderDetail := fmt.Sprintf(

0 commit comments

Comments
 (0)