mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 07:26:47 +00:00
Improvements in config, currency, exchange, pair and helper code
This commit is contained in:
@@ -126,3 +126,23 @@ func Contains(pairs []CurrencyPair, p CurrencyPair) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// FormatPairs formats a string array to a list of currency pairs with the
|
||||
// supplied currency pair format
|
||||
func FormatPairs(pairs []string, delimiter, index string) []CurrencyPair {
|
||||
var result []CurrencyPair
|
||||
for x := range pairs {
|
||||
var p CurrencyPair
|
||||
if delimiter != "" {
|
||||
p = NewCurrencyPairDelimiter(pairs[x], delimiter)
|
||||
} else {
|
||||
if index != "" {
|
||||
p = NewCurrencyPairFromIndex(pairs[x], index)
|
||||
} else {
|
||||
p = NewCurrencyPair(pairs[x][0:3], pairs[x][3:])
|
||||
}
|
||||
}
|
||||
result = append(result, p)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -251,3 +251,17 @@ func TestContains(t *testing.T) {
|
||||
t.Errorf("Test failed. TestContains: Non-existant pair was found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatPairs(t *testing.T) {
|
||||
if FormatPairs([]string{"BTC-USD"}, "-", "")[0].Pair().String() != "BTC-USD" {
|
||||
t.Error("Test failed. TestFormatPairs: Expected pair was not found")
|
||||
}
|
||||
|
||||
if FormatPairs([]string{"BTCUSD"}, "", "BTC")[0].Pair().String() != "BTCUSD" {
|
||||
t.Error("Test failed. TestFormatPairs: Expected pair was not found")
|
||||
}
|
||||
|
||||
if FormatPairs([]string{"ETHUSD"}, "", "")[0].Pair().String() != "ETHUSD" {
|
||||
t.Error("Test failed. TestFormatPairs: Expected pair was not found")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user