(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:
Ryan O'Hara-Reid
2020-10-02 13:36:01 +10:00
committed by GitHub
parent ecbc68561f
commit 4e828a8124
93 changed files with 3070 additions and 1676 deletions

View File

@@ -14,7 +14,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
@@ -387,11 +386,12 @@ func TestSubmitOrder(t *testing.T) {
Base: currency.BTC,
Quote: currency.LTC,
},
Side: order.Buy,
Type: order.Limit,
Price: 1,
Amount: 1,
ClientID: "meowOrder",
Side: order.Buy,
Type: order.Limit,
Price: 1,
Amount: 1,
ClientID: "meowOrder",
AssetType: asset.Spot,
}
response, err := b.SubmitOrder(orderSubmission)
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
@@ -413,6 +413,7 @@ func TestCancelExchangeOrder(t *testing.T) {
WalletAddress: core.BitcoinDonationAddress,
AccountID: "1",
Pair: currencyPair,
AssetType: asset.Spot,
}
err := b.CancelOrder(orderCancellation)
@@ -436,6 +437,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
WalletAddress: core.BitcoinDonationAddress,
AccountID: "1",
Pair: currencyPair,
AssetType: asset.Spot,
}
resp, err := b.CancelAllOrders(orderCancellation)
@@ -474,11 +476,13 @@ func TestModifyOrder(t *testing.T) {
t.Fatal(err)
}
_, err = b.ModifyOrder(&order.Modify{
ID: "1337",
Price: 100,
Amount: 1000,
Side: order.Sell,
Pair: curr})
ID: "1337",
Price: 100,
Amount: 1000,
Side: order.Sell,
Pair: curr,
AssetType: asset.Spot,
})
if err == nil {
t.Error("ModifyOrder() Expected error")
}
@@ -494,7 +498,7 @@ func TestWithdraw(t *testing.T) {
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Crypto: &withdraw.CryptoRequest{
Crypto: withdraw.CryptoRequest{
Address: core.BitcoinDonationAddress,
},
}
@@ -515,8 +519,7 @@ func TestWithdrawFiat(t *testing.T) {
}
var withdrawFiatRequest = withdraw.Request{
Fiat: &withdraw.FiatRequest{
Bank: &banking.Account{},
Fiat: withdraw.FiatRequest{
WireCurrency: currency.KRW.String(),
RequiresIntermediaryBank: false,
IsExpressWire: false,

View File

@@ -337,6 +337,10 @@ func (b *Bithumb) GetExchangeHistory(p currency.Pair, assetType asset.Item, time
// SubmitOrder submits a new order
// TODO: Fill this out to support limit orders
func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
if err := s.Validate(); err != nil {
return order.SubmitResponse{}, err
}
var submitOrderResponse order.SubmitResponse
if err := s.Validate(); err != nil {
return submitOrderResponse, err
@@ -371,6 +375,10 @@ func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Bithumb) ModifyOrder(action *order.Modify) (string, error) {
if err := action.Validate(); err != nil {
return "", err
}
order, err := b.ModifyTrade(action.ID,
action.Pair.Base.String(),
action.Side.Lower(),
@@ -385,15 +393,23 @@ func (b *Bithumb) ModifyOrder(action *order.Modify) (string, error) {
}
// CancelOrder cancels an order by its corresponding ID number
func (b *Bithumb) CancelOrder(order *order.Cancel) error {
_, err := b.CancelTrade(order.Side.String(),
order.ID,
order.Pair.Base.String())
func (b *Bithumb) CancelOrder(o *order.Cancel) error {
if err := o.Validate(o.StandardCancel()); err != nil {
return err
}
_, err := b.CancelTrade(o.Side.String(),
o.ID,
o.Pair.Base.String())
return err
}
// CancelAllOrders cancels all orders associated with a currency pair
func (b *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
if err := orderCancellation.Validate(); err != nil {
return order.CancelAllResponse{}, err
}
cancelAllOrdersResponse := order.CancelAllResponse{
Status: make(map[string]string),
}
@@ -447,6 +463,10 @@ func (b *Bithumb) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
v, err := b.WithdrawCrypto(withdrawRequest.Crypto.Address,
withdrawRequest.Crypto.AddressTag,
withdrawRequest.Currency.String(),
@@ -463,6 +483,10 @@ func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request)
// WithdrawFiatFunds returns a withdrawal ID when a
// withdrawal is submitted
func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
if math.Mod(withdrawRequest.Amount, 1) != 0 {
return nil, errors.New("currency KRW does not support decimal places")
}
@@ -500,6 +524,9 @@ func (b *Bithumb) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
// GetActiveOrders retrieves any orders that are active/open
func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
var orders []order.Detail
resp, err := b.GetOrders("", "", "1000", "", "")
if err != nil {
@@ -548,6 +575,10 @@ func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
var orders []order.Detail
resp, err := b.GetOrders("", "", "1000", "", "")
if err != nil {