Skip to content

Commit 760f3f6

Browse files
authored
Merge pull request #2374 from c9s/dboy/slack/order-exchange-field
FEATURE: [order] add fields to Slack attachment
2 parents ddcbadb + fbeb206 commit 760f3f6

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

pkg/types/order.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -538,23 +538,22 @@ func (o Order) PlainText() string {
538538
}
539539

540540
func (o Order) SlackAttachment() slack.Attachment {
541-
var fields = []slack.AttachmentField{
542-
{Title: "Symbol", Value: o.Symbol, Short: true},
543-
{Title: "Side", Value: string(o.Side), Short: true},
544-
{Title: "Price", Value: o.Price.String(), Short: true},
545-
{
546-
Title: "Executed Quantity",
547-
Value: o.ExecutedQuantity.String() + "/" + o.Quantity.String(),
541+
542+
var fields []slack.AttachmentField
543+
if o.UUID != "" {
544+
fields = append(fields, slack.AttachmentField{
545+
Title: "UUID",
546+
Value: o.UUID + fmt.Sprintf(" (%d)", o.OrderID),
547+
Short: false,
548+
})
549+
} else {
550+
fields = append(fields, slack.AttachmentField{
551+
Title: "ID",
552+
Value: strconv.FormatUint(o.OrderID, 10),
548553
Short: true,
549-
},
554+
})
550555
}
551556

552-
fields = append(fields, slack.AttachmentField{
553-
Title: "ID",
554-
Value: strconv.FormatUint(o.OrderID, 10),
555-
Short: true,
556-
})
557-
558557
orderStatusIcon := ""
559558

560559
switch o.Status {
@@ -576,11 +575,19 @@ func (o Order) SlackAttachment() slack.Attachment {
576575
})
577576

578577
footerIcon := ExchangeFooterIcon(o.Exchange)
578+
fillRatio := o.ExecutedQuantity.Div(o.Quantity)
579+
orderDetail := fmt.Sprintf(
580+
"%s/%s @ %s (fill ratio: %s)",
581+
o.ExecutedQuantity.String(),
582+
o.Quantity.String(),
583+
o.Price.String(),
584+
fillRatio.Percentage(),
585+
)
579586

580587
return slack.Attachment{
581-
Color: SideToColorName(o.Side),
582-
Title: string(o.Type) + " Order " + string(o.Side),
583-
// Text: "",
588+
Color: SideToColorName(o.Side),
589+
Title: string(o.Type) + " Order " + string(o.Side) + " " + o.Symbol,
590+
Text: orderDetail,
584591
Fields: fields,
585592
FooterIcon: footerIcon,
586593
Footer: strings.ToLower(o.Exchange.String()) + templateutil.Render(" creation time {{ . }}", o.CreationTime.Time().Format(time.StampMilli)),

pkg/types/trade.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,36 @@ func (trade Trade) SlackAttachment() slack.Attachment {
227227
liquidity := trade.Liquidity()
228228
text := templateutil.Render(slackTradeTextTemplate, trade)
229229

230+
fields := []slack.AttachmentField{
231+
{Title: "QuoteQuantity", Value: trade.QuoteQuantity.String(), Short: true},
232+
{Title: "Fee", Value: trade.Fee.String() + " " + trade.FeeCurrency, Short: true},
233+
{Title: "Liquidity", Value: liquidity, Short: true},
234+
}
235+
236+
if trade.OrderUUID != "" {
237+
fields = append(
238+
fields,
239+
slack.AttachmentField{
240+
Title: "Order ID",
241+
Value: fmt.Sprintf("%s (%s)", trade.OrderUUID, strconv.FormatUint(trade.OrderID, 10)),
242+
Short: false,
243+
})
244+
} else {
245+
fields = append(
246+
fields,
247+
slack.AttachmentField{
248+
Title: "Order ID",
249+
Value: strconv.FormatUint(trade.OrderID, 10),
250+
Short: true,
251+
})
252+
}
253+
230254
return slack.Attachment{
231255
Text: text,
232256
// Title: ...
233257
// Pretext: pretext,
234-
Color: color,
235-
Fields: []slack.AttachmentField{
236-
{Title: "Exchange", Value: trade.Exchange.String(), Short: true},
237-
{Title: "QuoteQuantity", Value: trade.QuoteQuantity.String(), Short: true},
238-
{Title: "Fee", Value: trade.Fee.String() + " " + trade.FeeCurrency, Short: true},
239-
{Title: "Liquidity", Value: liquidity, Short: true},
240-
{Title: "Order ID", Value: strconv.FormatUint(trade.OrderID, 10), Short: true},
241-
},
258+
Color: color,
259+
Fields: fields,
242260
FooterIcon: ExchangeFooterIcon(trade.Exchange),
243261
Footer: strings.ToLower(trade.Exchange.String()) + templateutil.Render(" traded at {{ . }}", trade.Time.Time().Format(time.StampMilli)),
244262
}

0 commit comments

Comments
 (0)