Bitstamp: Fix GetWithdrawalRequests/GetWithdrawalsHistory date parsing and enhance test coverage (#1406)

* Bitstamp: Fix GetWithdrawalRequests date parsing

* Bitstamp: Add return error to GetWithdrawalsHistory

* Bitstamp: GetWithdrawalsHistory remove log.Errorf, add description to fmt.Errorf

* Bitstamp: Add tests
This commit is contained in:
Bea
2023-12-29 10:19:23 +07:00
committed by GitHub
parent e866c8f08d
commit 07300d1c70
4 changed files with 37 additions and 14 deletions

View File

@@ -388,15 +388,23 @@ func TestGetOrderStatus(t *testing.T) {
func TestGetWithdrawalRequests(t *testing.T) {
t.Parallel()
_, err := b.GetWithdrawalRequests(context.Background(), 0)
switch {
case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests:
t.Error("GetWithdrawalRequests() error", err)
case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("GetWithdrawalRequests() error", err)
if !mockTests {
sharedtestvalues.SkipTestIfCredentialsUnset(t, b)
}
r, err := b.GetWithdrawalRequests(context.Background(), 1)
assert.NoError(t, err, "GetWithdrawalRequests should not error")
if mockTests {
assert.NotEmpty(t, r, "GetWithdrawalRequests should return a withdrawal request")
for _, req := range r {
assert.Equal(t, int64(1), req.OrderID, "OrderId should match")
assert.Equal(t, "aMDHooGmAkyrsaQiKhAORhSNTmoRzxqWIO", req.Address, "Address should match")
assert.Equal(t, "2022-01-31 16:07:32", req.Date, "Date should match")
assert.Equal(t, currency.BTC, req.Currency, "Currency should match")
assert.Equal(t, 0.00006000, req.Amount, "Amount should match")
assert.Equal(t, "NsOeFbQhRnpGzNIThWGBTkQwRJqTNOGPVhYavrVyMfkAyMUmIlUpFIwGTzSvpeOP", req.TransactionID, "TransactionID should match")
assert.Equal(t, int64(2), req.Status, "Status should match")
assert.Equal(t, int64(0), req.Type, "Type should match")
}
}
}

View File

@@ -2,7 +2,6 @@ package bitstamp
import (
"errors"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
)
@@ -156,7 +155,7 @@ type DepositAddress struct {
// WithdrawalRequests holds request information on withdrawals
type WithdrawalRequests struct {
OrderID int64 `json:"id"`
Date time.Time `json:"datetime"`
Date string `json:"datetime"`
Type int64 `json:"type"`
Amount float64 `json:"amount,string"`
Status int64 `json:"status"`

View File

@@ -540,10 +540,15 @@ func (b *Bitstamp) GetWithdrawalsHistory(ctx context.Context, c currency.Code, _
}
resp := make([]exchange.WithdrawalHistory, 0, len(withdrawals))
for i := range withdrawals {
var tm time.Time
tm, err = parseTime(withdrawals[i].Date)
if err != nil {
return nil, fmt.Errorf("getWithdrawalsHistory unable to parse Date field: %w", err)
}
if c.IsEmpty() || c.Equal(withdrawals[i].Currency) {
resp = append(resp, exchange.WithdrawalHistory{
Status: strconv.FormatInt(withdrawals[i].Status, 10),
Timestamp: withdrawals[i].Date,
Timestamp: tm,
Currency: withdrawals[i].Currency.String(),
Amount: withdrawals[i].Amount,
TransferType: strconv.FormatInt(withdrawals[i].Type, 10),

View File

@@ -68270,9 +68270,20 @@
"/api/withdrawal_requests/": {
"POST": [
{
"data": [],
"data": [{
"address": "aMDHooGmAkyrsaQiKhAORhSNTmoRzxqWIO",
"amount": "0.00006000",
"currency": "BTC",
"datetime": "2022-01-31 16:07:32",
"id": 1,
"network": "bitcoin",
"status": 2,
"transaction_id": "NsOeFbQhRnpGzNIThWGBTkQwRJqTNOGPVhYavrVyMfkAyMUmIlUpFIwGTzSvpeOP",
"txid": 1,
"type": 0
}],
"queryString": "",
"bodyParams": "key=\u0026nonce=1560480184558170717\u0026signature=5CE4CEFAA663FA03DE0005741683D2AE77D9ACD75F4644A2A1E9030E596D4E04",
"bodyParams": "key=&nonce=1701424773861988000&signature=63D3A30E29FF85C814715111F8AC138B0D658C01D45A2EDDCE1E0F09B354DA88&timedelta=1",
"headers": {
"Content-Type": [
"application/x-www-form-urlencoded"