Improvements in config, currency, exchange, pair and helper code

This commit is contained in:
Adrian Gallagher
2018-01-17 13:42:09 +11:00
parent 3e30bb7213
commit 5dc6df72aa
12 changed files with 475 additions and 373 deletions

View File

@@ -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
}

View File

@@ -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")
}
}