mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 15:10:49 +00:00
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:
@@ -940,13 +940,13 @@ func TestSetCollateralCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
var expectedError = errExchangeNameEmpty
|
||||
pc := SetupPositionController()
|
||||
err := pc.SetCollateralCurrency("", asset.Spot, currency.Pair{}, currency.Code{})
|
||||
err := pc.SetCollateralCurrency("", asset.Spot, currency.EMPTYPAIR, currency.Code{})
|
||||
if !errors.Is(err, expectedError) {
|
||||
t.Errorf("received '%v' expected '%v", err, expectedError)
|
||||
}
|
||||
|
||||
expectedError = ErrNotFuturesAsset
|
||||
err = pc.SetCollateralCurrency("hi", asset.Spot, currency.Pair{}, currency.Code{})
|
||||
err = pc.SetCollateralCurrency("hi", asset.Spot, currency.EMPTYPAIR, currency.Code{})
|
||||
if !errors.Is(err, expectedError) {
|
||||
t.Errorf("received '%v' expected '%v", err, expectedError)
|
||||
}
|
||||
@@ -1012,7 +1012,7 @@ func TestSetCollateralCurrency(t *testing.T) {
|
||||
}
|
||||
|
||||
var nilPC *PositionController
|
||||
err = nilPC.SetCollateralCurrency("hi", asset.Spot, currency.Pair{}, currency.Code{})
|
||||
err = nilPC.SetCollateralCurrency("hi", asset.Spot, currency.EMPTYPAIR, currency.Code{})
|
||||
expectedError = common.ErrNilPointer
|
||||
if !errors.Is(err, expectedError) {
|
||||
t.Errorf("received '%v' expected '%v", err, expectedError)
|
||||
|
||||
@@ -165,7 +165,6 @@ func (e *ExecutionLimits) LoadLimits(levels []MinMaxLevel) error {
|
||||
func (e *ExecutionLimits) GetOrderExecutionLimits(a asset.Item, cp currency.Pair) (MinMaxLevel, error) {
|
||||
e.mtx.RLock()
|
||||
defer e.mtx.RUnlock()
|
||||
|
||||
if e.m == nil {
|
||||
return MinMaxLevel{}, ErrExchangeLimitNotLoaded
|
||||
}
|
||||
|
||||
@@ -263,6 +263,14 @@ func TestOrderSides(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitle(t *testing.T) {
|
||||
t.Parallel()
|
||||
orderType := Limit
|
||||
if orderType.Title() != "Limit" {
|
||||
t.Errorf("received '%v' expected 'Limit'", orderType.Title())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderTypes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -1316,13 +1324,13 @@ func TestValidationOnOrderTypes(t *testing.T) {
|
||||
t.Fatal("should return nil")
|
||||
}
|
||||
|
||||
var getOrders *GetOrdersRequest
|
||||
var getOrders *MultiOrderRequest
|
||||
err = getOrders.Validate()
|
||||
if !errors.Is(err, ErrGetOrdersRequestIsNil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, ErrGetOrdersRequestIsNil)
|
||||
}
|
||||
|
||||
getOrders = new(GetOrdersRequest)
|
||||
getOrders = new(MultiOrderRequest)
|
||||
err = getOrders.Validate()
|
||||
if !errors.Is(err, asset.ErrNotSupported) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, asset.ErrNotSupported)
|
||||
@@ -1897,7 +1905,7 @@ func TestDeriveCancel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOrdersRequest_Filter(t *testing.T) {
|
||||
request := new(GetOrdersRequest)
|
||||
request := new(MultiOrderRequest)
|
||||
request.AssetType = asset.Spot
|
||||
request.Type = AnyType
|
||||
request.Side = AnySide
|
||||
|
||||
@@ -23,6 +23,8 @@ var (
|
||||
ErrAmountIsInvalid = errors.New("order amount is equal or less than zero")
|
||||
ErrPriceMustBeSetIfLimitOrder = errors.New("order price must be set if limit order type is desired")
|
||||
ErrOrderIDNotSet = errors.New("order id or client order id is not set")
|
||||
ErrClientOrderIDNotSupported = errors.New("client order id not supported")
|
||||
ErrUnsupportedOrderType = errors.New("unsupported order type")
|
||||
// ErrNoRates is returned when no margin rates are returned when they are expected
|
||||
ErrNoRates = errors.New("no rates")
|
||||
|
||||
@@ -253,17 +255,19 @@ type TradeHistory struct {
|
||||
Total float64
|
||||
}
|
||||
|
||||
// GetOrdersRequest used for GetOrderHistory and GetOpenOrders wrapper functions
|
||||
type GetOrdersRequest struct {
|
||||
Type Type
|
||||
Side Side
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
OrderID string
|
||||
// MultiOrderRequest used for GetOrderHistory and GetOpenOrders wrapper functions
|
||||
type MultiOrderRequest struct {
|
||||
// Currencies Empty array = all currencies. Some endpoints only support
|
||||
// singular currency enquiries
|
||||
Pairs currency.Pairs
|
||||
AssetType asset.Item
|
||||
Type Type
|
||||
Side Side
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
// FromOrderID for some APIs require order history searching
|
||||
// from a specific orderID rather than via timestamps
|
||||
FromOrderID string
|
||||
}
|
||||
|
||||
// Status defines order status types
|
||||
@@ -368,5 +372,5 @@ type ClassificationError struct {
|
||||
|
||||
// FilteredOrders defines orders that have been filtered at the wrapper level
|
||||
// forcing required filter operations when calling method Filter() on
|
||||
// GetOrdersRequest.
|
||||
// MultiOrderRequest.
|
||||
type FilteredOrders []Detail
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/validate"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,6 +31,8 @@ var (
|
||||
// ErrUnableToPlaceOrder defines an error when an order submission has
|
||||
// failed.
|
||||
ErrUnableToPlaceOrder = errors.New("order not placed")
|
||||
// ErrOrderNotFound is returned when no order is found
|
||||
ErrOrderNotFound = errors.New("order not found")
|
||||
|
||||
errTimeInForceConflict = errors.New("multiple time in force options applied")
|
||||
errUnrecognisedOrderSide = errors.New("unrecognised order side")
|
||||
@@ -694,7 +698,7 @@ func (t Type) Lower() string {
|
||||
|
||||
// Title returns the type titleized, eg "Limit"
|
||||
func (t Type) Title() string {
|
||||
return strings.Title(strings.ToLower(t.String()))
|
||||
return cases.Title(language.English).String(t.String())
|
||||
}
|
||||
|
||||
// String implements the stringer interface
|
||||
@@ -747,7 +751,7 @@ func (s Side) Lower() string {
|
||||
|
||||
// Title returns the side titleized, eg "Buy"
|
||||
func (s Side) Title() string {
|
||||
return strings.Title(strings.ToLower(s.String()))
|
||||
return cases.Title(language.English).String(s.String())
|
||||
}
|
||||
|
||||
// IsShort returns if the side is short
|
||||
@@ -1186,7 +1190,7 @@ func (c *Cancel) Validate(opt ...validate.Checker) error {
|
||||
|
||||
// Validate checks internal struct requirements and returns filter requirement
|
||||
// options for wrapper standardization procedures.
|
||||
func (g *GetOrdersRequest) Validate(opt ...validate.Checker) error {
|
||||
func (g *MultiOrderRequest) Validate(opt ...validate.Checker) error {
|
||||
if g == nil {
|
||||
return ErrGetOrdersRequestIsNil
|
||||
}
|
||||
@@ -1214,7 +1218,7 @@ func (g *GetOrdersRequest) Validate(opt ...validate.Checker) error {
|
||||
}
|
||||
|
||||
// Filter reduces slice by optional fields
|
||||
func (g *GetOrdersRequest) Filter(exch string, orders []Detail) FilteredOrders {
|
||||
func (g *MultiOrderRequest) Filter(exch string, orders []Detail) FilteredOrders {
|
||||
filtered := make([]Detail, len(orders))
|
||||
copy(filtered, orders)
|
||||
FilterOrdersByPairs(&filtered, g.Pairs)
|
||||
|
||||
Reference in New Issue
Block a user