From 6bc8dffe160c9222ec04e07251ad14130146f73f Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 31 Jul 2024 16:43:56 +0800 Subject: [PATCH] maxapi: improve withdraw status conversion --- pkg/exchange/max/convert.go | 24 +++++++++++++++++++++++ pkg/exchange/max/exchange.go | 24 +++++------------------ pkg/exchange/max/maxapi/account.go | 31 +++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/pkg/exchange/max/convert.go b/pkg/exchange/max/convert.go index 28fa41788..6cf67d018 100644 --- a/pkg/exchange/max/convert.go +++ b/pkg/exchange/max/convert.go @@ -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) + } +} diff --git a/pkg/exchange/max/exchange.go b/pkg/exchange/max/exchange.go index 41f23d937..ce52d09da 100644 --- a/pkg/exchange/max/exchange.go +++ b/pkg/exchange/max/exchange.go @@ -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) } diff --git a/pkg/exchange/max/maxapi/account.go b/pkg/exchange/max/maxapi/account.go index 678de81f7..018c87b90 100644 --- a/pkg/exchange/max/maxapi/account.go +++ b/pkg/exchange/max/maxapi/account.go @@ -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