maxapi: improve withdraw status conversion

This commit is contained in:
c9s 2024-07-31 16:43:56 +08:00
parent ab20b6db89
commit 6bc8dffe16
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 55 additions and 24 deletions

View File

@ -340,3 +340,27 @@ func convertWebSocketOrderUpdate(u max.OrderUpdate) (*types.Order, error) {
UpdateTime: types.Time(time.Unix(0, u.UpdateTime*int64(time.Millisecond))),
}, nil
}
func convertWithdrawStatus(state max.WithdrawState) types.WithdrawStatus {
switch state {
case max.WithdrawStateSent, max.WithdrawStateSubmitting, max.WithdrawStatePending, "accepted", "approved":
return types.WithdrawStatusSent
case max.WithdrawStateProcessing, "delisted_processing", "kgi_manually_processing", "kgi_manually_confirmed", "sygna_verifying":
return types.WithdrawStatusProcessing
case max.WithdrawStateFailed, "kgi_possible_failed", "rejected", "suspect", "retryable":
return types.WithdrawStatusFailed
case max.WithdrawStateCanceled:
return types.WithdrawStatusCancelled
case "confirmed":
// make it compatible with binance
return types.WithdrawStatusCompleted
default:
return types.WithdrawStatus(state)
}
}

View File

@ -867,23 +867,7 @@ func (e *Exchange) QueryWithdrawHistory(
}
// we can convert this later
status := d.State
switch d.State {
case "confirmed":
status = "completed" // make it compatible with binance
case "submitting", "submitted", "accepted",
"rejected", "suspect", "approved", "delisted_processing",
"processing", "retryable", "sent", "canceled",
"failed", "pending",
"kgi_manually_processing", "kgi_manually_confirmed", "kgi_possible_failed",
"sygna_verifying":
default:
status = d.State
}
status := convertWithdrawStatus(d.State)
txIDs[d.TxID] = struct{}{}
withdraw := types.Withdraw{
@ -891,14 +875,16 @@ func (e *Exchange) QueryWithdrawHistory(
ApplyTime: types.Time(d.CreatedAt),
Asset: toGlobalCurrency(d.Currency),
Amount: d.Amount,
Address: "",
Address: d.Address,
AddressTag: "",
TransactionID: d.TxID,
TransactionFee: d.Fee,
TransactionFeeCurrency: d.FeeCurrency,
Network: d.NetworkProtocol,
// WithdrawOrderID: d.WithdrawOrderID,
// Network: d.Network,
Status: status,
Status: status,
OriginalStatus: string(d.State),
}
allWithdraws = append(allWithdraws, withdraw)
}

View File

@ -155,7 +155,23 @@ type WithdrawState string
const (
WithdrawStateSubmitting WithdrawState = "submitting"
WithdrawStateSubmitted WithdrawState = "submitted"
WithdrawStateConfirmed WithdrawState = "confirmed"
WithdrawStatePending WithdrawState = "pending"
WithdrawStateProcessing WithdrawState = "processing"
WithdrawStateCanceled WithdrawState = "canceled"
WithdrawStateFailed WithdrawState = "failed"
WithdrawStateSent WithdrawState = "sent"
WithdrawStateRejected WithdrawState = "rejected"
)
type WithdrawStatus string
const (
WithdrawStatusPending WithdrawStatus = "pending"
WithdrawStatusCancelled WithdrawStatus = "cancelled"
WithdrawStatusFailed WithdrawStatus = "failed"
WithdrawStatusOK WithdrawStatus = "ok"
)
type Withdraw struct {
@ -167,17 +183,22 @@ type Withdraw struct {
FeeCurrency string `json:"fee_currency"`
TxID string `json:"txid"`
NetworkProtocol string `json:"network_protocol"`
Address string `json:"to_address"`
// State can be "submitting", "submitted",
// "rejected", "accepted", "suspect", "approved", "delisted_processing",
// "processing", "retryable", "sent", "canceled",
// "failed", "pending", "confirmed",
// "kgi_manually_processing", "kgi_manually_confirmed", "kgi_possible_failed",
// "sygna_verifying"
State string `json:"state"`
Confirmations int `json:"confirmations"`
CreatedAt types.MillisecondTimestamp `json:"created_at"`
UpdatedAt types.MillisecondTimestamp `json:"updated_at"`
Notes string `json:"notes"`
State WithdrawState `json:"state"`
Status WithdrawStatus `json:"status,omitempty"`
CreatedAt types.MillisecondTimestamp `json:"created_at"`
UpdatedAt types.MillisecondTimestamp `json:"updated_at"`
Notes string `json:"notes"`
}
//go:generate GetRequest -url "v2/withdrawals" -type GetWithdrawHistoryRequest -responseType []Withdraw