mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +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:
@@ -842,14 +842,20 @@ func (s *RPCServer) SubmitOrder(_ context.Context, r *gctrpc.SubmitOrderRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a := asset.Item(r.AssetType)
|
||||
if !asset.IsValid(a) {
|
||||
return nil, fmt.Errorf("asset type: %s is invalid", a)
|
||||
}
|
||||
|
||||
submission := &order.Submit{
|
||||
Pair: p,
|
||||
Side: order.Side(r.Side),
|
||||
Type: order.Type(r.OrderType),
|
||||
Amount: r.Amount,
|
||||
Price: r.Price,
|
||||
ClientID: r.ClientId,
|
||||
Exchange: r.Exchange,
|
||||
Pair: p,
|
||||
Side: order.Side(r.Side),
|
||||
Type: order.Type(r.OrderType),
|
||||
Amount: r.Amount,
|
||||
Price: r.Price,
|
||||
ClientID: r.ClientId,
|
||||
Exchange: r.Exchange,
|
||||
AssetType: a,
|
||||
}
|
||||
|
||||
resp, err := exch.SubmitOrder(submission)
|
||||
@@ -958,12 +964,18 @@ func (s *RPCServer) CancelOrder(_ context.Context, r *gctrpc.CancelOrderRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a := asset.Item(r.AssetType)
|
||||
if !asset.IsValid(a) {
|
||||
return nil, fmt.Errorf("asset type: %s is invalid", a)
|
||||
}
|
||||
|
||||
err = exch.CancelOrder(&order.Cancel{
|
||||
AccountID: r.AccountId,
|
||||
ID: r.OrderId,
|
||||
Side: order.Side(r.Side),
|
||||
WalletAddress: r.WalletAddress,
|
||||
Pair: p,
|
||||
AssetType: a,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1045,18 +1057,19 @@ func (s *RPCServer) WithdrawCryptocurrencyFunds(_ context.Context, r *gctrpc.Wit
|
||||
}
|
||||
|
||||
request := &withdraw.Request{
|
||||
Exchange: r.Exchange,
|
||||
Amount: r.Amount,
|
||||
Currency: currency.NewCode(strings.ToUpper(r.Currency)),
|
||||
Type: withdraw.Crypto,
|
||||
Description: r.Description,
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: r.Address,
|
||||
AddressTag: r.AddressTag,
|
||||
FeeAmount: r.Fee,
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := SubmitWithdrawal(r.Exchange, request)
|
||||
resp, err := SubmitWithdrawal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1088,15 +1101,17 @@ func (s *RPCServer) WithdrawFiatFunds(_ context.Context, r *gctrpc.WithdrawFiatR
|
||||
}
|
||||
|
||||
request := &withdraw.Request{
|
||||
Exchange: r.Exchange,
|
||||
Amount: r.Amount,
|
||||
Currency: currency.NewCode(strings.ToUpper(r.Currency)),
|
||||
Type: withdraw.Fiat,
|
||||
Description: r.Description,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: bankAccount,
|
||||
Fiat: withdraw.FiatRequest{
|
||||
Bank: *bankAccount,
|
||||
},
|
||||
}
|
||||
resp, err := SubmitWithdrawal(r.Exchange, request)
|
||||
|
||||
resp, err := SubmitWithdrawal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1153,7 +1168,7 @@ func (s *RPCServer) WithdrawalEventByID(_ context.Context, r *gctrpc.WithdrawalE
|
||||
Fee: v.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
} else if v.RequestDetails.Type == withdraw.Fiat {
|
||||
if v.RequestDetails.Fiat != nil {
|
||||
if v.RequestDetails.Fiat != (withdraw.FiatRequest{}) {
|
||||
resp.Event.Request.Fiat = new(gctrpc.FiatWithdrawalEvent)
|
||||
resp.Event.Request.Fiat = &gctrpc.FiatWithdrawalEvent{
|
||||
BankName: v.RequestDetails.Fiat.Bank.BankName,
|
||||
|
||||
Reference in New Issue
Block a user