Merge pull request #1685 from c9s/c9s/xalign/notification

IMPROVE: [xalign] improve notification
This commit is contained in:
c9s 2024-08-07 15:05:07 +08:00 committed by GitHub
commit 9e28898df0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 92 additions and 9 deletions

View File

@ -341,6 +341,26 @@ func convertWebSocketOrderUpdate(u max.OrderUpdate) (*types.Order, error) {
}, nil
}
func convertWithdrawStatusV3(status max.WithdrawStatus) types.WithdrawStatus {
switch status {
case max.WithdrawStatusPending:
return types.WithdrawStatusSent
case max.WithdrawStatusOK:
return types.WithdrawStatusCompleted
case max.WithdrawStatusFailed:
return types.WithdrawStatusFailed
case max.WithdrawStatusCancelled:
return types.WithdrawStatusCancelled
}
return types.WithdrawStatus(status)
}
func convertWithdrawStatus(state max.WithdrawState) types.WithdrawStatus {
switch state {

View File

@ -824,8 +824,7 @@ func (e *Exchange) QueryWithdrawHistory(
limit := 1000
txIDs := map[string]struct{}{}
emptyTime := time.Time{}
if startTime == emptyTime {
if startTime.IsZero() {
startTime, err = e.getLaunchDate()
if err != nil {
return nil, err
@ -867,7 +866,7 @@ func (e *Exchange) QueryWithdrawHistory(
}
// we can convert this later
status := convertWithdrawStatus(d.State)
status := convertWithdrawStatusV3(d.Status)
txIDs[d.TxID] = struct{}{}
withdraw := types.Withdraw{
@ -881,11 +880,10 @@ func (e *Exchange) QueryWithdrawHistory(
TransactionFee: d.Fee,
TransactionFeeCurrency: d.FeeCurrency,
Network: d.NetworkProtocol,
// WithdrawOrderID: d.WithdrawOrderID,
// Network: d.Network,
Status: status,
OriginalStatus: string(d.State),
Status: status,
OriginalStatus: string(d.State),
}
allWithdraws = append(allWithdraws, withdraw)
}

View File

@ -145,8 +145,9 @@ func (s *Strategy) detectActiveWithdraw(
}
for _, withdraw := range withdraws {
log.Infof("checking withdraw status: %s", withdraw.String())
switch withdraw.Status {
case types.WithdrawStatusProcessing, types.WithdrawStatusSent, types.WithdrawStatusAwaitingApproval:
case types.WithdrawStatusSent, types.WithdrawStatusProcessing, types.WithdrawStatusAwaitingApproval:
return &withdraw, nil
}
}

View File

@ -4,6 +4,8 @@ import (
"fmt"
"time"
"github.com/slack-go/slack"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
@ -47,7 +49,7 @@ func cutstr(s string, maxLen, head, tail int) string {
}
func (w Withdraw) String() (o string) {
o = fmt.Sprintf("%s WITHDRAW %8f %s -> ", w.Exchange, w.Amount.Float64(), w.Asset)
o = fmt.Sprintf("%s WITHDRAW %s %s -> ", w.Exchange, w.Amount.String(), w.Asset)
if len(w.Network) > 0 && w.Network != w.Asset {
o += w.Network + ":"
@ -68,6 +70,7 @@ func (w Withdraw) String() (o string) {
o += fmt.Sprintf(" TxID: %s", cutstr(w.TransactionID, 12, 4, 4))
}
o += fmt.Sprintf(" STATUS: %s (%s)", w.Status, w.OriginalStatus)
return o
}
@ -75,6 +78,67 @@ func (w Withdraw) EffectiveTime() time.Time {
return w.ApplyTime.Time()
}
func (w *Withdraw) SlackAttachment() slack.Attachment {
var fields []slack.AttachmentField
if len(w.TransactionID) > 0 {
fields = append(fields, slack.AttachmentField{
Title: "TransactionID",
Value: w.TransactionID,
Short: false,
})
}
if w.TransactionFee.Sign() > 0 {
fields = append(fields, slack.AttachmentField{
Title: "Transaction Fee",
Value: fmt.Sprintf("%s %s", w.TransactionFee.String(), w.TransactionFeeCurrency),
Short: false,
})
}
if len(w.Status) > 0 {
fields = append(fields, slack.AttachmentField{
Title: "Status",
Value: fmt.Sprintf("%s (%s)", w.Status, w.OriginalStatus),
Short: false,
})
}
return slack.Attachment{
Color: withdrawStatusSlackColor(w.Status),
Title: fmt.Sprintf("Withdraw %s %s To %s (Network %s)", w.Amount.String(), w.Asset, w.Address, w.Network),
// TitleLink: "",
Pretext: "",
Text: "",
// ServiceName: "",
// ServiceIcon: "",
// FromURL: "",
// OriginalURL: "",
Fields: fields,
Footer: fmt.Sprintf("Apply Time: %s", w.ApplyTime.Time().Format(time.RFC3339)),
// FooterIcon: "",
}
}
func withdrawStatusSlackColor(status WithdrawStatus) string {
switch status {
case WithdrawStatusCompleted:
return "good"
case WithdrawStatusFailed:
return "red"
case WithdrawStatusCancelled:
return "gray"
default:
return "gray"
}
}
type WithdrawalOptions struct {
Network string
AddressTag string