Merge pull request #1789 from c9s/kbear/xalign/fix-log
Some checks are pending
Go / build (1.21, 6.2) (push) Waiting to run
golang-lint / lint (push) Waiting to run

FIX: add slackAttachment method on Deposit
This commit is contained in:
c9s 2024-10-24 16:35:28 +08:00 committed by GitHub
commit 441476c678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/slack-go/slack"
)
type DepositStatus string
@ -81,3 +82,53 @@ func (d Deposit) String() (o string) {
return o
}
func (d *Deposit) SlackAttachment() slack.Attachment {
var fields []slack.AttachmentField
if len(d.TransactionID) > 0 {
fields = append(fields, slack.AttachmentField{
Title: "TransactionID",
Value: d.TransactionID,
Short: false,
})
}
if len(d.Status) > 0 {
fields = append(fields, slack.AttachmentField{
Title: "Status",
Value: string(d.Status),
Short: false,
})
}
return slack.Attachment{
Color: depositStatusSlackColor(d.Status),
Title: fmt.Sprintf("Deposit %s %s To %s", d.Amount.String(), d.Asset, d.Address),
// TitleLink: "",
Pretext: "",
Text: "",
// ServiceName: "",
// ServiceIcon: "",
// FromURL: "",
// OriginalURL: "",
Fields: fields,
Footer: fmt.Sprintf("Apply Time: %s", d.Time.Time().Format(time.RFC3339)),
// FooterIcon: "",
}
}
func depositStatusSlackColor(status DepositStatus) string {
switch status {
case DepositSuccess:
return "good"
case DepositRejected:
return "red"
default:
return "gray"
}
}