mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 15:10:42 +00:00
(Exchanges) Introduce validation method and small updates (#565)
* Remove pointer reference * Fix portfolio withdraw tests * Add nil protection in validator method to reduce prospective panics and for future outbound checking * Updated tests * ch order var to not ref package * rm comparison * Add order ID validation check * Add exchange name validation check * Add in test details * fix tests * fix linter issues * linter issues strikes again * linter rabbit hole * Addr nitterinos * Add validation variadic interface to define sets of functionality check POC * didn't want to add an amount other than 0, didn't want to add address to exchange withdraw, didn't want to whitlist, can change if need be * add coverage * Add validation method options for exchange wrappers and abstracted validation into its own package * Add validation code for structs in exchange template generation * remove extra validation call as this is done in wrapper * fix niterinos for examplerinos * Add template to documentation tool and regenerated documentation * Addr niticles * Fix tests due to validation update * Add more validation checks for modify/submit orders * update tests * fix more tests * Add asset type to submit variable in tests and rpc call. Regen funcs. * Add field to modify struct in tests * applied field asset to cancel struct across project * fix woopsy
This commit is contained in:
@@ -318,7 +318,7 @@ func ExchangeOrderCancel(args ...objects.Object) (objects.Object, error) {
|
||||
|
||||
// ExchangeOrderSubmit submit order on exchange
|
||||
func ExchangeOrderSubmit(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 8 {
|
||||
if len(args) != 9 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
@@ -334,6 +334,10 @@ func ExchangeOrderSubmit(args ...objects.Object) (objects.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, delimiter)
|
||||
}
|
||||
pair, err := currency.NewPairDelimiter(currencyPair, delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderType, ok := objects.ToString(args[3])
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, orderType)
|
||||
@@ -354,23 +358,23 @@ func ExchangeOrderSubmit(args ...objects.Object) (objects.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, orderClientID)
|
||||
}
|
||||
pair, err := currency.NewPairDelimiter(currencyPair, delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
assetType, ok := objects.ToString(args[8])
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, orderClientID)
|
||||
}
|
||||
a := asset.Item(assetType)
|
||||
if !asset.IsValid(a) {
|
||||
return nil, fmt.Errorf("asset type: %s is invalid", a)
|
||||
}
|
||||
|
||||
tempSubmit := &order.Submit{
|
||||
Pair: pair,
|
||||
Type: order.Type(orderType),
|
||||
Side: order.Side(orderSide),
|
||||
Price: orderPrice,
|
||||
Amount: orderAmount,
|
||||
ClientID: orderClientID,
|
||||
}
|
||||
|
||||
err = tempSubmit.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
Pair: pair,
|
||||
Type: order.Type(orderType),
|
||||
Side: order.Side(orderSide),
|
||||
Price: orderPrice,
|
||||
Amount: orderAmount,
|
||||
ClientID: orderClientID,
|
||||
AssetType: a,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().SubmitOrder(tempSubmit)
|
||||
@@ -452,7 +456,8 @@ func ExchangeWithdrawCrypto(args ...objects.Object) (objects.Object, error) {
|
||||
}
|
||||
|
||||
withdrawRequest := &withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Exchange: exchangeName,
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: address,
|
||||
AddressTag: addressTag,
|
||||
FeeAmount: feeAmount,
|
||||
@@ -462,7 +467,7 @@ func ExchangeWithdrawCrypto(args ...objects.Object) (objects.Object, error) {
|
||||
Amount: amount,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalCryptoFunds(exchangeName, withdrawRequest)
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalCryptoFunds(withdrawRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -498,12 +503,13 @@ func ExchangeWithdrawFiat(args ...objects.Object) (objects.Object, error) {
|
||||
}
|
||||
|
||||
withdrawRequest := &withdraw.Request{
|
||||
Exchange: exchangeName,
|
||||
Currency: currency.NewCode(cur),
|
||||
Description: description,
|
||||
Amount: amount,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalFiatFunds(exchangeName, bankAccountID, withdrawRequest)
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalFiatFunds(bankAccountID, withdrawRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
objects "github.com/d5/tengo/v2"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctscript/modules"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctscript/wrappers/validator"
|
||||
)
|
||||
@@ -191,21 +192,22 @@ func TestExchangeOrderSubmit(t *testing.T) {
|
||||
orderType := &objects.String{Value: "LIMIT"}
|
||||
orderPrice := &objects.Float{Value: 1}
|
||||
orderAmount := &objects.Float{Value: 1}
|
||||
orderAsset := &objects.String{Value: asset.Spot.String()}
|
||||
|
||||
_, err = ExchangeOrderSubmit(exch, currencyPair, delimiter,
|
||||
orderType, orderSide, orderPrice, orderAmount, orderID)
|
||||
orderType, orderSide, orderPrice, orderAmount, orderID, orderAsset)
|
||||
if err != nil && !errors.Is(err, errTestFailed) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = ExchangeOrderSubmit(exch, currencyPair, delimiter,
|
||||
orderType, orderSide, orderPrice, orderAmount, orderID)
|
||||
orderType, orderSide, orderPrice, orderAmount, orderID, orderAsset)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = ExchangeOrderSubmit(objects.TrueValue, currencyPair, delimiter,
|
||||
orderType, orderSide, orderPrice, orderAmount, orderID)
|
||||
orderType, orderSide, orderPrice, orderAmount, orderID, orderAsset)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ type Exchange interface {
|
||||
CancelOrder(exch, orderid string) (bool, error)
|
||||
AccountInformation(exch string) (account.Holdings, error)
|
||||
DepositAddress(exch string, currencyCode currency.Code) (string, error)
|
||||
WithdrawalFiatFunds(exch, bankAccountID string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalCryptoFunds(exch string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalFiatFunds(bankAccountID string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalCryptoFunds(request *withdraw.Request) (out string, err error)
|
||||
OHLCV(exch string, pair currency.Pair, item asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user