exchanges/qa: Add exchange wrapper testing suite (#1159)

* initial concept of a nice validation tester for exchanges

* adds some datahandler design

* expand testing

* more tests and fixes

* minor end of day fix for bithumb

* fixes implementation issues

* more test coverage and improvements, but not sure if i should continue

* fix more wrapper implementations

* adds error type, more fixes

* changes signature, fixes implementations

* fixes more wrapper implementations

* one more bit

* more cleanup

* WOW things work?

* lintle 1/1337

* mini bump

* fixes all linting

* neaten

* GetOrderInfo+ asset pair fixes+improvements

* adds new websocket test

* expand ws testing

* fix bug, expand tests, improve implementation

* code coverage of a lot of new codes

* fixes everything

* reverts accidental changes

* minor fixes from reviewing code

* removes Bitfinex cancelBatchOrder implementation

* fixes dumb baby typo for babies

* mini nit fixes

* so many nits to address

* addresses all the nits

* Titlecase

* switcheroo

* removes websocket testing for now

* fix appveyor, minor test fix

* fixes typo, re-kindles killed kode

* skip binance wrapper tests when running CI

* expired context, huobi okx fixes

* kodespull

* fix ordering

* time fix because why not

* fix exmo, others

* hopefully this fixes all of my life's problems

* last thing today

* huobi, more like hypotrophy

* golangci-lint, more like mypooroldknee-splint

* fix huobi times by removing them

* should fix okx currency issues

* blocks the application

* adds last little contingency for pairs

* addresses most nits and new problems

* lovely fixed before seeing why okx sucks

* fixes issues with okx websocket

* the classic receieieivaier

* lintle

* adds test and fixes existing tests

* expands error handling messages during setup

* fixes dumb okx bugs introduced

* quick fix for lint and exmo

* fixes nixes

* fix exmo deposit issue

* lint

* fixes issue with extra asset runs missing

* fix surprise race

* all the lint and merge fixes

* fixes surprise bugs in OKx

* fixes issues with times and chains

* fixing all the merge stuff

* merge fix

* rm logs and a panic potential

* lovely lint lament

* an easy demonstration of scenario, but not of initial purpose

* put it in the bin

* Revert "put it in the bin"

This reverts commit 15c6490f713233d43f10957367fcbf18e3818bdd.

* re-add after immediate error popup

* fix mini poor test design

* okx okay

* merge fixes

* fixes issues discovered in lovely test

* I FORGOT TO COMMIT THIS

* nit fixaroonaboo

* forgoetten test fix

* revert old okx asset intrument work

* fixes

* revert problems I didnt understand. update bybit

* fix merge bugs

* test cleanup

* further improvements

* reshuffle and lint

* rm redundant CI_TEST by rm the CI_TEST field that is redundant

* path fix

* move to its own section, dont run on 32 bit + appveyor

* lint

* fix lbank

* address nits

* let it rip

* fix failing test time range

* niteroo boogaloo

* mod tidy, use common.SimpleTimeFormat
This commit is contained in:
Scott
2023-07-03 11:09:43 +10:00
committed by GitHub
parent ef605a3c19
commit fcc5ad4551
210 changed files with 38548 additions and 6519 deletions

View File

@@ -303,7 +303,7 @@ func (i *ItBit) SendHTTPRequest(ctx context.Context, ep exchange.URL, path strin
return i.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
return item, nil
})
}, request.UnauthenticatedRequest)
}
// SendAuthenticatedHTTPRequest sends an authenticated request to itBit
@@ -368,13 +368,12 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.UR
Headers: headers,
Body: bytes.NewBuffer(PayloadJSON),
Result: &intermediary,
AuthRequest: true,
NonceEnabled: true,
Verbose: i.Verbose,
HTTPDebugging: i.HTTPDebugging,
HTTPRecording: i.HTTPRecording,
}, nil
})
}, request.AuthenticatedRequest)
if err != nil {
return err
}

