mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +00:00
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:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user