From e0c6e118ed5b24975b2472fc0999d34aa84f9b24 Mon Sep 17 00:00:00 2001 From: Bea <103050835+Beadko@users.noreply.github.com> Date: Mon, 5 Feb 2024 06:39:44 +0700 Subject: [PATCH] Bitstamp/Kraken: Enhance test coverage (#1423) * Bitstamp: Improve GetAccountTradingFees * Bitstamp: Improve test coverage * Bitstamp: Improve TestWithdrawInternationalBank and TestWithdrawFiat * Bitstamp: Fix the failing tests WIP * Bitstamp: Fix TestWithdraw mockTest * Bitstamp: Fix TestWithdrawFiat * Bitstamp: Fix TestWithdrawInternationalBank * Bitstamp: Simplify conditions in TestGetDepositAddress * Bitstamp: Switch Ws functions Errors to assert.Error * Bitstamp: Fix TestSubmitOrder, update other errors * Bitstamp: Fix TestGetOrderStatus, amend error comments * Bitstamp: Fix TestGetOrderInfo * Bitstamp: Fix TestTransferAccountBalance * Bitstamp: Update TestGetWithdrawalsHistory, fix linter errors * Bitstamp: Update TestGetRecentTrades, change type Withdrawal.Requests.Date * Bitstamp: Update TestGetDepositAddress, TestBitstamp_OHLC, TestBitstamp_GetHistoricCandles, TestBitstamp_GetHistoricCandlesExtended * Bitstamp: Fix tests * Bitstamp: Fix the typos and linter, add a side test to TestGetTicker * Bitstamp: Update WithdrawFiat and WithdrawFiatFundsToInternationalBank * Bitstamp: Fix the error description * Bitstamp: Fixup SkipTestIfCredentialsUnset * Bitstamp: Fixup tests * Bitstamp: Fix panic, skip live test TestWithdraw, amend mocktest * Bitstamp: Fixup * Bitstamp: Fixup * Bitstamp: Fixup --- exchanges/bitstamp/bitstamp_mock_test.go | 12 +- exchanges/bitstamp/bitstamp_test.go | 728 +++++++++++----------- exchanges/bitstamp/bitstamp_types.go | 23 +- exchanges/kraken/kraken_test.go | 4 +- testdata/http_mock/bitstamp/bitstamp.json | 262 ++++++-- 5 files changed, 610 insertions(+), 419 deletions(-) diff --git a/exchanges/bitstamp/bitstamp_mock_test.go b/exchanges/bitstamp/bitstamp_mock_test.go index b7f57254..9498879a 100644 --- a/exchanges/bitstamp/bitstamp_mock_test.go +++ b/exchanges/bitstamp/bitstamp_mock_test.go @@ -30,9 +30,15 @@ func TestMain(m *testing.M) { } b.SkipAuthCheck = true bitstampConfig.API.AuthenticatedSupport = true - bitstampConfig.API.Credentials.Key = apiKey - bitstampConfig.API.Credentials.Secret = apiSecret - bitstampConfig.API.Credentials.ClientID = customerID + if apiKey != "" { + bitstampConfig.API.Credentials.Key = apiKey + } + if apiSecret != "" { + bitstampConfig.API.Credentials.Secret = apiSecret + } + if customerID != "" { + bitstampConfig.API.Credentials.ClientID = customerID + } b.SetDefaults() b.Websocket = sharedtestvalues.NewTestWebsocket() err = b.Setup(bitstampConfig) diff --git a/exchanges/bitstamp/bitstamp_test.go b/exchanges/bitstamp/bitstamp_test.go index 81abe485..53d772d9 100644 --- a/exchanges/bitstamp/bitstamp_test.go +++ b/exchanges/bitstamp/bitstamp_test.go @@ -2,11 +2,11 @@ package bitstamp import ( "context" - "errors" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/core" "github.com/thrasher-corp/gocryptotrader/currency" @@ -29,6 +29,7 @@ const ( ) var b = &Bitstamp{} +var btcusdPair = currency.NewPair(currency.BTC, currency.USD) func setFeeBuilder() *exchange.FeeBuilder { return &exchange.FeeBuilder{ @@ -43,23 +44,16 @@ func setFeeBuilder() *exchange.FeeBuilder { func TestGetFeeByTypeOfflineTradeFee(t *testing.T) { t.Parallel() + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } var feeBuilder = setFeeBuilder() _, err := b.GetFeeByType(context.Background(), feeBuilder) - if err != nil { - t.Fatal(err) - } - if !sharedtestvalues.AreAPICredentialsSet(b) { - if feeBuilder.FeeType != exchange.OfflineTradeFee { - t.Errorf("Expected %v, received %v", - exchange.OfflineTradeFee, - feeBuilder.FeeType) - } + assert.NoError(t, err, "GetFeeByType should not error") + if mockTests { + assert.Equal(t, exchange.OfflineTradeFee, feeBuilder.FeeType, "TradeFee should be correct") } else { - if feeBuilder.FeeType != exchange.CryptocurrencyTradeFee { - t.Errorf("Expected %v, received %v", - exchange.CryptocurrencyTradeFee, - feeBuilder.FeeType) - } + assert.Equal(t, exchange.CryptocurrencyTradeFee, feeBuilder.FeeType, "TradeFee should be correct") } } @@ -69,74 +63,69 @@ func TestGetFee(t *testing.T) { var feeBuilder = setFeeBuilder() // CryptocurrencyTradeFee Basic - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) + fee, err := b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") + if mockTests { + assert.NotEmpty(t, fee, "Fee should not be empty") } // CryptocurrencyTradeFee High quantity - feeBuilder = setFeeBuilder() feeBuilder.Amount = 1000 feeBuilder.PurchasePrice = 1000 - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) - } + _, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") // CryptocurrencyTradeFee IsMaker feeBuilder = setFeeBuilder() feeBuilder.IsMaker = true - fee, err := b.GetFee(context.Background(), feeBuilder) - if err != nil { - t.Error(err) - } else if expected := 0.003 * feeBuilder.PurchasePrice * feeBuilder.Amount; fee != expected { - t.Errorf("Bitstamp GetFee wrong Maker fee; Pair: %s Expected: %v Got: %v", feeBuilder.Pair, expected, fee) + fee, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") + if mockTests { + assert.Positive(t, fee, "Maker fee should be positive") } // CryptocurrencyTradeFee IsTaker feeBuilder = setFeeBuilder() feeBuilder.IsMaker = false fee, err = b.GetFee(context.Background(), feeBuilder) - if err != nil { - t.Error(err) - } else if expected := 0.002 * feeBuilder.PurchasePrice * feeBuilder.Amount; fee != expected { - t.Errorf("Bitstamp GetFee wrong Taker fee; Pair: %s Expected: %v Got: %v", feeBuilder.Pair, expected, fee) + if assert.NoError(t, err, "GetFee should not error") { + if mockTests { + assert.Positive(t, fee, "Taker fee should be positive") + } } // CryptocurrencyTradeFee Negative purchase price feeBuilder = setFeeBuilder() feeBuilder.PurchasePrice = -1000 - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) - } + _, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") // CryptocurrencyWithdrawalFee Basic feeBuilder = setFeeBuilder() feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) - } + _, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") // CryptocurrencyDepositFee Basic feeBuilder = setFeeBuilder() feeBuilder.FeeType = exchange.CryptocurrencyDepositFee - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) - } + _, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") // InternationalBankDepositFee Basic feeBuilder = setFeeBuilder() feeBuilder.FeeType = exchange.InternationalBankDepositFee feeBuilder.FiatCurrency = currency.HKD - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) - } + _, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") // InternationalBankWithdrawalFee Basic feeBuilder = setFeeBuilder() feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee feeBuilder.FiatCurrency = currency.HKD - if _, err := b.GetFee(context.Background(), feeBuilder); err != nil { - t.Error(err) - } + fee, err = b.GetFee(context.Background(), feeBuilder) + assert.NoError(t, err, "GetFee should not error") + assert.NotEmpty(t, fee, "Fee should not be empty") } func TestGetAccountTradingFee(t *testing.T) { @@ -183,57 +172,71 @@ func TestGetAccountTradingFees(t *testing.T) { func TestGetTicker(t *testing.T) { t.Parallel() - _, err := b.GetTicker(context.Background(), + tick, err := b.GetTicker(context.Background(), currency.BTC.String()+currency.USD.String(), false) - if err != nil { - t.Error("GetTicker() error", err) - } + assert.NoError(t, err, "GetTicker should not error") + assert.Positive(t, tick.Ask, "Ask should be positive") + assert.Positive(t, tick.Bid, "Bid should be positive") + assert.Positive(t, tick.High, "High should be positive") + assert.Positive(t, tick.Low, "Low should be positive") + assert.Positive(t, tick.Last, "Last should be positive") + assert.Positive(t, tick.Open, "Open should be positive") + assert.Positive(t, tick.Volume, "Volume should be positive") + assert.Positive(t, tick.Vwap, "Vwap should be positive") + assert.NotEmpty(t, tick.Timestamp, "Timestamp should not be empty") + assert.Contains(t, []order.Side{order.Buy, order.Sell}, tick.Side.Side(), "Side should be either Buy or Sell") } func TestGetOrderbook(t *testing.T) { t.Parallel() - _, err := b.GetOrderbook(context.Background(), - currency.BTC.String()+currency.USD.String()) - if err != nil { - t.Error("GetOrderbook() error", err) + ob, err := b.GetOrderbook(context.Background(), currency.BTC.String()+currency.USD.String()) + assert.NoError(t, err, "GetOrderbook should not error") + assert.NotEmpty(t, ob.Timestamp, "Timestamp should not be empty") + for i, o := range [][]OrderbookBase{ob.Asks, ob.Bids} { + s := []string{"Ask", "Bid"}[i] + if assert.NotEmptyf(t, o, "Should have items in %ss", s) { + a := o[0] + assert.Positivef(t, a.Price, "%ss Price should be positive", s) + assert.Positivef(t, a.Amount, "%ss Amount should be positive", s) + } } } func TestGetTradingPairs(t *testing.T) { t.Parallel() - _, err := b.GetTradingPairs(context.Background()) - if err != nil { - t.Error("GetTradingPairs() error", err) + p, err := b.GetTradingPairs(context.Background()) + assert.NoError(t, err, "GetTradingPairs should not error") + assert.NotEmpty(t, p, "Pairs should not be empty") + for _, res := range p { + if mockTests { + assert.Positive(t, res.BaseDecimals, "BaseDecimals should be positive") + assert.Positive(t, res.CounterDecimals, "CounterDecimals should be positive") + } + assert.NotEmpty(t, res.Name, "Name should not be empty") + assert.Positive(t, res.MinimumOrder, "MinimumOrder should be positive") + assert.NotEmpty(t, res.URLSymbol, "URLSymbol should not be empty") + assert.NotEmpty(t, res.Description, "Description should not be empty") } } func TestFetchTradablePairs(t *testing.T) { t.Parallel() - pairs, err := b.FetchTradablePairs(context.Background(), asset.Spot) - if err != nil { - t.Fatal(err) - } - if !pairs.Contains(currency.NewPair(currency.COMP, currency.USD), false) { - t.Error("expected pair COMP/USD") - } - if !pairs.Contains(currency.NewPair(currency.BTC, currency.USD), false) { - t.Error("expected pair BTC/USD") - } - if !pairs.Contains(currency.NewPair(currency.USDC, currency.USDT), false) { - t.Error("expected pair USDC/USDT") - } + + p, err := b.FetchTradablePairs(context.Background(), asset.Spot) + assert.NoError(t, err, "FetchTradablePairs should not error") + assert.True(t, p.Contains(currency.NewBTCUSD(), true), "Pairs should contain BTC/USD") } func TestUpdateTradablePairs(t *testing.T) { t.Parallel() - if err := b.UpdateTradablePairs(context.Background(), true); err != nil { - t.Error("Bitstamp UpdateTradablePairs() error", err) - } + err := b.UpdateTradablePairs(context.Background(), true) + assert.NoError(t, err, "UpdateTradablePairs should not error") } func TestUpdateOrderExecutionLimits(t *testing.T) { t.Parallel() + type limitTest struct { pair currency.Pair step float64 @@ -256,11 +259,17 @@ func TestUpdateOrderExecutionLimits(t *testing.T) { t.Errorf("Bitstamp GetOrderExecutionLimits() error during TestExecutionLimits; Asset: %s Pair: %s Err: %v", assetItem, limitTest.pair, err) continue } - if got := limits.PriceStepIncrementSize; got != limitTest.step { - t.Errorf("Bitstamp UpdateOrderExecutionLimits wrong PriceStepIncrementSize; Asset: %s Pair: %s Expected: %v Got: %v", assetItem, limitTest.pair, limitTest.step, got) - } - if got := limits.MinimumQuoteAmount; got != limitTest.min { - t.Errorf("Bitstamp UpdateOrderExecutionLimits wrong MinAmount; Pair: %s Expected: %v Got: %v", limitTest.pair, limitTest.min, got) + assert.NotEmpty(t, limits.Pair, "Pair should not be empty") + assert.Positive(t, limits.PriceStepIncrementSize, "PriceStepIncrementSize should be positive") + assert.Positive(t, limits.AmountStepIncrementSize, "AmountStepIncrementSize should be positive") + assert.Positive(t, limits.MinimumQuoteAmount, "MinimumQuoteAmount should be positive") + if mockTests { + if got := limits.PriceStepIncrementSize; got != limitTest.step { + t.Errorf("Bitstamp UpdateOrderExecutionLimits wrong PriceStepIncrementSize; Asset: %s Pair: %s Expected: %v Got: %v", assetItem, limitTest.pair, limitTest.step, got) + } + if got := limits.MinimumQuoteAmount; got != limitTest.min { + t.Errorf("Bitstamp UpdateOrderExecutionLimits wrong MinAmount; Pair: %s Expected: %v Got: %v", limitTest.pair, limitTest.min, got) + } } } } @@ -268,33 +277,37 @@ func TestUpdateOrderExecutionLimits(t *testing.T) { func TestGetTransactions(t *testing.T) { t.Parallel() - _, err := b.GetTransactions(context.Background(), + + tr, err := b.GetTransactions(context.Background(), currency.BTC.String()+currency.USD.String(), "hour") - if err != nil { - t.Error("GetTransactions() error", err) + assert.NoError(t, err, "GetTransactions should not error") + assert.NotEmpty(t, tr, "Transactions should not be empty") + for _, res := range tr { + assert.NotEmpty(t, res.Date, "Date should not be empty") + assert.Positive(t, res.Amount, "Amount should be positive") + assert.Positive(t, res.Price, "Price should be positive") + assert.NotEmpty(t, res.TradeID, "TradeID should not be empty") } } func TestGetEURUSDConversionRate(t *testing.T) { t.Parallel() - _, err := b.GetEURUSDConversionRate(context.Background()) - if err != nil { - t.Error("GetEURUSDConversionRate() error", err) - } + c, err := b.GetEURUSDConversionRate(context.Background()) + assert.NoError(t, err, "GetEURUSDConversionRate should not error") + assert.Positive(t, c.Sell, "Sell should be positive") + assert.Positive(t, c.Buy, "Buy should be positive") } func TestGetBalance(t *testing.T) { t.Parallel() + + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } bal, err := b.GetBalance(context.Background()) - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Error("GetBalance() 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("GetBalance() error", err) - case mockTests: + assert.NoError(t, err, "GetBalance should not error") + if mockTests { for k, e := range map[string]Balance{ "USDT": { Available: 42.42, @@ -309,22 +322,10 @@ func TestGetBalance(t *testing.T) { WithdrawalFee: 0.00050000, }, } { - if got, ok := bal[k]; !ok { - t.Error("Expected to find USDT balance") - } else { - if got.Available != e.Available { - t.Errorf("Incorrect Available balance for %s; Expected: %v Got: %v", k, e.Available, got.Available) - } - if got.Balance != e.Balance { - t.Errorf("Incorrect Balance for %s; Expected: %v Got: %v", k, e.Balance, got.Balance) - } - if got.Reserved != e.Reserved { - t.Errorf("Incorrect Reserved balance for %s; Expected: %v Got: %v", k, e.Reserved, got.Reserved) - } - if got.WithdrawalFee != e.WithdrawalFee { - t.Errorf("Incorrect WithdrawalFee for %s; Expected: %v Got: %v", k, e.WithdrawalFee, got.WithdrawalFee) - } - } + assert.Equal(t, e.Available, bal[k].Available, "Available balance should match") + assert.Equal(t, e.Balance, bal[k].Balance, "Balance should match") + assert.Equal(t, e.Reserved, bal[k].Reserved, "Reserved balance should match") + assert.Equal(t, e.WithdrawalFee, bal[k].WithdrawalFee, "WithdrawalFee should match") } } } @@ -332,47 +333,62 @@ func TestGetBalance(t *testing.T) { func TestGetUserTransactions(t *testing.T) { t.Parallel() - _, err := b.GetUserTransactions(context.Background(), "btcusd") - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Error("GetUserTransactions() 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("GetUserTransactions() error", err) + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + tr, err := b.GetUserTransactions(context.Background(), "btcusd") + assert.NoError(t, err, "GetUserTransactions should not error") + if mockTests { + assert.NotEmpty(t, tr, "Transactions should not be empty") + for _, res := range tr { + assert.NotEmpty(t, res.OrderID, "OrderID should not be empty") + assert.NotEmpty(t, res.Date, "Date should not be empty") + } } } func TestGetOpenOrders(t *testing.T) { t.Parallel() - _, err := b.GetOpenOrders(context.Background(), "btcusd") - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Error("GetOpenOrders() 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("GetOpenOrders() error", err) + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + o, err := b.GetOpenOrders(context.Background(), "btcusd") + assert.NoError(t, err, "GetOpenOrders should not error") + if mockTests { + assert.NotEmpty(t, o, "Orders should not be empty") + for _, res := range o { + assert.Equal(t, "2022-01-31 14:43:15", res.DateTime, "order date should match") + assert.Equal(t, int64(1234123412341234), res.ID, "order ID should match") + assert.Equal(t, 0.50000000, res.Amount, "amount should match") + assert.Equal(t, 100.00, res.Price, "price should match") + assert.Equal(t, 0, res.Type, "type should match") + } } } func TestGetOrderStatus(t *testing.T) { t.Parallel() - _, err := b.GetOrderStatus(context.Background(), 1337) - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Error("GetOrderStatus() 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("Expecting an error until a QA pass can be completed") + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + o, err := b.GetOrderStatus(context.Background(), 1458532827766784) + if !mockTests { + assert.ErrorContains(t, err, "Order not found") + } else { + assert.NoError(t, err, "TestGetOrderStatus should not error") + assert.Equal(t, "2022-01-31 14:43:15", o.DateTime, "order date should match") + assert.Equal(t, "1458532827766784", o.ID, "order ID should match") + assert.Equal(t, 200.00, o.Amount, "amount should match") + assert.Equal(t, 50.00, o.Price, "price should match") + assert.Equal(t, 0, o.Type, "type should match") } } func TestGetWithdrawalRequests(t *testing.T) { t.Parallel() + if !mockTests { sharedtestvalues.SkipTestIfCredentialsUnset(t, b) } @@ -396,14 +412,16 @@ func TestGetWithdrawalRequests(t *testing.T) { func TestGetUnconfirmedBitcoinDeposits(t *testing.T) { t.Parallel() - _, err := b.GetUnconfirmedBitcoinDeposits(context.Background()) - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Error("GetUnconfirmedBitcoinDeposits() 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("GetUnconfirmedBitcoinDeposits() error", err) + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + d, err := b.GetUnconfirmedBitcoinDeposits(context.Background()) + assert.NoError(t, err, "GetUnconfirmedBitcoinDeposits should not error") + if mockTests { + assert.NotEmpty(t, d, "Deposits should not be empty") + for _, res := range d { + assert.Equal(t, "0x6a56f5b80f04b4fd70d64d72e1396698635e5436", res.Address) + } } } @@ -413,14 +431,12 @@ func TestTransferAccountBalance(t *testing.T) { if !mockTests { sharedtestvalues.SkipTestIfCredentialsUnset(t, b) } - err := b.TransferAccountBalance(context.Background(), - 0.01, "btc", "testAccount", true) - if !mockTests && err != nil { - t.Error("TransferAccountBalance() error", err) - } - if mockTests && err == nil { - t.Error("Expecting an error until a QA pass can be completed") + 10000, "BTC", "1234567", true) + if !mockTests { + assert.ErrorContains(t, err, "Sub account with identifier \"1234567\" does not exist.") + } else { + assert.NoError(t, err, "TransferAccountBalance should not error") } } @@ -431,50 +447,52 @@ func TestFormatWithdrawPermissions(t *testing.T) { " & " + exchange.AutoWithdrawFiatText withdrawPermissions := b.FormatWithdrawPermissions() - if withdrawPermissions != expectedResult { - t.Errorf("Expected: %s, Received: %s", - expectedResult, - withdrawPermissions) - } + assert.Equal(t, expectedResult, withdrawPermissions, "Permissions should be the same") } func TestGetActiveOrders(t *testing.T) { t.Parallel() - var getOrdersRequest = order.MultiOrderRequest{ + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + o, err := b.GetActiveOrders(context.Background(), &order.MultiOrderRequest{ Type: order.AnyType, AssetType: asset.Spot, Side: order.AnySide, - } - - _, err := b.GetActiveOrders(context.Background(), &getOrdersRequest) - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Could not get open orders: %s", err) - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case mockTests && err != nil: - t.Errorf("Could not get open orders: %s", err) + }) + assert.NoError(t, err, "GetActiveOrders should not error") + if mockTests { + assert.NotEmpty(t, o, "ActiveOrders should not be empty") + for _, res := range o { + assert.Equal(t, "1234123412341234", res.OrderID, "OrderID should be correct") + assert.Equal(t, time.Date(2022, time.January, 31, 14, 43, 15, 0, time.UTC), res.Date, "Date should be correct") + assert.Equal(t, order.Buy, res.Side, "Order Side should be correct") + assert.Equal(t, 100.00, res.Price, "Price should be correct") + assert.Equal(t, currency.NewPairWithDelimiter("BTC", "USD", "/"), res.Pair, "Pair should be correct") + assert.Equal(t, 0.50000000, res.Amount, "Amount should be correct") + } } } func TestGetOrderHistory(t *testing.T) { t.Parallel() - var getOrdersRequest = order.MultiOrderRequest{ + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + o, err := b.GetOrderHistory(context.Background(), &order.MultiOrderRequest{ Type: order.AnyType, AssetType: asset.Spot, Side: order.AnySide, - } - - _, err := b.GetOrderHistory(context.Background(), &getOrdersRequest) - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Could not get order history: %s", err) - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case mockTests && err != nil: - t.Errorf("Could not get order history: %s", err) + }) + assert.NoError(t, err, "GetOrderHistory should not error") + if mockTests { + assert.NotEmpty(t, o, "OrderHistory should not be empty") + for _, res := range o { + assert.NotEmpty(t, res.OrderID, "OrderID should not be empty") + assert.NotEmpty(t, res.Date, "Date should not be empty") + } } } @@ -485,30 +503,32 @@ func TestSubmitOrder(t *testing.T) { t.Parallel() if !mockTests { - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders) } - - var orderSubmission = &order.Submit{ + o, err := b.SubmitOrder(context.Background(), &order.Submit{ Exchange: b.Name, Pair: currency.Pair{ Base: currency.BTC, Quote: currency.USD, }, - Side: order.Buy, - Type: order.Limit, - Price: 1, - Amount: 1, - ClientID: "meowOrder", - AssetType: asset.Spot, - } - response, err := b.SubmitOrder(context.Background(), orderSubmission) - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && (err != nil || response.Status != order.New) && !mockTests: - t.Errorf("Order failed to be placed: %v", err) - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case mockTests && err == nil: - t.Error("Expecting an error until QA pass is completed") + Side: order.Buy, + Type: order.Limit, + Price: 2211.00, + Amount: 45, + ClientOrderID: "123456789", + AssetType: asset.Spot, + }) + if !mockTests { + assert.ErrorContains(t, err, "You have only 0 USD available. Check your account balance for details.") + } else { + assert.NoError(t, err, "SubmitOrder should not error") + assert.Equal(t, float64(45), o.Amount, "Amount should be correct") + assert.Equal(t, asset.Spot, o.AssetType, "AssetType should be correct") + assert.Equal(t, "123456789", o.ClientOrderID, "ClientOrderID should be correct") + assert.Equal(t, "1234123412341234", o.OrderID, "OrderID should be correct") + assert.Equal(t, 2211.0, o.Price, "Price should be correct") + assert.Equal(t, btcusdPair, o.Pair, "Pair should be correct") + assert.WithinRange(t, o.Date, time.Now().Add(-24*time.Hour), time.Now(), "Date should be correct") } } @@ -516,21 +536,15 @@ func TestCancelExchangeOrder(t *testing.T) { t.Parallel() if !mockTests { - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders) } - - orderCancellation := &order.Cancel{ - OrderID: "1234", - AssetType: asset.Spot, - } - err := b.CancelOrder(context.Background(), orderCancellation) - switch { - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Could not cancel orders: %v", err) - case mockTests && err == nil: - t.Error("Expecting an error until QA pass is completed") + err := b.CancelOrder(context.Background(), &order.Cancel{ + OrderID: "1453282316578816", + }) + if !mockTests { + assert.ErrorContains(t, err, "Order not found") + } else { + assert.NoError(t, err, "CancelExchangeOrder should not error") } } @@ -538,20 +552,11 @@ func TestCancelAllExchangeOrders(t *testing.T) { t.Parallel() if !mockTests { - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders) } - resp, err := b.CancelAllOrders(context.Background(), &order.Cancel{AssetType: asset.Spot}) - switch { - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Could not cancel orders: %v", err) - case mockTests && err != nil: - t.Errorf("Could not cancel orders: %v", err) - } - + assert.NoError(t, err, "TestCancelAllExchangeOrders should not error") if len(resp.Status) > 0 { t.Errorf("%v orders failed to cancel", len(resp.Status)) } @@ -559,78 +564,70 @@ func TestCancelAllExchangeOrders(t *testing.T) { func TestModifyOrder(t *testing.T) { t.Parallel() - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + _, err := b.ModifyOrder(context.Background(), &order.Modify{AssetType: asset.Spot}) - if err == nil { - t.Error("ModifyOrder() Expected error") - } + assert.ErrorIs(t, err, common.ErrFunctionNotSupported) } func TestWithdraw(t *testing.T) { t.Parallel() if !mockTests { - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + t.Skip("TestWithdraw not allowed for live tests") } - - withdrawCryptoRequest := withdraw.Request{ + w, err := b.WithdrawCryptocurrencyFunds(context.Background(), &withdraw.Request{ Exchange: b.Name, - Amount: -1, + Amount: 6, Currency: currency.BTC, Description: "WITHDRAW IT ALL", Crypto: withdraw.CryptoRequest{ Address: core.BitcoinDonationAddress, }, - } - - _, err := b.WithdrawCryptocurrencyFunds(context.Background(), &withdrawCryptoRequest) - switch { - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Withdraw failed to be placed: %v", err) - case mockTests && err == nil: - t.Error("Expecting an error until QA pass is completed") - } + }) + require.NoError(t, err, "WithdrawCryptocurrencyFunds should not error") + assert.Equal(t, "1", w.ID, "Withdrawal ID should be correct") } func TestWithdrawFiat(t *testing.T) { t.Parallel() if !mockTests { - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders) } var withdrawFiatRequest = withdraw.Request{ + Type: withdraw.Fiat, + Exchange: b.Name, Fiat: withdraw.FiatRequest{ Bank: banking.Account{ - AccountName: "Satoshi Nakamoto", - AccountNumber: "12345", - BankAddress: "123 Fake St", - BankPostalCity: "Tarry Town", - BankCountry: "AU", - BankName: "Federal Reserve Bank", - SWIFTCode: "CTBAAU2S", - BankPostalCode: "2088", - IBAN: "IT60X0542811101000000123456", + SupportedExchanges: b.Name, + Enabled: true, + AccountName: "Satoshi Nakamoto", + AccountNumber: "12345", + BankAddress: "123 Fake St", + BankPostalCity: "Tarry Town", + BankCountry: "AU", + BankName: "Federal Reserve Bank", + SWIFTCode: "CTBAAU2S", + BankPostalCode: "2088", + IBAN: "IT60X0542811101000000123456", + SupportedCurrencies: "USD", }, WireCurrency: currency.USD.String(), RequiresIntermediaryBank: false, IsExpressWire: false, }, - Amount: -1, + Amount: 10, Currency: currency.USD, Description: "WITHDRAW IT ALL", } - _, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest) - switch { - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Withdraw failed to be placed: %v", err) - case mockTests && err == nil: - t.Error("Expecting an error until QA pass is completed") + w, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest) + if mockTests { + assert.NoError(t, err, "WithdrawFiat should not error") + assert.Equal(t, "1", w.ID, "Withdrawal ID should be correct") + } else { + assert.ErrorContains(t, err, "Check your account balance for details") } } @@ -638,21 +635,26 @@ func TestWithdrawInternationalBank(t *testing.T) { t.Parallel() if !mockTests { - sharedtestvalues.SkipTestIfCannotManipulateOrders(t, b, canManipulateRealOrders) + sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders) } var withdrawFiatRequest = withdraw.Request{ + Type: withdraw.Fiat, + Exchange: b.Name, Fiat: withdraw.FiatRequest{ Bank: banking.Account{ - AccountName: "Satoshi Nakamoto", - AccountNumber: "12345", - BankAddress: "123 Fake St", - BankPostalCity: "Tarry Town", - BankCountry: "AU", - BankName: "Federal Reserve Bank", - SWIFTCode: "CTBAAU2S", - BankPostalCode: "2088", - IBAN: "IT60X0542811101000000123456", + SupportedExchanges: b.Name, + Enabled: true, + AccountName: "Satoshi Nakamoto", + AccountNumber: "12345", + BankAddress: "123 Fake St", + BankPostalCity: "Tarry Town", + BankCountry: "AU", + BankName: "Federal Reserve Bank", + SWIFTCode: "CTBAAU2S", + BankPostalCode: "2088", + IBAN: "IT60X0542811101000000123456", + SupportedCurrencies: "USD", }, WireCurrency: currency.USD.String(), RequiresIntermediaryBank: false, @@ -664,35 +666,30 @@ func TestWithdrawInternationalBank(t *testing.T) { IntermediaryBankName: "Federal Reserve Bank", IntermediaryBankPostalCode: "2088", }, - Amount: -1, + Amount: 50, Currency: currency.USD, Description: "WITHDRAW IT ALL", } - _, err := b.WithdrawFiatFundsToInternationalBank(context.Background(), + w, err := b.WithdrawFiatFundsToInternationalBank(context.Background(), &withdrawFiatRequest) - switch { - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("Expecting an error when no keys are set") - case sharedtestvalues.AreAPICredentialsSet(b) && err != nil && !mockTests: - t.Errorf("Withdraw failed to be placed: %v", err) - case mockTests && err == nil: - t.Error("Expecting an error until QA pass is completed") + if mockTests { + assert.Equal(t, "1", w.ID, "Withdrawal ID should be correct") + } else { + assert.NoError(t, err, "WithdrawFiatFundsToInternationalBank should not error") } } func TestGetDepositAddress(t *testing.T) { t.Parallel() - _, err := b.GetDepositAddress(context.Background(), currency.XRP, "", "") - switch { - case sharedtestvalues.AreAPICredentialsSet(b) && customerID != "" && err != nil && !mockTests: - t.Error("GetDepositAddress error", err) - case !sharedtestvalues.AreAPICredentialsSet(b) && err == nil && !mockTests: - t.Error("GetDepositAddress error cannot be nil") - case mockTests && err != nil: - t.Error("GetDepositAddress error", err) + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders) } + a, err := b.GetDepositAddress(context.Background(), currency.XRP, "", "") + assert.NoError(t, err, "GetDepositAddress should not error") + assert.NotEmpty(t, a.Address, "Address should not be empty") + assert.NotEmpty(t, a.Tag, "Tag should not be empty") } func TestParseTime(t *testing.T) { @@ -721,9 +718,7 @@ func TestWsSubscription(t *testing.T) { } }`) err := b.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "TestWsSubscription should not error") } func TestWsUnsubscribe(t *testing.T) { @@ -734,41 +729,34 @@ func TestWsUnsubscribe(t *testing.T) { } }`) err := b.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "WsUnsubscribe should not error") } func TestWsTrade(t *testing.T) { pressXToJSON := []byte(`{"data": {"microtimestamp": "1580336751488517", "amount": 0.00598803, "buy_order_id": 4621328909, "sell_order_id": 4621329035, "amount_str": "0.00598803", "price_str": "9334.73", "timestamp": "1580336751", "price": 9334.73, "type": 1, "id": 104007706}, "event": "trade", "channel": "live_trades_btcusd"}`) err := b.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "TestWsTrade should not error") } func TestWsOrderbook(t *testing.T) { pressXToJSON := []byte(`{"data": {"timestamp": "1580336834", "microtimestamp": "1580336834607546", "bids": [["9328.28", "0.05925332"], ["9327.34", "0.43120000"], ["9327.29", "0.63470860"], ["9326.59", "0.41114619"], ["9326.38", "1.06910000"], ["9323.91", "2.67930000"], ["9322.69", "0.80000000"], ["9322.57", "0.03000000"], ["9322.31", "1.36010820"], ["9319.54", "0.03090000"], ["9318.97", "0.28000000"], ["9317.61", "0.02910000"], ["9316.39", "1.08000000"], ["9316.20", "2.00000000"], ["9315.48", "1.00000000"], ["9314.72", "0.11197459"], ["9314.47", "0.32207398"], ["9312.53", "0.03961501"], ["9312.29", "1.00000000"], ["9311.78", "0.03060000"], ["9311.69", "0.32217221"], ["9310.98", "3.29000000"], ["9310.18", "0.01304192"], ["9310.13", "0.02500000"], ["9309.04", "1.00000000"], ["9309.00", "0.05000000"], ["9308.96", "0.03030000"], ["9308.91", "0.32227154"], ["9307.52", "0.32191362"], ["9307.25", "2.44280000"], ["9305.92", "3.00000000"], ["9305.62", "2.37600000"], ["9305.60", "0.21815312"], ["9305.54", "2.80000000"], ["9305.13", "0.05000000"], ["9305.02", "2.90917302"], ["9303.68", "0.02316372"], ["9303.53", "12.55000000"], ["9303.00", "0.02191430"], ["9302.94", "2.38250000"], ["9302.37", "0.01000000"], ["9301.85", "2.50000000"], ["9300.89", "0.02000000"], ["9300.40", "4.10000000"], ["9300.00", "0.33936139"], ["9298.48", "1.45200000"], ["9297.80", "0.42380000"], ["9295.44", "4.54689328"], ["9295.43", "3.20000000"], ["9295.00", "0.28669566"], ["9291.66", "14.09931321"], ["9290.13", "2.87254900"], ["9290.00", "0.67530840"], ["9285.37", "0.38033002"], ["9285.15", "5.37993528"], ["9285.00", "0.09419278"], ["9283.71", "0.15679830"], ["9280.33", "12.55000000"], ["9280.13", "3.20310000"], ["9280.00", "1.36477909"], ["9276.01", "0.00707488"], ["9275.75", "0.56974291"], ["9275.00", "5.88000000"], ["9274.00", "0.00754205"], ["9271.68", "0.01400000"], ["9271.11", "15.37188500"], ["9270.00", "0.06674325"], ["9268.79", "24.54320000"], ["9257.18", "12.55000000"], ["9256.30", "0.17876365"], ["9255.71", "13.82642967"], ["9254.79", "0.96329407"], ["9250.00", "0.78214958"], ["9245.34", "4.90200000"], ["9245.13", "0.10000000"], ["9240.00", "0.44383459"], ["9238.84", "13.16615207"], ["9234.11", "0.43317656"], ["9234.10", "12.55000000"], ["9231.28", "11.79290000"], ["9230.09", "4.15059441"], ["9227.69", "0.00791097"], ["9225.00", "0.44768346"], ["9224.49", "0.85857203"], ["9223.50", "5.61001041"], ["9216.01", "0.03222653"], ["9216.00", "0.05000000"], ["9213.54", "0.71253866"], ["9212.50", "2.86768195"], ["9211.07", "12.55000000"], ["9210.00", "0.54288817"], ["9208.00", "1.00000000"], ["9206.06", "2.62587578"], ["9205.98", "15.40000000"], ["9205.52", "0.01710603"], ["9205.37", "0.03524953"], ["9205.11", "0.15000000"], ["9205.00", "0.01534763"], ["9204.76", "7.00600000"], ["9203.00", "0.01090000"]], "asks": [["9337.10", "0.03000000"], ["9340.85", "2.67820000"], ["9340.95", "0.02900000"], ["9341.17", "1.00000000"], ["9341.41", "2.13966390"], ["9341.61", "0.20000000"], ["9341.97", "0.11199911"], ["9341.98", "3.00000000"], ["9342.26", "0.32112762"], ["9343.87", "1.00000000"], ["9344.17", "3.57250000"], ["9345.04", "0.32103450"], ["9345.41", "4.90000000"], ["9345.69", "1.03000000"], ["9345.80", "0.03000000"], ["9346.00", "0.10200000"], ["9346.69", "0.02397394"], ["9347.41", "1.00000000"], ["9347.82", "0.32094177"], ["9348.23", "0.02880000"], ["9348.62", "11.96287551"], ["9349.31", "2.44270000"], ["9349.47", "0.96000000"], ["9349.86", "4.50000000"], ["9350.37", "0.03300000"], ["9350.57", "0.34682266"], ["9350.60", "0.32085527"], ["9351.45", "0.31147923"], ["9352.31", "0.28000000"], ["9352.86", "9.80000000"], ["9353.73", "0.02360739"], ["9354.00", "0.45000000"], ["9354.12", "0.03000000"], ["9354.29", "3.82446861"], ["9356.20", "0.64000000"], ["9356.90", "0.02316372"], ["9357.30", "2.50000000"], ["9357.70", "2.38240000"], ["9358.92", "6.00000000"], ["9359.97", "0.34898075"], ["9359.98", "2.30000000"], ["9362.56", "2.37600000"], ["9365.00", "0.64000000"], ["9365.16", "1.70030306"], ["9365.27", "3.03000000"], ["9369.99", "2.47102665"], ["9370.00", "3.15688574"], ["9370.21", "2.32720000"], ["9371.78", "13.20000000"], ["9371.89", "0.96293482"], ["9375.08", "4.74762500"], ["9384.34", "1.45200000"], ["9384.49", "16.42310000"], ["9385.66", "0.34382112"], ["9388.19", "0.00268265"], ["9392.20", "0.20980000"], ["9392.40", "0.10320000"], ["9393.00", "0.20980000"], ["9395.40", "0.40000000"], ["9398.86", "24.54310000"], ["9400.00", "0.05489988"], ["9400.33", "0.00495100"], ["9400.45", "0.00484700"], ["9402.92", "17.20000000"], ["9404.18", "10.00000000"], ["9418.89", "16.38000000"], ["9419.41", "3.06700000"], ["9420.40", "12.50000000"], ["9421.11", "0.10500000"], ["9434.47", "0.03215805"], ["9434.48", "0.28285714"], ["9434.49", "15.83000000"], ["9435.13", "0.15000000"], ["9438.93", "0.00368800"], ["9439.19", "0.69343985"], ["9442.86", "0.10000000"], ["9443.96", "12.50000000"], ["9444.00", "0.06004471"], ["9444.97", "0.01494896"], ["9447.00", "0.01234000"], ["9448.97", "0.14500000"], ["9449.00", "0.05000000"], ["9450.00", "11.13426018"], ["9451.87", "15.90000000"], ["9452.00", "0.20000000"], ["9454.25", "0.01100000"], ["9454.51", "0.02409062"], ["9455.05", "0.00600063"], ["9456.00", "0.27965118"], ["9456.10", "0.17000000"], ["9459.00", "0.00320000"], ["9459.98", "0.02460685"], ["9459.99", "8.11000000"], ["9460.00", "0.08500000"], ["9464.36", "0.56957951"], ["9464.54", "0.69158059"], ["9465.00", "21.00002015"], ["9467.57", "12.50000000"], ["9468.00", "0.08800000"], ["9469.09", "13.94000000"]]}, "event": "data", "channel": "order_book_btcusd"}`) err := b.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "TestWsOrderbook should not error") + pressXToJSON = []byte(`{"data": {"timestamp": "1580336834", "microtimestamp": "1580336834607546", "bids": [["9328.28", "0.05925332"], ["9327.34", "0.43120000"], ["9327.29", "0.63470860"], ["9326.59", "0.41114619"], ["9326.38", "1.06910000"], ["9323.91", "2.67930000"], ["9322.69", "0.80000000"], ["9322.57", "0.03000000"], ["9322.31", "1.36010820"], ["9319.54", "0.03090000"], ["9318.97", "0.28000000"], ["9317.61", "0.02910000"], ["9316.39", "1.08000000"], ["9316.20", "2.00000000"], ["9315.48", "1.00000000"], ["9314.72", "0.11197459"], ["9314.47", "0.32207398"], ["9312.53", "0.03961501"], ["9312.29", "1.00000000"], ["9311.78", "0.03060000"], ["9311.69", "0.32217221"], ["9310.98", "3.29000000"], ["9310.18", "0.01304192"], ["9310.13", "0.02500000"], ["9309.04", "1.00000000"], ["9309.00", "0.05000000"], ["9308.96", "0.03030000"], ["9308.91", "0.32227154"], ["9307.52", "0.32191362"], ["9307.25", "2.44280000"], ["9305.92", "3.00000000"], ["9305.62", "2.37600000"], ["9305.60", "0.21815312"], ["9305.54", "2.80000000"], ["9305.13", "0.05000000"], ["9305.02", "2.90917302"], ["9303.68", "0.02316372"], ["9303.53", "12.55000000"], ["9303.00", "0.02191430"], ["9302.94", "2.38250000"], ["9302.37", "0.01000000"], ["9301.85", "2.50000000"], ["9300.89", "0.02000000"], ["9300.40", "4.10000000"], ["9300.00", "0.33936139"], ["9298.48", "1.45200000"], ["9297.80", "0.42380000"], ["9295.44", "4.54689328"], ["9295.43", "3.20000000"], ["9295.00", "0.28669566"], ["9291.66", "14.09931321"], ["9290.13", "2.87254900"], ["9290.00", "0.67530840"], ["9285.37", "0.38033002"], ["9285.15", "5.37993528"], ["9285.00", "0.09419278"], ["9283.71", "0.15679830"], ["9280.33", "12.55000000"], ["9280.13", "3.20310000"], ["9280.00", "1.36477909"], ["9276.01", "0.00707488"], ["9275.75", "0.56974291"], ["9275.00", "5.88000000"], ["9274.00", "0.00754205"], ["9271.68", "0.01400000"], ["9271.11", "15.37188500"], ["9270.00", "0.06674325"], ["9268.79", "24.54320000"], ["9257.18", "12.55000000"], ["9256.30", "0.17876365"], ["9255.71", "13.82642967"], ["9254.79", "0.96329407"], ["9250.00", "0.78214958"], ["9245.34", "4.90200000"], ["9245.13", "0.10000000"], ["9240.00", "0.44383459"], ["9238.84", "13.16615207"], ["9234.11", "0.43317656"], ["9234.10", "12.55000000"], ["9231.28", "11.79290000"], ["9230.09", "4.15059441"], ["9227.69", "0.00791097"], ["9225.00", "0.44768346"], ["9224.49", "0.85857203"], ["9223.50", "5.61001041"], ["9216.01", "0.03222653"], ["9216.00", "0.05000000"], ["9213.54", "0.71253866"], ["9212.50", "2.86768195"], ["9211.07", "12.55000000"], ["9210.00", "0.54288817"], ["9208.00", "1.00000000"], ["9206.06", "2.62587578"], ["9205.98", "15.40000000"], ["9205.52", "0.01710603"], ["9205.37", "0.03524953"], ["9205.11", "0.15000000"], ["9205.00", "0.01534763"], ["9204.76", "7.00600000"], ["9203.00", "0.01090000"]], "asks": [["9337.10", "0.03000000"], ["9340.85", "2.67820000"], ["9340.95", "0.02900000"], ["9341.17", "1.00000000"], ["9341.41", "2.13966390"], ["9341.61", "0.20000000"], ["9341.97", "0.11199911"], ["9341.98", "3.00000000"], ["9342.26", "0.32112762"], ["9343.87", "1.00000000"], ["9344.17", "3.57250000"], ["9345.04", "0.32103450"], ["9345.41", "4.90000000"], ["9345.69", "1.03000000"], ["9345.80", "0.03000000"], ["9346.00", "0.10200000"], ["9346.69", "0.02397394"], ["9347.41", "1.00000000"], ["9347.82", "0.32094177"], ["9348.23", "0.02880000"], ["9348.62", "11.96287551"], ["9349.31", "2.44270000"], ["9349.47", "0.96000000"], ["9349.86", "4.50000000"], ["9350.37", "0.03300000"], ["9350.57", "0.34682266"], ["9350.60", "0.32085527"], ["9351.45", "0.31147923"], ["9352.31", "0.28000000"], ["9352.86", "9.80000000"], ["9353.73", "0.02360739"], ["9354.00", "0.45000000"], ["9354.12", "0.03000000"], ["9354.29", "3.82446861"], ["9356.20", "0.64000000"], ["9356.90", "0.02316372"], ["9357.30", "2.50000000"], ["9357.70", "2.38240000"], ["9358.92", "6.00000000"], ["9359.97", "0.34898075"], ["9359.98", "2.30000000"], ["9362.56", "2.37600000"], ["9365.00", "0.64000000"], ["9365.16", "1.70030306"], ["9365.27", "3.03000000"], ["9369.99", "2.47102665"], ["9370.00", "3.15688574"], ["9370.21", "2.32720000"], ["9371.78", "13.20000000"], ["9371.89", "0.96293482"], ["9375.08", "4.74762500"], ["9384.34", "1.45200000"], ["9384.49", "16.42310000"], ["9385.66", "0.34382112"], ["9388.19", "0.00268265"], ["9392.20", "0.20980000"], ["9392.40", "0.10320000"], ["9393.00", "0.20980000"], ["9395.40", "0.40000000"], ["9398.86", "24.54310000"], ["9400.00", "0.05489988"], ["9400.33", "0.00495100"], ["9400.45", "0.00484700"], ["9402.92", "17.20000000"], ["9404.18", "10.00000000"], ["9418.89", "16.38000000"], ["9419.41", "3.06700000"], ["9420.40", "12.50000000"], ["9421.11", "0.10500000"], ["9434.47", "0.03215805"], ["9434.48", "0.28285714"], ["9434.49", "15.83000000"], ["9435.13", "0.15000000"], ["9438.93", "0.00368800"], ["9439.19", "0.69343985"], ["9442.86", "0.10000000"], ["9443.96", "12.50000000"], ["9444.00", "0.06004471"], ["9444.97", "0.01494896"], ["9447.00", "0.01234000"], ["9448.97", "0.14500000"], ["9449.00", "0.05000000"], ["9450.00", "11.13426018"], ["9451.87", "15.90000000"], ["9452.00", "0.20000000"], ["9454.25", "0.01100000"], ["9454.51", "0.02409062"], ["9455.05", "0.00600063"], ["9456.00", "0.27965118"], ["9456.10", "0.17000000"], ["9459.00", "0.00320000"], ["9459.98", "0.02460685"], ["9459.99", "8.11000000"], ["9460.00", "0.08500000"], ["9464.36", "0.56957951"], ["9464.54", "0.69158059"], ["9465.00", "21.00002015"], ["9467.57", "12.50000000"], ["9468.00", "0.08800000"], ["9469.09", "13.94000000"]]}, "event": "data", "channel": ""}`) - if err = b.wsHandleData(pressXToJSON); !errors.Is(err, errWSPairParsingError) { - t.Errorf("expected %s, got %s", errWSPairParsingError, err) - } + err = b.wsHandleData(pressXToJSON) + assert.Equal(t, errWSPairParsingError, err, "TestWsOrderbook should error parsing error") } func TestWsOrderbook2(t *testing.T) { pressXToJSON := []byte(`{"data":{"timestamp":"1606965727","microtimestamp":"1606965727403931","bids":[["19133.97","0.01000000"],["19131.58","0.39200000"],["19131.18","0.69581810"],["19131.17","0.48139054"],["19129.72","0.48164130"],["19129.71","0.65400000"],["19128.80","1.04500000"],["19128.59","0.65400000"],["19128.12","0.00259236"],["19127.81","0.19784245"],["19126.66","1.04500000"],["19125.74","0.26020000"],["19124.68","0.22000000"],["19122.01","0.39777840"],["19122.00","1.04600000"],["19121.27","0.16741000"],["19121.10","1.56390000"],["19119.90","1.60000000"],["19119.58","0.15593238"],["19117.70","1.14600000"],["19115.36","2.61300000"],["19114.60","1.19570000"],["19113.88","0.07500000"],["19113.86","0.15668522"],["19113.70","1.00000000"],["19113.69","1.60000000"],["19112.27","0.00166667"],["19111.00","0.15464628"],["19108.80","0.70000000"],["19108.77","0.16300000"],["19108.38","1.10000000"],["19107.53","0.10000000"],["19106.83","0.21377991"],["19106.78","3.45938881"],["19104.24","1.30000000"],["19100.81","0.00166667"],["19100.21","0.49770000"],["19099.54","2.40971961"],["19099.53","0.51223189"],["19097.40","1.55000000"],["19095.55","2.61300000"],["19092.94","0.27402906"],["19092.20","1.60000000"],["19089.36","0.00166667"],["19086.32","1.62000000"],["19085.23","1.65670000"],["19080.88","1.40000000"],["19075.45","1.16000000"],["19071.24","1.20000000"],["19065.09","1.51000000"],["19059.38","1.57000000"],["19058.11","0.37393556"],["19052.98","0.01000000"],["19052.90","0.33000000"],["19049.55","6.89000000"],["19047.61","6.03623432"],["19030.16","16.60260000"],["19026.76","23.90800000"],["19024.78","2.16656212"],["19022.11","0.02628500"],["19020.37","6.03000000"],["19000.00","0.00132020"],["18993.52","2.22000000"],["18979.21","6.03240000"],["18970.20","0.01500000"],["18969.14","7.42000000"],["18956.46","6.03240000"],["18950.22","42.37500000"],["18950.00","0.00132019"],["18949.94","0.52650000"],["18946.00","0.00791700"],["18933.74","6.03240000"],["18932.21","8.21000000"],["18926.99","0.00150000"],["18926.98","0.02641500"],["18925.00","0.02000000"],["18909.99","0.00133000"],["18908.47","7.15000000"],["18905.99","0.00133000"],["18905.20","0.00190000"],["18901.00","0.10000000"],["18900.67","0.24430000"],["18900.00","7.56529933"],["18895.99","0.00178450"],["18890.00","0.10000000"],["18889.90","0.10580000"],["18888.00","0.00362564"],["18887.00","4.00000000"],["18881.62","0.20583403"],["18880.08","5.72198740"],["18880.05","8.33480000"],["18879.09","7.33000000"],["18875.99","0.00132450"],["18875.00","0.02000000"],["18873.47","0.25934200"],["18871.99","0.00132600"],["18870.93","0.36463225"],["18864.10","43.56800000"],["18853.11","0.00540000"],["18850.01","0.38925549"]],"asks":[["19141.75","0.39300000"],["19141.78","0.10204700"],["19143.05","1.99685100"],["19143.08","0.05777900"],["19143.09","1.60700800"],["19143.10","0.48282909"],["19143.36","0.11250000"],["19144.06","0.26040000"],["19145.97","0.65400000"],["19146.02","0.22000000"],["19146.56","0.45061841"],["19147.45","0.15877831"],["19148.92","0.70431840"],["19148.93","0.78400000"],["19150.32","0.78400000"],["19151.55","0.07500000"],["19152.64","3.11400000"],["19153.32","1.04600000"],["19153.84","0.15626630"],["19155.57","3.10000000"],["19156.40","0.13438213"],["19156.92","0.16300000"],["19157.54","1.38970000"],["19158.18","0.00166667"],["19158.41","0.15317000"],["19158.78","0.15888798"],["19160.14","0.10000000"],["19160.34","1.60000000"],["19160.70","1.21590000"],["19162.17","0.00352761"],["19162.67","1.04500000"],["19163.61","0.15000000"],["19163.80","1.18050000"],["19164.62","0.86919692"],["19165.36","0.15674424"],["19166.75","1.40000000"],["19167.47","2.61300000"],["19169.68","0.00166667"],["19171.08","0.15452025"],["19171.69","0.54308236"],["19172.12","0.49000000"],["19173.47","1.34000000"],["19174.49","1.07436448"],["19175.37","0.01200000"],["19178.25","1.50000000"],["19178.80","0.49770000"],["19181.18","0.00166667"],["19182.75","1.77297176"],["19182.76","2.61099999"],["19183.03","1.20000000"],["19185.17","6.00352761"],["19189.56","0.05797137"],["19189.72","1.17000000"],["19193.94","1.60000000"],["19197.15","0.26961100"],["19200.00","0.03107838"],["19200.06","1.29000000"],["19202.73","1.65670000"],["19206.06","1.30000000"],["19208.19","6.00352761"],["19209.00","0.00132021"],["19210.70","1.20000000"],["19213.77","0.02615500"],["19217.40","8.50000000"],["19217.57","1.29000000"],["19222.61","1.19000000"],["19230.00","0.00193480"],["19231.24","6.00000000"],["19237.91","6.89152278"],["19240.13","6.90000000"],["19242.16","0.00336000"],["19243.38","0.00299103"],["19244.48","14.79300000"],["19248.25","0.01300000"],["19250.00","1.95802492"],["19251.00","0.45000000"],["19254.20","0.00366102"],["19254.32","6.00000000"],["19259.00","0.00131022"],["19266.43","0.00917191"],["19267.63","0.05000000"],["19267.79","7.10000000"],["19268.72","16.60260000"],["19277.42","6.00000000"],["19286.64","0.00916230"],["19295.49","7.77000000"],["19300.00","0.19668172"],["19306.00","0.06000000"],["19307.00","3.00000000"],["19307.40","0.19000000"],["19309.00","0.00262046"],["19310.33","0.02602500"],["19319.33","0.00213688"],["19320.00","0.00171242"],["19321.02","48.47300000"],["19322.74","0.00250000"],["19324.00","0.36983571"],["19325.54","0.02314521"],["19325.73","7.22000000"],["19326.50","0.00915272"]]},"channel":"order_book_btcusd","event":"data"}`) err := b.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "WsOrderbook2 should not error") } func TestWsOrderUpdate(t *testing.T) { t.Parallel() + n := new(Bitstamp) sharedtestvalues.TestFixtureToDataHandler(t, b, n, "testdata/wsMyOrders.json", n.wsHandleData) seen := 0 @@ -856,100 +844,110 @@ func TestWsRequestReconnect(t *testing.T) { "data": "" }`) err := b.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "WsRequestReconnect should not error") } func TestBitstamp_OHLC(t *testing.T) { start := time.Unix(1546300800, 0) end := time.Unix(1577836799, 0) - _, err := b.OHLC(context.Background(), "btcusd", start, end, "60", "10") - if err != nil { - t.Fatal(err) + o, err := b.OHLC(context.Background(), "btcusd", start, end, "60", "10") + assert.NoError(t, err, "TestBitstamp_OHLC should not error") + assert.Equal(t, "BTC/USD", o.Data.Pair, "Pair should be correct") + for _, req := range o.Data.OHLCV { + assert.Positive(t, req.Low, "Low should be positive") + assert.Positive(t, req.Close, "Close should be positive") + assert.Positive(t, req.Open, "Open should be positive") + assert.Positive(t, req.Volume, "Volume should be positive") + assert.NotEmpty(t, req.Timestamp, "Timestamp should not be empty") } } func TestBitstamp_GetHistoricCandles(t *testing.T) { - pair, err := currency.NewPairFromString("BTCUSD") - if err != nil { - t.Fatal(err) - } start := time.Unix(1546300800, 0) end := time.Unix(1577836799, 0) - _, err = b.GetHistoricCandles(context.Background(), pair, asset.Spot, kline.OneDay, start, end) - if err != nil { - t.Fatal(err) + c, err := b.GetHistoricCandles(context.Background(), btcusdPair, asset.Spot, kline.OneDay, start, end) + assert.NoError(t, err, "GetHistoricCandles should not error") + assert.Equal(t, btcusdPair, c.Pair, "Pair should be correct") + assert.NotEmpty(t, c, "Candles should not be empty") + for _, req := range c.Candles { + assert.Positive(t, req.High, "High should be positive") + assert.Positive(t, req.Low, "Low should be positive") + assert.Positive(t, req.Close, "Close should be positive") + assert.Positive(t, req.Open, "Open should be positive") + assert.Positive(t, req.Volume, "Volume should be positive") + assert.NotEmpty(t, req.Time, "Time should not be empty") } } func TestBitstamp_GetHistoricCandlesExtended(t *testing.T) { - pair, err := currency.NewPairFromString("BTCUSD") - if err != nil { - t.Fatal(err) - } start := time.Unix(1546300800, 0) end := time.Unix(1577836799, 0) - _, err = b.GetHistoricCandlesExtended(context.Background(), pair, asset.Spot, kline.OneDay, start, end) - if err != nil { - t.Fatal(err) + c, err := b.GetHistoricCandlesExtended(context.Background(), btcusdPair, asset.Spot, kline.OneDay, start, end) + assert.NoError(t, err, "GetHistoricCandlesExtended should not error") + assert.Equal(t, btcusdPair, c.Pair, "Pair should be correct") + assert.NotEmpty(t, c, "Candles should not be empty") + for _, req := range c.Candles { + assert.Positive(t, req.High, "High should be positive") + assert.Positive(t, req.Low, "Low should be positive") + assert.Positive(t, req.Close, "Close should be positive") + assert.Positive(t, req.Open, "Open should be positive") + assert.Positive(t, req.Volume, "Volume should be positive") + assert.NotEmpty(t, req.Time, "Time should not be empty") } } func TestGetRecentTrades(t *testing.T) { t.Parallel() + currencyPair, err := currency.NewPairFromString("LTCUSD") - if err != nil { - t.Fatal(err) - } - _, err = b.GetRecentTrades(context.Background(), currencyPair, asset.Spot) - if err != nil { - t.Error(err) + assert.NoError(t, err, "NewPairFromString should not error") + + tr, err := b.GetRecentTrades(context.Background(), currencyPair, asset.Spot) + assert.NoError(t, err, "GetRecentTrades should not error") + assert.NotEmpty(t, tr, "Trades should not be empty") + for _, req := range tr { + assert.Positive(t, req.Amount, "Amount should be positive") + assert.Equal(t, currency.NewPairWithDelimiter("ltc", "usd", ""), req.CurrencyPair, "Pair should be correct") + assert.Equal(t, asset.Spot, req.AssetType, "AssetType should be set") + assert.NotEmpty(t, req.Timestamp, "Timestamp should not be empty") + assert.Positive(t, req.Price, "Price should be positive") + assert.NotEmpty(t, req.TID, "TID should not be empty") } } func TestGetHistoricTrades(t *testing.T) { t.Parallel() + currencyPair, err := currency.NewPairFromString("LTCUSD") - if err != nil { - t.Fatal(err) - } + assert.NoError(t, err, "NewPairFromString should not error") _, err = b.GetHistoricTrades(context.Background(), currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now()) - if err != nil && err != common.ErrFunctionNotSupported { - t.Error(err) - } + assert.ErrorIs(t, err, common.ErrFunctionNotSupported) } func TestOrderbookZeroBidPrice(t *testing.T) { t.Parallel() + ob := &orderbook.Base{ Exchange: "Bitstamp", - Pair: currency.NewPair(currency.BTC, currency.USD), + Pair: btcusdPair, Asset: asset.Spot, } - filterOrderbookZeroBidPrice(ob) - ob.Bids = orderbook.Items{ {Price: 69, Amount: 1337}, {Price: 0, Amount: 69}, } - filterOrderbookZeroBidPrice(ob) - if ob.Bids[0].Price != 69 || ob.Bids[0].Amount != 1337 || len(ob.Bids) != 1 { t.Error("invalid orderbook bid values") } - ob.Bids = orderbook.Items{ {Price: 59, Amount: 1337}, {Price: 42, Amount: 8595}, } - filterOrderbookZeroBidPrice(ob) - if ob.Bids[0].Price != 59 || ob.Bids[0].Amount != 1337 || ob.Bids[1].Price != 42 || ob.Bids[1].Amount != 8595 || len(ob.Bids) != 2 { t.Error("invalid orderbook bid values") @@ -958,29 +956,49 @@ func TestOrderbookZeroBidPrice(t *testing.T) { func TestGetWithdrawalsHistory(t *testing.T) { t.Parallel() - sharedtestvalues.SkipTestIfCredentialsUnset(t, b) - _, err := b.GetWithdrawalsHistory(context.Background(), currency.BTC, asset.Spot) - if err != nil { - t.Error(err) + + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + h, err := b.GetWithdrawalsHistory(context.Background(), currency.BTC, asset.Spot) + assert.NoError(t, err, "GetWithdrawalsHistory should not error") + if mockTests { + assert.NotEmpty(t, h, "WithdrawalHistory should not be empty") + for _, req := range h { + assert.Equal(t, time.Date(2022, time.January, 31, 16, 7, 32, 0, time.UTC), req.Timestamp, "Timestamp should match") + assert.Equal(t, "BTC", req.Currency, "Currency should match") + assert.Equal(t, 0.00006000, req.Amount, "Amount should match") + } } } - func TestGetOrderInfo(t *testing.T) { t.Parallel() - sharedtestvalues.SkipTestIfCredentialsUnset(t, b) - _, err := b.GetOrderInfo(context.Background(), "1234", currency.NewPair(currency.BTC, currency.USD), asset.Spot) - if err != nil { - t.Error(err) + + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) + } + o, err := b.GetOrderInfo(context.Background(), "1458532827766784", btcusdPair, asset.Spot) + if mockTests { + assert.NoError(t, err, "GetOrderInfo should not error") + assert.Equal(t, time.Date(2022, time.January, 31, 14, 43, 15, 0, time.UTC), o.Date, "order date should match") + assert.Equal(t, "1458532827766784", o.OrderID, "order ID should match") + assert.Equal(t, 200.00, o.Amount, "amount should match") + assert.Equal(t, 50.00, o.Price, "price should match") + } else { + assert.ErrorContains(t, err, "authenticated request failed Order not found") } } func TestFetchWSAuth(t *testing.T) { t.Parallel() - resp, err := b.FetchWSAuth(context.TODO()) - if assert.NoError(t, err, "FetchWSAuth should not error") { - assert.NotNil(t, resp, "resp should not be nil") - assert.Positive(t, resp.UserID, "UserID should be positive") - assert.Len(t, resp.Token, 32, "Token should be 32 chars") - assert.Positive(t, resp.ValidSecs, "ValidSecs should be positive") + + if !mockTests { + sharedtestvalues.SkipTestIfCredentialsUnset(t, b) } + resp, err := b.FetchWSAuth(context.TODO()) + assert.NoError(t, err, "FetchWSAuth should not error") + assert.NotNil(t, resp, "resp should not be nil") + assert.Positive(t, resp.UserID, "UserID should be positive") + assert.Len(t, resp.Token, 32, "Token should be 32 chars") + assert.Positive(t, resp.ValidSecs, "ValidSecs should be positive") } diff --git a/exchanges/bitstamp/bitstamp_types.go b/exchanges/bitstamp/bitstamp_types.go index 924a1931..41c32d34 100644 --- a/exchanges/bitstamp/bitstamp_types.go +++ b/exchanges/bitstamp/bitstamp_types.go @@ -24,15 +24,16 @@ var errWSPairParsingError = errors.New("unable to parse currency pair from wsRes // Ticker holds ticker information type Ticker struct { - Last float64 `json:"last,string"` - High float64 `json:"high,string"` - Low float64 `json:"low,string"` - Vwap float64 `json:"vwap,string"` - Volume float64 `json:"volume,string"` - Bid float64 `json:"bid,string"` - Ask float64 `json:"ask,string"` - Timestamp int64 `json:"timestamp,string"` - Open float64 `json:"open,string"` + Last float64 `json:"last,string"` + High float64 `json:"high,string"` + Low float64 `json:"low,string"` + Vwap float64 `json:"vwap,string"` + Volume float64 `json:"volume,string"` + Bid float64 `json:"bid,string"` + Ask float64 `json:"ask,string"` + Timestamp int64 `json:"timestamp,string"` + Open float64 `json:"open,string"` + Side orderSide `json:"side,string"` } // OrderbookBase holds singular price information @@ -166,12 +167,12 @@ type WithdrawalRequests struct { // CryptoWithdrawalResponse response from a crypto withdrawal request type CryptoWithdrawalResponse struct { - ID int64 `json:"id"` + ID int64 `json:"withdrawal_id"` } // FIATWithdrawalResponse response from a fiat withdrawal request type FIATWithdrawalResponse struct { - ID int64 `json:"id"` + ID int64 `json:"withdrawal_id"` } // UnconfirmedBTCTransactions holds address information about unconfirmed diff --git a/exchanges/kraken/kraken_test.go b/exchanges/kraken/kraken_test.go index 29418e38..263d70bf 100644 --- a/exchanges/kraken/kraken_test.go +++ b/exchanges/kraken/kraken_test.go @@ -2200,9 +2200,7 @@ func TestGetFuturesContractDetails(t *testing.T) { } _, err = k.GetFuturesContractDetails(context.Background(), asset.Futures) - if !errors.Is(err, nil) { - t.Error(err) - } + assert.NoError(t, err, "GetFuturesContractDetails should not error") } func TestGetLatestFundingRates(t *testing.T) { diff --git a/testdata/http_mock/bitstamp/bitstamp.json b/testdata/http_mock/bitstamp/bitstamp.json index a8bc4dae..40a6165c 100644 --- a/testdata/http_mock/bitstamp/bitstamp.json +++ b/testdata/http_mock/bitstamp/bitstamp.json @@ -14,6 +14,23 @@ } ] }, + "/api/ripple_address/": { + "POST": [ + { + "data": { + "address": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "destination_tag": 89473951 + }, + "queryString": "", + "bodyParams": "key=\u0026nonce=1560479820465818675\u0026signature=71962D6BBDFE3BF42BAC455E3A9C410FA90286148A6C299BAC1B44234072DA45", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + } + ] + }, "/api/bitcoin_withdrawal/": { "POST": [ { @@ -72,10 +89,27 @@ "POST": [ { "data": { - "error": "Order not found" + "id": "1458532827766784", + "datetime": "2022-01-31 14:43:15", + "type": 0, + "status": "Open", + "market": "BTC/USD", + "price":"50.00", + "transactions": [ + { + "tid": 1, + "price": "50.00", + "{from_currency}": "101.00", + "{to_currency}": "1", + "fee": "1.00", + "datetime": "2022-01-31 14:43:15", + "type": 0 + } + ], + "amount": "200.00" }, "queryString": "", - "bodyParams": "id=1337\u0026key=\u0026nonce=1560480481012757775\u0026signature=71E0C3A3B0CE4C96C9AC0C6519C3F4801A46C52C5C9BAAADB8642CE65F0CF385", + "bodyParams": "id=1458532827766784&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&nonce=1700374285822027000&signature=0B7C759A57B10EC315CE3A53480EDC720BE9BCD2CCEA86313808914484483386", "headers": { "Content-Type": [ "application/x-www-form-urlencoded" @@ -87,7 +121,11 @@ "/api/unconfirmed_btc/": { "POST": [ { - "data": [], + "data": [{ + "address": "0x6a56f5b80f04b4fd70d64d72e1396698635e5436", + "destination_tag": 89473951, + "memo_id": "299576079" + }], "queryString": "", "bodyParams": "key=\u0026nonce=1560479341665583985\u0026signature=8E4563D286BB5EEE45093DA708A8F78780B20CA5B1631E308E9C5CB64ACFE8D3", "headers": { @@ -105,7 +143,6 @@ "bch_available": "0.00000000", "bch_balance": "0.00000000", "bch_reserved": "0.00000000", - "bch_withdrawal_fee": "0.00000000", "bch_withdrawal_fee": "0.25", "btc_available": "9.1000000", "btc_balance": "11.20000000", @@ -157,7 +194,8 @@ { "maker": "0.3", "taker": "0.2" - } + }, + "market": "ltcbtc" }, "queryString": "", "bodyParams": "key=\u0026nonce=1690610275327495000\u0026signature=B619E1AEF317B95D3BB28025F36EEF94CABCDE425CE3E13E8A1861C0A9777F2A", @@ -178,14 +216,16 @@ "fees": { "maker": "0.3", "taker": "0.2" - } + }, + "market": "ltcbtc" }, { "currency_pair":"btcusd", "fees": { "maker": "0.3", "taker": "0.2" - } + }, + "market": "ltcbtc" } ], "queryString": "", @@ -202,15 +242,16 @@ "POST": [ { "data": { - "status": "error", - "reason": { - "__all__": [ - "You can only buy 0.00000000 BTC. Check your account balance for details." - ] - } + "id": "1234123412341234", + "market": "BTC/USD", + "datetime": "2022-01-31 14:43:15.796000", + "type": "0", + "price": "2211.00", + "amount": "45.00000000", + "client_order_id": "123456789" }, "queryString": "", - "bodyParams": "amount=1\u0026key=\u0026nonce=1560469416881040806\u0026price=1\u0026signature=D683BE07779B299B730F334C94758EBC56E264FC5C96C87B64E5ECC670421D65", + "bodyParams": "amount=45\u0026key=\u0026nonce=1560469416881040806\u0026price=1\u0026signature=D683BE07779B299B730F334C94758EBC56E264FC5C96C87B64E5ECC670421D65", "headers": { "Content-Type": [ "application/x-www-form-urlencoded" @@ -219,14 +260,40 @@ } ] }, + "/api/v2/buy/btcusd/": { + "POST": [ + { + "data": { + "id": "1234123412341234", + "market": "BTC/USD", + "datetime": "2022-01-31 14:43:15.796000", + "type": "1", + "price": "2211.00", + "amount": "45", + "client_order_id": "123456789" + }, + "queryString": "", + "bodyParams": "amount=45&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&nonce=1700378043980665000&price=2211&signature=2D0A359D16FCA1FD6185E9B8C007F294154AF296659AF2FF965695B6452B0C40", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + } + ] + }, "/api/v2/cancel_order/": { "POST": [ { "data": { - "error": "Order not found" + "id": 1453282316578816, + "amount": 0.02035278, + "price": 2100.45, + "type": 0, + "market": "BTC/USD" }, "queryString": "", - "bodyParams": "id=1234\u0026key=\u0026nonce=1560467884949723197\u0026signature=79D88FC2BC3AECBFDD27F70EF5DDBB485349F45129C58EE725BAEE0DF7818452", + "bodyParams": "id=1453282316578816\u0026key=\u0026nonce=1560467884949723197\u0026signature=79D88FC2BC3AECBFDD27F70EF5DDBB485349F45129C58EE725BAEE0DF7818452", "headers": { "Content-Type": [ "application/x-www-form-urlencoded" @@ -24378,7 +24445,18 @@ "/api/v2/open_orders/all/": { "POST": [ { - "data": [], + "data": [{ + "id": "1234123412341234", + "datetime": "2022-01-31 14:43:15", + "type": "0", + "price": "100.00", + "amount": "0.50000000", + "amount_at_create": "0.50000000", + "currency_pair": "BTC/USD", + "market": "BTC/USD", + "limit_price": "110.00", + "client_order_id": "1234123412341234" + }], "queryString": "", "bodyParams": "key=\u0026nonce=1560473214020947705\u0026signature=4530400B3F02B223F5AFE62DA3B18A09757A32882D9798B9AA78D70DE976316F", "headers": { @@ -24392,7 +24470,17 @@ "/api/v2/open_orders/btcusd/": { "POST": [ { - "data": [], + "data": [{ + "amount": "0.50000000", + "amount_at_create": "0.50000000", + "client_order_id": "1234123412341234", + "datetime": "2022-01-31 14:43:15", + "id": "1234123412341234", + "limit_price": "110.00", + "market": "BTC/USD", + "price": "100.00", + "type": "0" + }], "queryString": "", "bodyParams": "key=\u0026nonce=1560480749904299481\u0026signature=C1DCFCFC6E3122D12ACCA57178F781658DA6690DCAE4F56EC13998D5FCE9DF5D", "headers": { @@ -63767,16 +63855,19 @@ "GET": [ { "data": { - "high": "8335.56", - "last": "8213.59", - "timestamp": "1560482195", - "bid": "8210.38", - "vwap": "8190.45", - "volume": "6793.04518082", - "low": "8049.22", - "ask": "8213.59", - "open": "8235.44" - }, + "ask": "2211.00", + "bid": "2188.97", + "high": "2811.00", + "last": "2211.00", + "low": "2188.97", + "open": "2211.00", + "open_24": "2211.00", + "percent_change_24": "13.57", + "side": "0", + "timestamp": "1643640186", + "volume": "213.26801100", + "vwap": "2189.80" + }, "queryString": "", "bodyParams": "\u003cnil\u003e", "headers": {} @@ -67867,11 +67958,10 @@ { "data": { "code": "API0000", - "reason": "Missing key, signature and nonce parameters", - "status": "error" + "status": "ok" }, "queryString": "", - "bodyParams": "amount=0.01\u0026currency=btc\u0026key=\u0026nonce=1563774326032825427\u0026signature=0EEA71F2E4811F720A9C5D294D33A75404D2C0902C120D976A50B68946F699C9\u0026subAccount=testAccount", + "bodyParams": "amount=10000¤cy=BTC&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&nonce=1700382096969064000&signature=0EAAF413A980752F4018A6DD083B4AA9470AF839AD5862D8E803CAE8C6813C43&subAccount=1234567", "headers": { "Content-Type": [ "application/x-www-form-urlencoded" @@ -68216,15 +68306,10 @@ "POST": [ { "data": { - "status": "error", - "reason": { - "amount": [ - "You have only 0.00 USD available. Check your account balance for details." - ] - } + "withdrawal_id": 1 }, "queryString": "", - "bodyParams": "account_currency=USD\u0026address=123+Fake+St\u0026amount=-1\u0026bank_address=123+Fake+St\u0026bank_city=Tarry+Town\u0026bank_country=AU\u0026bank_name=Federal+Reserve+Bank\u0026bank_postal_code=2088\u0026bic=CTBAAU2S\u0026city=Tarry+Town\u0026comment=WITHDRAW+IT+ALL\u0026country=AU\u0026currency=USD\u0026iban=IT60X0542811101000000123456\u0026key=\u0026name=Satoshi+Nakamoto\u0026nonce=1560404081220544346\u0026postal_code=2088\u0026signature=17C71D3A9175255D46D786E9709B815E6C1B450B0E4E60B622EF35F0AD966B70\u0026type=international", + "bodyParams": "account_currency=USD&address=123+Fake+St&amount=10&bic=CTBAAU2S&city=Tarry+Town&comment=WITHDRAW+IT+ALL&country=AU&iban=IT60X0542811101000000123456&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&name=Satoshi+Nakamoto&nonce=1700299995971938000&postal_code=2088&signature=8FAD96A92BBA8F4D6599906E1553B0186A8503F97FA1581C838B5049BB253DAE&type=sepa", "headers": { "Content-Type": [ "application/x-www-form-urlencoded" @@ -68233,23 +68318,85 @@ }, { "data": { - "status": "error", - "reason": { - "amount": [ - "You have only 0.00 USD available. Check your account balance for details." - ] - } + "withdrawal_id": 1 }, "queryString": "", - "bodyParams": "account_currency=USD\u0026address=123+Fake+St\u0026amount=-1\u0026bic=CTBAAU2S\u0026city=Tarry+Town\u0026comment=WITHDRAW+IT+ALL\u0026country=AU\u0026iban=IT60X0542811101000000123456\u0026key=\u0026name=Satoshi+Nakamoto\u0026nonce=1560405334882045192\u0026postal_code=2088\u0026signature=1EB01441F5FB1FA1335EF5586D86F210101F641768C7568A4F9D592AA529628B\u0026type=sepa", + "bodyParams": "account_currency=USD&address=123+Fake+St&amount=50&bank_address=123+Fake+St&bank_city=Tarry+Town&bank_country=AU&bank_name=Federal+Reserve+Bank&bank_postal_code=2088&bic=CTBAAU2S&city=Tarry+Town&comment=WITHDRAW+IT+ALL&country=AU¤cy=USD&iban=IT60X0542811101000000123456&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&name=Satoshi+Nakamoto&nonce=1700301535927143000&postal_code=2088&signature=56886D87E0F1D4F3A197FC24B9D0CD1D17931B5E589ABF1D3B521AF3B45DBFEE&type=international", "headers": { "Content-Type": [ "application/x-www-form-urlencoded" ] } - } + }, + { + "data": { + "status": "error", + "reason": { + "amount": [ + "You have only 0.00 USD available. Check your account balance for details." + ] + } + }, + "queryString": "", + "bodyParams": "account_currency=USD&address=123+Fake+St&amount=10&bic=CTBAAU2S&city=Tarry+Town&comment=WITHDRAW+IT+ALL&country=AU&iban=IT60X0542811101000000123456&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&name=Satoshi+Nakamoto&nonce=1700299995971938000&postal_code=2088&signature=8FAD96A92BBA8F4D6599906E1553B0186A8503F97FA1581C838B5049BB253DAE&type=sepa", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + }, + { + "data": { + "status": "error", + "reason": { + "amount": [ + "You have only 0.00 USD available. Check your account balance for details." + ] + } + }, + "queryString": "", + "bodyParams": "account_currency=USD&address=123+Fake+St&amount=50&bank_address=123+Fake+St&bank_city=Tarry+Town&bank_country=AU&bank_name=Federal+Reserve+Bank&bank_postal_code=2088&bic=CTBAAU2S&city=Tarry+Town&comment=WITHDRAW+IT+ALL&country=AU¤cy=USD&iban=IT60X0542811101000000123456&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&name=Satoshi+Nakamoto&nonce=1702376984181107000&postal_code=2088&signature=7493E07560ED08C05D1BFE6E1726EB76EF90AD9DC874AD5DFE3EBB50D94C0940&type=international", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + } ] }, + "/api/v2/btc_withdrawal/": { + "POST": [ + { + "data": { + "withdrawal_id": 1 + }, + "queryString": "", + "bodyParams": "address=bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc&amount=6&key=FUId9Nby1VbZrGgZHfzGbswd4CDcp6Ar&nonce=1700299173646350000&signature=5D7281469C1E57BDAE13FF2C967F69B95C51A4496BEB92F040BC7345D517B911", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + }, + { + "data": { + "status": "error", + "reason": { + "amount": [ + "You have only 0.00 USD available. Check your account balance for details." + ] + } + }, + "queryString": "", + "bodyParams": "account_currency=USD\u0026address=123+Fake+St\u0026amount=-1\u0026bic=CTBAAU2S\u0026city=Tarry+Town\u0026comment=WITHDRAW+IT+ALL\u0026country=AU\u0026iban=IT60X0542811101000000123456\u0026key=\u0026name=Satoshi+Nakamoto\u0026nonce=1560405334882045192\u0026postal_code=2088\u0026signature=1EB01441F5FB1FA1335EF5586D86F210101F641768C7568A4F9D592AA529628B\u0026type=sepa", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + } + ] + }, "/api/v2/xrp_address/": { "POST": [ { @@ -68289,7 +68436,28 @@ "application/x-www-form-urlencoded" ] } - } + }, + { + "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=&nonce=1701424773861988000&signature=63D3A30E29FF85C814715111F8AC138B0D658C01D45A2EDDCE1E0F09B354DA88", + "headers": { + "Content-Type": [ + "application/x-www-form-urlencoded" + ] + } + } ] }, "/api/v2/websockets_token/": {