diff --git a/config/config.go b/config/config.go index c0694d34..996a1aed 100644 --- a/config/config.go +++ b/config/config.go @@ -610,7 +610,7 @@ func (c *Config) GetEnabledPairs(exchName string) (currency.Pairs, error) { return nil, err } - return exchCfg.AvailablePairs.Format(exchCfg.ConfigCurrencyPairFormat.Delimiter, + return exchCfg.EnabledPairs.Format(exchCfg.ConfigCurrencyPairFormat.Delimiter, exchCfg.ConfigCurrencyPairFormat.Index, exchCfg.ConfigCurrencyPairFormat.Uppercase), nil } diff --git a/currency/pairs.go b/currency/pairs.go index 8d2bf3f5..53c468a6 100644 --- a/currency/pairs.go +++ b/currency/pairs.go @@ -4,6 +4,7 @@ import ( "math/rand" "github.com/thrasher-/gocryptotrader/common" + log "github.com/thrasher-/gocryptotrader/logger" ) // NewPairsFromStrings takes in currency pair strings and returns a currency @@ -41,19 +42,25 @@ func (p Pairs) Join() string { func (p Pairs) Format(delimiter, index string, uppercase bool) Pairs { var pairs Pairs for i := range p { - var formattedPair Pair - formattedPair.Delimiter = delimiter - formattedPair.Base = p[i].Base - formattedPair.Quote = p[i].Quote - + var formattedPair = Pair{ + Delimiter: delimiter, + Base: p[i].Base, + Quote: p[i].Quote, + } if index != "" { - formattedPair.Quote = NewCode(index) + newP, err := NewPairFromIndex(p[i].String(), index) + if err != nil { + log.Errorf("failed to create NewPairFromIndex. Err: %s", err) + continue + } + formattedPair.Base = newP.Base + formattedPair.Quote = newP.Quote } if uppercase { pairs = append(pairs, formattedPair.Upper()) } else { - pairs = append(pairs, formattedPair) + pairs = append(pairs, formattedPair.Lower()) } } return pairs diff --git a/currency/pairs_test.go b/currency/pairs_test.go index 98055708..bcf435d5 100644 --- a/currency/pairs_test.go +++ b/currency/pairs_test.go @@ -50,13 +50,19 @@ func TestPairsFormat(t *testing.T) { expected = "btc:usd,btc:aud,btc:ltc" if pairs.Format(":", "", false).Join() != expected { t.Errorf("Test Failed - Pairs Join() error expected %s but received %s", - expected, pairs.Format("-", "", true).Join()) + expected, pairs.Format(":", "", false).Join()) } - expected = "btc:krw,btc:krw,btc:krw" - if pairs.Format(":", "krw", false).Join() != expected { + if pairs.Format(":", "KRW", false).Join() != "" { t.Errorf("Test Failed - Pairs Join() error expected %s but received %s", - expected, pairs.Format("-", "", true).Join()) + expected, pairs.Format(":", "KRW", true).Join()) + } + + pairs = NewPairsFromStrings([]string{"DASHKRW", "BTCKRW"}) + expected = "dash-krw,btc-krw" + if pairs.Format("-", "KRW", false).Join() != expected { + t.Errorf("Test Failed - Pairs Join() error expected %s but received %s", + expected, pairs.Format("-", "KRW", false).Join()) } } diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index 3ddb75d9..a0fd98db 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -401,6 +401,7 @@ func TestGetEnabledCurrencies(t *testing.T) { format := config.CurrencyPairFormatConfig{ Delimiter: "-", Index: "", + Uppercase: true, } b.RequestCurrencyPairFormat = format @@ -466,6 +467,7 @@ func TestGetAvailableCurrencies(t *testing.T) { format := config.CurrencyPairFormatConfig{ Delimiter: "-", Index: "", + Uppercase: true, } b.RequestCurrencyPairFormat = format