diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 08465fca..443bf7f7 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -2,6 +2,7 @@ package exchange import ( "errors" + "fmt" "log" "net/http" "sync" @@ -475,6 +476,10 @@ func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) { // SetCurrencies sets the exchange currency pairs for either enabledPairs or // availablePairs func (e *Base) SetCurrencies(pairs []pair.CurrencyPair, enabledPairs bool) error { + if len(pairs) == 0 { + return fmt.Errorf("%s SetCurrencies error - pairs is empty", e.Name) + } + cfg := config.GetConfig() exchCfg, err := cfg.GetExchangeConfig(e.Name) if err != nil { @@ -501,6 +506,10 @@ func (e *Base) SetCurrencies(pairs []pair.CurrencyPair, enabledPairs bool) error // UpdateCurrencies updates the exchange currency pairs for either enabledPairs or // availablePairs func (e *Base) UpdateCurrencies(exchangeProducts []string, enabled, force bool) error { + if len(exchangeProducts) == 0 { + return fmt.Errorf("%s UpdateCurrencies error - exchangeProducts is empty", e.Name) + } + exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",") var products []string diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index 549788e1..b48e9466 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -669,6 +669,11 @@ func TestSetCurrencies(t *testing.T) { if !pair.Contains(UAC.GetAvailableCurrencies(), newPair, true) { t.Fatal("Test failed. TestSetCurrencies failed to set currencies") } + + err = UAC.SetCurrencies(nil, false) + if err == nil { + t.Fatal("Test failed. TestSetCurrencies should return an error when attempting to set an empty pairs array") + } } func TestUpdateCurrencies(t *testing.T) { @@ -744,6 +749,13 @@ func TestUpdateCurrencies(t *testing.T) { if err != nil { t.Errorf("Test Failed - Forced Exchange UpdateCurrencies() error: %s", err) } + + // Test that empty exchange products should return an error + exchangeProducts = nil + err = UAC.UpdateCurrencies(exchangeProducts, false, false) + if err == nil { + t.Errorf("Test failed - empty available pairs should return an error") + } } func TestAPIURL(t *testing.T) {