mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Moved check for enabled exchanges > 0 to config value checker.
This commit is contained in:
24
config.go
24
config.go
@@ -18,8 +18,9 @@ var (
|
||||
ErrExchangeAvailablePairsEmpty = "Exchange %s: Available pairs is empty."
|
||||
ErrExchangeEnabledPairsEmpty = "Exchange %s: Enabled pairs is empty."
|
||||
ErrExchangeBaseCurrenciesEmpty = "Exchange %s: Base currencies is empty."
|
||||
ErrExchangeAuthAPIDefaultOrEmptyValues = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values."
|
||||
WarningExchangeAuthAPIDefaultOrEmptyValues = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values."
|
||||
ErrExchangeNotFound = "Exchange %s: Not found."
|
||||
ErrNoEnabledExchanges = "No Exchanges enabled."
|
||||
WarningSMSGlobalDefaultOrEmptyValues = "WARNING -- SMS Support disabled due to default or empty Username/Password values."
|
||||
WarningSSMSGlobalSMSContactDefaultOrEmptyValues = "WARNING -- SMS contact #%d Name/Number disabled due to default or empty values."
|
||||
WarningSSMSGlobalSMSNoContacts = "WARNING -- SMS Support disabled due to no enabled contacts."
|
||||
@@ -57,6 +58,16 @@ type Exchanges struct {
|
||||
BaseCurrencies string
|
||||
}
|
||||
|
||||
func GetEnabledExchanges() int {
|
||||
counter := 0
|
||||
for i := range bot.config.Exchanges {
|
||||
if bot.config.Exchanges[i].Enabled {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
return counter
|
||||
}
|
||||
|
||||
func GetExchangeConfig(name string) (Exchanges, error) {
|
||||
for i, _ := range bot.config.Exchanges {
|
||||
if bot.config.Exchanges[i].Name == name {
|
||||
@@ -101,7 +112,8 @@ func CheckSMSGlobalConfigValues() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckConfigValues() error {
|
||||
func CheckExchangeConfigValues() error {
|
||||
exchanges := 0
|
||||
for i, exch := range bot.config.Exchanges {
|
||||
if exch.Enabled {
|
||||
if exch.Name == "" {
|
||||
@@ -119,18 +131,22 @@ func CheckConfigValues() error {
|
||||
if exch.AuthenticatedAPISupport { // non-fatal error
|
||||
if exch.APIKey == "" || exch.APISecret == "" || exch.APIKey == "Key" || exch.APISecret == "Secret" {
|
||||
bot.config.Exchanges[i].AuthenticatedAPISupport = false
|
||||
log.Printf(ErrExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
||||
log.Printf(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
||||
continue
|
||||
} else if exch.Name == "ITBIT" || exch.Name == "Bitstamp" || exch.Name == "Coinbase" {
|
||||
if exch.ClientID == "" || exch.ClientID == "ClientID" {
|
||||
bot.config.Exchanges[i].AuthenticatedAPISupport = false
|
||||
log.Printf(ErrExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
||||
log.Printf(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
exchanges++
|
||||
}
|
||||
}
|
||||
if exchanges == 0 {
|
||||
return errors.New(ErrNoEnabledExchanges)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
26
main.go
26
main.go
@@ -43,49 +43,33 @@ func main() {
|
||||
|
||||
err := errors.New("")
|
||||
bot.config, err = ReadConfig()
|
||||
|
||||
if err != nil {
|
||||
log.Println("Fatal error opening config.json file. Error:", err)
|
||||
log.Printf("Fatal error opening config.json file. Error: %s", err)
|
||||
return
|
||||
}
|
||||
log.Println("Config file loaded. Checking settings.. ")
|
||||
|
||||
err = CheckConfigValues()
|
||||
|
||||
err = CheckExchangeConfigValues()
|
||||
if err != nil {
|
||||
log.Println("Fatal error checking config values. Error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = CheckSMSGlobalConfigValues()
|
||||
|
||||
if err != nil {
|
||||
// non fatal event
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
log.Println("Config file loaded.")
|
||||
log.Printf("Bot '%s' started.\n", bot.config.Name)
|
||||
|
||||
if bot.config.SMS.Enabled {
|
||||
log.Printf("SMS support enabled. Number of SMS contacts %d.\n", GetEnabledSMSContacts())
|
||||
} else {
|
||||
log.Println("SMS support disabled.")
|
||||
}
|
||||
|
||||
enabledExchanges := 0
|
||||
for _, exch := range bot.config.Exchanges {
|
||||
if exch.Enabled {
|
||||
enabledExchanges++
|
||||
}
|
||||
}
|
||||
|
||||
if enabledExchanges == 0 {
|
||||
log.Println("Bot started with no exchanges supported. Exiting.")
|
||||
return
|
||||
}
|
||||
|
||||
AdjustGoMaxProcs()
|
||||
|
||||
log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n", len(bot.config.Exchanges), enabledExchanges)
|
||||
log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n", len(bot.config.Exchanges), GetEnabledExchanges())
|
||||
log.Println("Bot Exchange support:")
|
||||
|
||||
bot.exchange.anx.SetDefaults()
|
||||
|
||||
Reference in New Issue
Block a user