mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1685 from c9s/c9s/xalign/notification
IMPROVE: [xalign] improve notification
This commit is contained in:
commit
9e28898df0
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
allWithdraws = append(allWithdraws, withdraw)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user