mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 23:16:52 +00:00
Improvements in config, currency, exchange, pair and helper code
This commit is contained in:
@@ -189,89 +189,26 @@ func (e *Base) GetName() string {
|
||||
// GetEnabledCurrencies is a method that returns the enabled currency pairs of
|
||||
// the exchange base
|
||||
func (e *Base) GetEnabledCurrencies() []pair.CurrencyPair {
|
||||
var pairs []pair.CurrencyPair
|
||||
for x := range e.EnabledPairs {
|
||||
var currencyPair pair.CurrencyPair
|
||||
if e.RequestCurrencyPairFormat.Delimiter != "" {
|
||||
if e.ConfigCurrencyPairFormat.Delimiter != "" {
|
||||
if e.ConfigCurrencyPairFormat.Delimiter == e.RequestCurrencyPairFormat.Delimiter {
|
||||
currencyPair = pair.NewCurrencyPairDelimiter(e.EnabledPairs[x],
|
||||
e.RequestCurrencyPairFormat.Delimiter)
|
||||
} else {
|
||||
currencyPair = pair.NewCurrencyPairDelimiter(e.EnabledPairs[x],
|
||||
e.ConfigCurrencyPairFormat.Delimiter)
|
||||
currencyPair.Delimiter = "-"
|
||||
}
|
||||
} else {
|
||||
if e.ConfigCurrencyPairFormat.Index != "" {
|
||||
currencyPair = pair.NewCurrencyPairFromIndex(e.EnabledPairs[x],
|
||||
e.ConfigCurrencyPairFormat.Index)
|
||||
} else {
|
||||
currencyPair = pair.NewCurrencyPair(e.EnabledPairs[x][0:3],
|
||||
e.EnabledPairs[x][3:])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if e.ConfigCurrencyPairFormat.Delimiter != "" {
|
||||
currencyPair = pair.NewCurrencyPairDelimiter(e.EnabledPairs[x],
|
||||
e.ConfigCurrencyPairFormat.Delimiter)
|
||||
} else {
|
||||
if e.ConfigCurrencyPairFormat.Index != "" {
|
||||
currencyPair = pair.NewCurrencyPairFromIndex(e.EnabledPairs[x],
|
||||
e.ConfigCurrencyPairFormat.Index)
|
||||
} else {
|
||||
currencyPair = pair.NewCurrencyPair(e.EnabledPairs[x][0:3],
|
||||
e.EnabledPairs[x][3:])
|
||||
}
|
||||
}
|
||||
}
|
||||
pairs = append(pairs, currencyPair)
|
||||
}
|
||||
return pairs
|
||||
return pair.FormatPairs(e.EnabledPairs,
|
||||
e.ConfigCurrencyPairFormat.Delimiter,
|
||||
e.ConfigCurrencyPairFormat.Index)
|
||||
}
|
||||
|
||||
// GetAvailableCurrencies is a method that returns the available currency pairs
|
||||
// of the exchange base
|
||||
func (e *Base) GetAvailableCurrencies() []pair.CurrencyPair {
|
||||
var pairs []pair.CurrencyPair
|
||||
for x := range e.AvailablePairs {
|
||||
var currencyPair pair.CurrencyPair
|
||||
if e.RequestCurrencyPairFormat.Delimiter != "" {
|
||||
if e.ConfigCurrencyPairFormat.Delimiter != "" {
|
||||
if e.ConfigCurrencyPairFormat.Delimiter == e.RequestCurrencyPairFormat.Delimiter {
|
||||
currencyPair = pair.NewCurrencyPairDelimiter(e.AvailablePairs[x],
|
||||
e.RequestCurrencyPairFormat.Delimiter)
|
||||
} else {
|
||||
currencyPair = pair.NewCurrencyPairDelimiter(e.AvailablePairs[x],
|
||||
e.ConfigCurrencyPairFormat.Delimiter)
|
||||
currencyPair.Delimiter = "-"
|
||||
}
|
||||
} else {
|
||||
if e.ConfigCurrencyPairFormat.Index != "" {
|
||||
currencyPair = pair.NewCurrencyPairFromIndex(e.AvailablePairs[x],
|
||||
e.ConfigCurrencyPairFormat.Index)
|
||||
} else {
|
||||
currencyPair = pair.NewCurrencyPair(e.AvailablePairs[x][0:3],
|
||||
e.AvailablePairs[x][3:])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if e.ConfigCurrencyPairFormat.Delimiter != "" {
|
||||
currencyPair = pair.NewCurrencyPairDelimiter(e.AvailablePairs[x],
|
||||
e.ConfigCurrencyPairFormat.Delimiter)
|
||||
} else {
|
||||
if e.ConfigCurrencyPairFormat.Index != "" {
|
||||
currencyPair = pair.NewCurrencyPairFromIndex(e.AvailablePairs[x],
|
||||
e.ConfigCurrencyPairFormat.Index)
|
||||
} else {
|
||||
currencyPair = pair.NewCurrencyPair(e.AvailablePairs[x][0:3],
|
||||
e.AvailablePairs[x][3:])
|
||||
}
|
||||
}
|
||||
}
|
||||
pairs = append(pairs, currencyPair)
|
||||
return pair.FormatPairs(e.AvailablePairs,
|
||||
e.ConfigCurrencyPairFormat.Delimiter,
|
||||
e.ConfigCurrencyPairFormat.Index)
|
||||
}
|
||||
|
||||
// SupportsCurrency returns true or not whether a currency pair exists in the
|
||||
// exchange available currencies or not
|
||||
func (e *Base) SupportsCurrency(p pair.CurrencyPair, enabledPairs bool) bool {
|
||||
if enabledPairs {
|
||||
return pair.Contains(e.GetEnabledCurrencies(), p)
|
||||
}
|
||||
return pairs
|
||||
return pair.Contains(e.GetAvailableCurrencies(), p)
|
||||
}
|
||||
|
||||
// GetExchangeFormatCurrencySeperator returns whether or not a specific
|
||||
|
||||
@@ -320,6 +320,34 @@ func TestGetAvailableCurrencies(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportsCurrency(t *testing.T) {
|
||||
b := Base{
|
||||
Name: "TESTNAME",
|
||||
}
|
||||
|
||||
b.AvailablePairs = []string{"BTC-USD", "ETH-USD"}
|
||||
b.EnabledPairs = []string{"BTC-USD"}
|
||||
|
||||
format := config.CurrencyPairFormatConfig{
|
||||
Delimiter: "-",
|
||||
Index: "",
|
||||
}
|
||||
|
||||
b.RequestCurrencyPairFormat = format
|
||||
b.ConfigCurrencyPairFormat = format
|
||||
|
||||
if !b.SupportsCurrency(pair.NewCurrencyPair("BTC", "USD"), true) {
|
||||
t.Error("Test Failed - Exchange SupportsCurrency() incorrect value")
|
||||
}
|
||||
|
||||
if !b.SupportsCurrency(pair.NewCurrencyPair("ETH", "USD"), false) {
|
||||
t.Error("Test Failed - Exchange SupportsCurrency() incorrect value")
|
||||
}
|
||||
|
||||
if b.SupportsCurrency(pair.NewCurrencyPair("ASD", "ASDF"), true) {
|
||||
t.Error("Test Failed - Exchange SupportsCurrency() incorrect value")
|
||||
}
|
||||
}
|
||||
func TestGetExchangeFormatCurrencySeperator(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig(config.ConfigTestFile)
|
||||
|
||||
Reference in New Issue
Block a user