View File

@@ -3,15 +3,13 @@ package itbit
import (
"context"
"errors"
"log"
"fmt"
"net/url"
"os"
"sync"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -31,28 +29,8 @@ const (
canManipulateRealOrders = false
)
func TestMain(m *testing.M) {
i.SetDefaults()
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Itbit load config error", err)
}
itbitConfig, err := cfg.GetExchangeConfig("ITBIT")
if err != nil {
log.Fatal("Itbit Setup() init error")
}
itbitConfig.API.AuthenticatedSupport = true
itbitConfig.API.Credentials.Key = apiKey
itbitConfig.API.Credentials.Secret = apiSecret
itbitConfig.API.Credentials.ClientID = clientID
err = i.Setup(itbitConfig)
if err != nil {
log.Fatal("Itbit setup error", err)
}
os.Exit(m.Run())
func TestMain(_ *testing.M) {
fmt.Println("ItBit API deprecated, skipping tests")
}
func TestStart(t *testing.T) {
@@ -131,7 +109,7 @@ func TestGetWalletTrades(t *testing.T) {
func TestGetFundingHistory(t *testing.T) {
_, err := i.GetFundingHistoryForWallet(context.Background(), "1337", url.Values{})
if err == nil {
t.Error("GetFundingHistory() Expected error")
t.Error("GetAccountFundingHistory() Expected error")
}
}
@@ -153,7 +131,8 @@ func TestGetOrder(t *testing.T) {
}
func TestCancelExistingOrder(t *testing.T) {
t.Skip()
sharedtestvalues.SkipTestIfCredentialsUnset(t, i, canManipulateRealOrders)
err := i.CancelExistingOrder(context.Background(), "1337", "1337order")
if err == nil {
t.Error("CancelOrder() Expected error")
@@ -286,7 +265,7 @@ func TestFormatWithdrawPermissions(t *testing.T) {
func TestGetActiveOrders(t *testing.T) {
t.Parallel()
var getOrdersRequest = order.GetOrdersRequest{
var getOrdersRequest = order.MultiOrderRequest{
Type: order.AnyType,
AssetType: asset.Spot,
Side: order.AnySide,
@@ -303,7 +282,7 @@ func TestGetActiveOrders(t *testing.T) {
func TestGetOrderHistory(t *testing.T) {
t.Parallel()
var getOrdersRequest = order.GetOrdersRequest{
var getOrdersRequest = order.MultiOrderRequest{
Type: order.AnyType,
AssetType: asset.Spot,
Side: order.AnySide,

View File

@@ -135,6 +135,11 @@ func (i *ItBit) Run(_ context.Context) {
}
}
// GetServerTime returns the current exchange server time.
func (i *ItBit) GetServerTime(_ context.Context, _ asset.Item) (time.Time, error) {
return time.Time{}, common.ErrFunctionNotSupported
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (i *ItBit) FetchTradablePairs(_ context.Context, _ asset.Item) (currency.Pairs, error) {
return nil, common.ErrFunctionNotSupported
@@ -153,12 +158,12 @@ func (i *ItBit) UpdateTickers(_ context.Context, _ asset.Item) error {
// UpdateTicker updates and returns the ticker for a currency pair
func (i *ItBit) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
fpair, err := i.FormatExchangeCurrency(p, a)
fPair, err := i.FormatExchangeCurrency(p, a)
if err != nil {
return nil, err
}
tick, err := i.GetTicker(ctx, fpair.String())
tick, err := i.GetTicker(ctx, fPair.String())
if err != nil {
return nil, err
}
@@ -202,6 +207,12 @@ func (i *ItBit) FetchOrderbook(ctx context.Context, p currency.Pair, assetType a
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (i *ItBit) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
if p.IsEmpty() {
return nil, currency.ErrCurrencyPairEmpty
}
if err := i.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
return nil, err
}
book := &orderbook.Base{
Exchange: i.Name,
Pair: p,
@@ -209,12 +220,12 @@ func (i *ItBit) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType
PriceDuplication: true,
VerifyOrderbook: i.CanVerifyOrderbook,
}
fpair, err := i.FormatExchangeCurrency(p, assetType)
fPair, err := i.FormatExchangeCurrency(p, assetType)
if err != nil {
return book, err
}
orderbookNew, err := i.GetOrderbook(ctx, fpair.String())
orderbookNew, err := i.GetOrderbook(ctx, fPair.String())
if err != nil {
return book, err
}
@@ -323,14 +334,14 @@ func (i *ItBit) FetchAccountInfo(ctx context.Context, assetType asset.Item) (acc
return acc, nil
}
// GetFundingHistory returns funding history, deposits and
// GetAccountFundingHistory returns funding history, deposits and
// withdrawals
func (i *ItBit) GetFundingHistory(_ context.Context) ([]exchange.FundHistory, error) {
func (i *ItBit) GetAccountFundingHistory(_ context.Context) ([]exchange.FundingHistory, error) {
return nil, common.ErrFunctionNotSupported
}
// GetWithdrawalsHistory returns previous withdrawals data
func (i *ItBit) GetWithdrawalsHistory(_ context.Context, _ currency.Code, _ asset.Item) (resp []exchange.WithdrawalHistory, err error) {
func (i *ItBit) GetWithdrawalsHistory(_ context.Context, _ currency.Code, _ asset.Item) ([]exchange.WithdrawalHistory, error) {
return nil, common.ErrNotYetImplemented
}
@@ -445,8 +456,8 @@ func (i *ItBit) CancelOrder(ctx context.Context, o *order.Cancel) error {
}
// CancelBatchOrders cancels an orders by their corresponding ID numbers
func (i *ItBit) CancelBatchOrders(_ context.Context, _ []order.Cancel) (order.CancelBatchResponse, error) {
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
func (i *ItBit) CancelBatchOrders(_ context.Context, _ []order.Cancel) (*order.CancelBatchResponse, error) {
return nil, common.ErrNotYetImplemented
}
// CancelAllOrders cancels all orders associated with a currency pair
@@ -480,14 +491,13 @@ func (i *ItBit) CancelAllOrders(ctx context.Context, orderCancellation *order.Ca
}
// GetOrderInfo returns order information based on order ID
func (i *ItBit) GetOrderInfo(_ context.Context, _ string, _ currency.Pair, _ asset.Item) (order.Detail, error) {
var orderDetail order.Detail
return orderDetail, common.ErrNotYetImplemented
func (i *ItBit) GetOrderInfo(_ context.Context, _ string, _ currency.Pair, _ asset.Item) (*order.Detail, error) {
return nil, common.ErrNotYetImplemented
}
// GetDepositAddress returns a deposit address for a specified currency
// NOTE: This has not been implemented due to the fact you need to generate a
// specific wallet ID and they restrict the amount of deposit addresses you can
// specific wallet ID, and they restrict the amount of deposit addresses you can
// request limiting them to 2.
func (i *ItBit) GetDepositAddress(_ context.Context, _ currency.Code, _, _ string) (*deposit.Address, error) {
return nil, common.ErrNotYetImplemented
@@ -524,7 +534,7 @@ func (i *ItBit) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilde
}
// GetActiveOrders retrieves any orders that are active/open
func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
err := req.Validate()
if err != nil {
return nil, err
@@ -578,7 +588,7 @@ func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest
Side: side,
Amount: allOrders[j].Amount,
ExecutedAmount: allOrders[j].AmountFilled,
RemainingAmount: (allOrders[j].Amount - allOrders[j].AmountFilled),
RemainingAmount: allOrders[j].Amount - allOrders[j].AmountFilled,
Exchange: i.Name,
Date: orderDate,
Pair: symbol,
@@ -589,7 +599,7 @@ func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
err := req.Validate()
if err != nil {
return nil, err