mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
Add currency pair display method to display a currency pair based on user config preferences (e.g BTC-USD or BTCUSD)
This commit is contained in:
@@ -75,16 +75,23 @@ type Post struct {
|
||||
Data Config `json:"Data"`
|
||||
}
|
||||
|
||||
// CurrencyPairFormatConfig stores the users preferred currency pair display
|
||||
type CurrencyPairFormatConfig struct {
|
||||
Uppercase bool
|
||||
Delimiter string
|
||||
}
|
||||
|
||||
// Config is the overarching object that holds all the information for
|
||||
// prestart management of portfolio, SMSGlobal, webserver and enabled exchange
|
||||
type Config struct {
|
||||
Name string
|
||||
EncryptConfig int
|
||||
Cryptocurrencies string
|
||||
Portfolio portfolio.Base `json:"PortfolioAddresses"`
|
||||
SMS SMSGlobalConfig `json:"SMSGlobal"`
|
||||
Webserver WebserverConfig `json:"Webserver"`
|
||||
Exchanges []ExchangeConfig `json:"Exchanges"`
|
||||
Name string
|
||||
EncryptConfig int
|
||||
Cryptocurrencies string
|
||||
CurrencyPairFormat *CurrencyPairFormatConfig `json:"CurrencyPairFormat"`
|
||||
Portfolio portfolio.Base `json:"PortfolioAddresses"`
|
||||
SMS SMSGlobalConfig `json:"SMSGlobal"`
|
||||
Webserver WebserverConfig `json:"Webserver"`
|
||||
Exchanges []ExchangeConfig `json:"Exchanges"`
|
||||
}
|
||||
|
||||
// ExchangeConfig holds all the information needed for each enabled Exchange.
|
||||
@@ -114,6 +121,11 @@ func (c *Config) GetConfigEnabledExchanges() int {
|
||||
return counter
|
||||
}
|
||||
|
||||
// GetCurrencyPairDisplayConfig retrieves the currency pair display preference
|
||||
func (c *Config) GetCurrencyPairDisplayConfig() *CurrencyPairFormatConfig {
|
||||
return c.CurrencyPairFormat
|
||||
}
|
||||
|
||||
// GetExchangeConfig returns your exchange configurations by its indivdual name
|
||||
func (c *Config) GetExchangeConfig(name string) (ExchangeConfig, error) {
|
||||
for i := range c.Exchanges {
|
||||
@@ -396,6 +408,13 @@ func (c *Config) LoadConfig(configPath string) error {
|
||||
return fmt.Errorf(ErrCheckingConfigValues, err)
|
||||
}
|
||||
|
||||
if c.CurrencyPairFormat == nil {
|
||||
c.CurrencyPairFormat = &CurrencyPairFormatConfig{
|
||||
Delimiter: "-",
|
||||
Uppercase: true,
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,22 @@ func TestGetConfigEnabledExchanges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCurrencyPairDisplayConfig(t *testing.T) {
|
||||
cfg := GetConfig()
|
||||
err := cfg.LoadConfig(ConfigTestFile)
|
||||
if err != nil {
|
||||
t.Errorf(
|
||||
"Test failed. GetCurrencyPairDisplayConfig. LoadConfig Error: %s", err.Error(),
|
||||
)
|
||||
}
|
||||
settings := cfg.GetCurrencyPairDisplayConfig()
|
||||
if settings.Delimiter != "-" || !settings.Uppercase {
|
||||
t.Errorf(
|
||||
"Test failed. GetCurrencyPairDisplayConfi. Invalid values",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExchangeConfig(t *testing.T) {
|
||||
GetExchangeConfig := GetConfig()
|
||||
err := GetExchangeConfig.LoadConfig(ConfigTestFile)
|
||||
|
||||
Reference in New Issue
Block a user