Config overwrite bugfix (#363)

* Fix bug where on parsing an alternate new config it will overwrite main config.json in gct dir

* Stop movement of config.json file from root dir when a new config is parsed in

* Stop overiding config.json at gct dir with new config.json from root directory

* RM LN :D

* Fix bug where promptforconfig in config_encryption.go overwrites default config
Ensure periphery command packages do not interact or save over configuration
Ensure tests to not save over or change current testdata/config
This commit is contained in:
Ryan O'Hara-Reid
2019-09-27 16:03:41 +10:00
committed by Adrian Gallagher
parent 6bdbe236c0
commit e2d57540a6
55 changed files with 408 additions and 173 deletions

View File

@@ -112,7 +112,8 @@ func main() {
}
conf := config.GetConfig()
err = conf.LoadConfig(configFile)
err = conf.LoadConfig(configFile, true)
if err != nil {
fmt.Println(err)
os.Exit(1)

View File

@@ -99,7 +99,7 @@ func main() {
}
configTestFile := config.GetConfig()
err = configTestFile.LoadConfig(exchangeConfigPath)
err = configTestFile.LoadConfig(exchangeConfigPath, true)
if err != nil {
log.Fatal("GoCryptoTrader: Exchange templating configuration retrieval error ", err)
}
@@ -129,7 +129,7 @@ func main() {
configTestFile.Exchanges = append(configTestFile.Exchanges, newExchConfig)
// TODO sorting function so exchanges are in alphabetical order - low priority
err = configTestFile.SaveConfig(exchangeJSON)
err = configTestFile.SaveConfig(exchangeJSON, false)
if err != nil {
log.Fatal("GoCryptoTrader: Exchange templating configuration error - cannot save")
}

View File

@@ -62,7 +62,7 @@ func main() {
// Otherwise default to loading the config file and generating OTP codes from it
var cfg config.Config
err = cfg.LoadConfig(cfgFile)
err = cfg.LoadConfig(cfgFile, true)
if err != nil {
log.Fatal(err)
}

View File

@@ -77,7 +77,7 @@ func main() {
log.Println("GoCryptoTrader: portfolio tool.")
var cfg config.Config
err = cfg.LoadConfig(inFile)
err = cfg.LoadConfig(inFile, true)
if err != nil {
log.Println(err)
os.Exit(1)

View File

@@ -76,7 +76,7 @@ func SendWebsocketEvent(event string, reqData interface{}, result *WebsocketEven
func main() {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigFile)
err := cfg.LoadConfig(config.ConfigFile, true)
if err != nil {
log.Fatalf("Failed to load config file: %s", err)
}

View File

@@ -41,7 +41,10 @@ type group struct {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig(config.ConfigTestFile)
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal(err)
}
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
@@ -51,7 +54,7 @@ func TestSetup(t *testing.T) {
func TestConnect(t *testing.T) {
err := s.Connect()
if err == nil {
t.Error("test failed - slack Connect() error")
t.Error("test failed - slack Connect() error cannot be nil")
}
}
@@ -59,7 +62,7 @@ func TestPushEvent(t *testing.T) {
t.Parallel()
err := s.PushEvent(base.Event{})
if err == nil {
t.Error("test failed - slack PushEvent() error")
t.Error("test failed - slack PushEvent() error cannot be nil")
}
}

View File

@@ -11,7 +11,10 @@ var s SMSGlobal
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal(err)
}
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
}
@@ -19,14 +22,14 @@ func TestSetup(t *testing.T) {
func TestConnect(t *testing.T) {
err := s.Connect()
if err != nil {
t.Error("test failed - SMSGlobal Connect() error")
t.Error("test failed - SMSGlobal Connect() error", err)
}
}
func TestPushEvent(t *testing.T) {
err := s.PushEvent(base.Event{})
if err != nil {
t.Error("test failed - SMSGlobal PushEvent() error")
t.Error("test failed - SMSGlobal PushEvent() error", err)
}
}

View File

@@ -11,7 +11,10 @@ var s SMTPservice
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal(err)
}
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
}
@@ -26,17 +29,17 @@ func TestConnect(t *testing.T) {
func TestPushEvent(t *testing.T) {
err := s.PushEvent(base.Event{})
if err == nil {
t.Error("test failed - smtpservice PushEvent() error", err)
t.Error("test failed - smtpservice PushEvent() error cannot be nil")
}
}
func TestSend(t *testing.T) {
err := s.Send("", "")
if err == nil {
t.Error("test failed - smtpservice Send() error", err)
t.Error("test failed - smtpservice Send() error cannot be nil")
}
err = s.Send("subject", "alertmessage")
if err == nil {
t.Error("test failed - smtpservice Send() error", err)
t.Error("test failed - smtpservice Send() error cannot be nil")
}
}

View File

@@ -15,13 +15,18 @@ var T Telegram
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal(err)
}
commsCfg := cfg.GetCommunicationsConfig()
T.Setup(&commsCfg)
if T.Name != "Telegram" || T.Enabled ||
T.Token != "testest" || T.Verbose {
if T.Name != "Telegram" || T.Enabled || T.Token != "testest" || T.Verbose {
t.Error("test failed - telegram Setup() error, unexpected setup values",
T.Name, T.Enabled, T.Token, T.Verbose)
T.Name,
T.Enabled,
T.Token,
T.Verbose)
}
}

View File

@@ -1423,24 +1423,38 @@ func GetFilePath(file string) (string, error) {
filepath.Join(newDir, EncryptedConfigFile),
}
// First upgrade the old dir config file if it exists to the corresponding new one
// First upgrade the old dir config file if it exists to the corresponding
// new one
for x := range oldDirs {
_, err := os.Stat(oldDirs[x])
if os.IsNotExist(err) {
continue
}
_, err = os.Stat(newDirs[x])
if !os.IsNotExist(err) {
log.Warnf(log.ConfigMgr,
"config.json file found in root dir and gct dir; cannot overwrite, defaulting to gct dir config.json at %s",
newDirs[x])
return newDirs[x], nil
}
if filepath.Ext(oldDirs[x]) == ".json" {
err = os.Rename(oldDirs[x], newDirs[0])
if err != nil {
return "", err
}
log.Debugf(log.ConfigMgr, "Renamed old config file %s to %s\n", oldDirs[x], newDirs[0])
log.Debugf(log.ConfigMgr,
"Renamed old config file %s to %s\n",
oldDirs[x],
newDirs[0])
} else {
err = os.Rename(oldDirs[x], newDirs[1])
if err != nil {
return "", err
}
log.Debugf(log.ConfigMgr, "Renamed old config file %s to %s\n", oldDirs[x], newDirs[1])
log.Debugf(log.ConfigMgr,
"Renamed old config file %s to %s\n",
oldDirs[x],
newDirs[1])
}
}
@@ -1485,7 +1499,7 @@ func GetFilePath(file string) (string, error) {
// ReadConfig verifies and checks for encryption and verifies the unencrypted
// file contains JSON.
func (c *Config) ReadConfig(configPath string) error {
func (c *Config) ReadConfig(configPath string, dryrun bool) error {
defaultPath, err := GetFilePath(configPath)
if err != nil {
return err
@@ -1510,9 +1524,9 @@ func (c *Config) ReadConfig(configPath string) error {
m.Lock()
IsInitialSetup = true
m.Unlock()
if c.PromptForConfigEncryption() {
if c.PromptForConfigEncryption(configPath, dryrun) {
c.EncryptConfig = configFileEncryptionEnabled
return c.SaveConfig(defaultPath)
return c.SaveConfig(defaultPath, dryrun)
}
}
} else {
@@ -1552,7 +1566,11 @@ func (c *Config) ReadConfig(configPath string) error {
}
// SaveConfig saves your configuration to your desired path
func (c *Config) SaveConfig(configPath string) error {
func (c *Config) SaveConfig(configPath string, dryrun bool) error {
if dryrun {
return nil
}
defaultPath, err := GetFilePath(configPath)
if err != nil {
return err
@@ -1666,8 +1684,8 @@ func (c *Config) CheckConfig() error {
}
// LoadConfig loads your configuration file into your configuration object
func (c *Config) LoadConfig(configPath string) error {
err := c.ReadConfig(configPath)
func (c *Config) LoadConfig(configPath string, dryrun bool) error {
err := c.ReadConfig(configPath, dryrun)
if err != nil {
return fmt.Errorf(ErrFailureOpeningConfig, configPath, err)
}
@@ -1676,7 +1694,7 @@ func (c *Config) LoadConfig(configPath string) error {
}
// UpdateConfig updates the config with a supplied config file
func (c *Config) UpdateConfig(configPath string, newCfg *Config) error {
func (c *Config) UpdateConfig(configPath string, newCfg *Config, dryrun bool) error {
err := newCfg.CheckConfig()
if err != nil {
return err
@@ -1691,12 +1709,12 @@ func (c *Config) UpdateConfig(configPath string, newCfg *Config) error {
c.Webserver = newCfg.Webserver
c.Exchanges = newCfg.Exchanges
err = c.SaveConfig(configPath)
err = c.SaveConfig(configPath, dryrun)
if err != nil {
return err
}
return c.LoadConfig(configPath)
return c.LoadConfig(configPath, dryrun)
}
// GetConfig returns a pointer to a configuration object

View File

@@ -11,6 +11,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
log "github.com/thrasher-corp/gocryptotrader/logger"
"golang.org/x/crypto/scrypt"
)
@@ -32,7 +33,7 @@ var (
)
// PromptForConfigEncryption asks for encryption key
func (c *Config) PromptForConfigEncryption() bool {
func (c *Config) PromptForConfigEncryption(configPath string, dryrun bool) bool {
fmt.Println("Would you like to encrypt your config file (y/n)?")
input := ""
@@ -43,7 +44,10 @@ func (c *Config) PromptForConfigEncryption() bool {
if !common.YesOrNo(input) {
c.EncryptConfig = configFileEncryptionDisabled
c.SaveConfig("")
err := c.SaveConfig(configPath, dryrun)
if err != nil {
log.Errorf(log.ConfigMgr, "cannot save config %s", err)
}
return false
}
return true

View File

@@ -8,7 +8,7 @@ import (
func TestPromptForConfigEncryption(t *testing.T) {
t.Parallel()
if Cfg.PromptForConfigEncryption() {
if Cfg.PromptForConfigEncryption("", true) {
t.Error("Test failed. PromptForConfigEncryption return incorrect bool")
}
}

View File

@@ -22,7 +22,7 @@ const (
func TestGetCurrencyConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetCurrencyConfig LoadConfig error", err)
}
@@ -31,7 +31,7 @@ func TestGetCurrencyConfig(t *testing.T) {
func TestGetExchangeBankAccounts(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetExchangeBankAccounts LoadConfig error", err)
}
@@ -47,7 +47,7 @@ func TestGetExchangeBankAccounts(t *testing.T) {
func TestUpdateExchangeBankAccounts(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. UpdateExchangeBankAccounts LoadConfig error", err)
}
@@ -77,7 +77,7 @@ func TestUpdateExchangeBankAccounts(t *testing.T) {
func TestGetClientBankAccounts(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetClientBankAccounts LoadConfig error", err)
}
@@ -97,7 +97,7 @@ func TestGetClientBankAccounts(t *testing.T) {
func TestUpdateClientBankAccounts(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. UpdateClientBankAccounts LoadConfig error", err)
}
@@ -127,7 +127,7 @@ func TestUpdateClientBankAccounts(t *testing.T) {
func TestCheckClientBankAccounts(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. CheckClientBankAccounts LoadConfig error", err)
}
@@ -262,7 +262,7 @@ func TestPurgeExchangeCredentials(t *testing.T) {
func TestGetCommunicationsConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetCommunicationsConfig LoadConfig error", err)
}
@@ -271,7 +271,7 @@ func TestGetCommunicationsConfig(t *testing.T) {
func TestUpdateCommunicationsConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. UpdateCommunicationsConfig LoadConfig error", err)
}
@@ -283,7 +283,7 @@ func TestUpdateCommunicationsConfig(t *testing.T) {
func TestGetCryptocurrencyProviderConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetCryptocurrencyProviderConfig LoadConfig error", err)
}
@@ -292,7 +292,7 @@ func TestGetCryptocurrencyProviderConfig(t *testing.T) {
func TestUpdateCryptocurrencyProviderConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. UpdateCryptocurrencyProviderConfig LoadConfig error", err)
}
@@ -308,7 +308,7 @@ func TestUpdateCryptocurrencyProviderConfig(t *testing.T) {
func TestCheckCommunicationsConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. CheckCommunicationsConfig LoadConfig error", err)
}
@@ -782,7 +782,7 @@ func TestCheckPairConsistency(t *testing.T) {
func TestSupportsPair(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. TestSupportsPair. LoadConfig Error: %s", err.Error(),
@@ -979,7 +979,7 @@ func TestGetEnabledPairs(t *testing.T) {
func TestGetEnabledExchanges(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. TestGetEnabledExchanges. LoadConfig Error: %s", err.Error(),
@@ -1002,7 +1002,7 @@ func TestGetEnabledExchanges(t *testing.T) {
func TestGetDisabledExchanges(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. TestGetDisabledExchanges. LoadConfig Error: %s", err.Error(),
@@ -1040,7 +1040,7 @@ func TestGetDisabledExchanges(t *testing.T) {
func TestCountEnabledExchanges(t *testing.T) {
GetConfigEnabledExchanges := GetConfig()
err := GetConfigEnabledExchanges.LoadConfig(ConfigTestFile)
err := GetConfigEnabledExchanges.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error(
"Test failed. GetConfigEnabledExchanges load config error: " + err.Error(),
@@ -1054,7 +1054,7 @@ func TestCountEnabledExchanges(t *testing.T) {
func TestGetConfigCurrencyPairFormat(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. TestGetConfigCurrencyPairFormat. LoadConfig Error: %s", err.Error(),
@@ -1080,7 +1080,7 @@ func TestGetConfigCurrencyPairFormat(t *testing.T) {
func TestGetRequestCurrencyPairFormat(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. TestGetRequestCurrencyPairFormat. LoadConfig Error: %s", err.Error(),
@@ -1107,7 +1107,7 @@ func TestGetRequestCurrencyPairFormat(t *testing.T) {
func TestGetCurrencyPairDisplayConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. GetCurrencyPairDisplayConfig. LoadConfig Error: %s", err.Error(),
@@ -1123,7 +1123,7 @@ func TestGetCurrencyPairDisplayConfig(t *testing.T) {
func TestGetAllExchangeConfigs(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetAllExchangeConfigs. LoadConfig error", err)
}
@@ -1134,7 +1134,7 @@ func TestGetAllExchangeConfigs(t *testing.T) {
func TestGetExchangeConfig(t *testing.T) {
GetExchangeConfig := GetConfig()
err := GetExchangeConfig.LoadConfig(ConfigTestFile)
err := GetExchangeConfig.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. GetExchangeConfig.LoadConfig Error: %s", err.Error(),
@@ -1153,7 +1153,7 @@ func TestGetExchangeConfig(t *testing.T) {
func TestGetForexProviderConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetForexProviderConfig. LoadConfig error", err)
}
@@ -1170,7 +1170,7 @@ func TestGetForexProviderConfig(t *testing.T) {
func TestGetForexProvidersConfig(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error(err)
}
@@ -1182,7 +1182,7 @@ func TestGetForexProvidersConfig(t *testing.T) {
func TestGetPrimaryForexProvider(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. GetPrimaryForexProvider. LoadConfig error", err)
}
@@ -1202,7 +1202,7 @@ func TestGetPrimaryForexProvider(t *testing.T) {
func TestUpdateExchangeConfig(t *testing.T) {
c := GetConfig()
err := c.LoadConfig(ConfigTestFile)
err := c.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error(err)
}
@@ -1232,7 +1232,7 @@ func TestCheckExchangeConfigValues(t *testing.T) {
t.Error("nil exchanges should throw an err")
}
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Fatal(err)
}
@@ -1548,7 +1548,7 @@ func TestCheckExchangeConfigValues(t *testing.T) {
func TestRetrieveConfigCurrencyPairs(t *testing.T) {
cfg := GetConfig()
err := cfg.LoadConfig(ConfigTestFile)
err := cfg.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf(
"Test failed. TestRetrieveConfigCurrencyPairs.LoadConfig: %s", err.Error(),
@@ -1573,17 +1573,17 @@ func TestRetrieveConfigCurrencyPairs(t *testing.T) {
func TestReadConfig(t *testing.T) {
readConfig := GetConfig()
err := readConfig.ReadConfig(ConfigTestFile)
err := readConfig.ReadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf("Test failed. TestReadConfig %s", err.Error())
}
err = readConfig.ReadConfig("bla")
err = readConfig.ReadConfig("bla", true)
if err == nil {
t.Error("Test failed. TestReadConfig error cannot be nil")
}
err = readConfig.ReadConfig("")
err = readConfig.ReadConfig("", true)
if err != nil {
t.Error("Test failed. TestReadConfig error")
}
@@ -1591,12 +1591,12 @@ func TestReadConfig(t *testing.T) {
func TestLoadConfig(t *testing.T) {
loadConfig := GetConfig()
err := loadConfig.LoadConfig(ConfigTestFile)
err := loadConfig.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Error("Test failed. TestLoadConfig " + err.Error())
}
err = loadConfig.LoadConfig("testy")
err = loadConfig.LoadConfig("testy", true)
if err == nil {
t.Error("Test failed. TestLoadConfig ")
}
@@ -1604,11 +1604,11 @@ func TestLoadConfig(t *testing.T) {
func TestSaveConfig(t *testing.T) {
saveConfig := GetConfig()
err := saveConfig.LoadConfig(ConfigTestFile)
err := saveConfig.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf("Test failed. TestSaveConfig.LoadConfig: %s", err.Error())
}
err2 := saveConfig.SaveConfig(ConfigTestFile)
err2 := saveConfig.SaveConfig(ConfigTestFile, true)
if err2 != nil {
t.Errorf("Test failed. TestSaveConfig.SaveConfig, %s", err2.Error())
}
@@ -1687,7 +1687,7 @@ func TestCheckRemoteControlConfig(t *testing.T) {
func TestCheckConfig(t *testing.T) {
var c Config
err := c.LoadConfig(ConfigTestFile)
err := c.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf("Test failed. %s", err)
}
@@ -1700,24 +1700,24 @@ func TestCheckConfig(t *testing.T) {
func TestUpdateConfig(t *testing.T) {
var c Config
err := c.LoadConfig(ConfigTestFile)
err := c.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Errorf("Test failed. %s", err)
}
newCfg := c
err = c.UpdateConfig(ConfigTestFile, &newCfg)
err = c.UpdateConfig(ConfigTestFile, &newCfg, true)
if err != nil {
t.Fatalf("Test failed. %s", err)
}
err = c.UpdateConfig("//non-existantpath\\", &newCfg)
err = c.UpdateConfig("//non-existantpath\\", &newCfg, true)
if err == nil {
t.Fatalf("Test failed. Error should of been thrown for invalid path")
}
newCfg.Currency.Cryptocurrencies = currency.NewCurrenciesFromStringArray([]string{""})
err = c.UpdateConfig(ConfigTestFile, &newCfg)
err = c.UpdateConfig(ConfigTestFile, &newCfg, true)
if err != nil {
t.Errorf("Test failed. %s", err)
}
@@ -1728,14 +1728,14 @@ func TestUpdateConfig(t *testing.T) {
func BenchmarkUpdateConfig(b *testing.B) {
var c Config
err := c.LoadConfig(ConfigTestFile)
err := c.LoadConfig(ConfigTestFile, true)
if err != nil {
b.Errorf("Unable to benchmark UpdateConfig(): %s", err)
}
newCfg := c
for i := 0; i < b.N; i++ {
_ = c.UpdateConfig(ConfigTestFile, &newCfg)
_ = c.UpdateConfig(ConfigTestFile, &newCfg, true)
}
}
@@ -1768,7 +1768,7 @@ func TestCheckLoggerConfig(t *testing.T) {
t.Error("unexpected result")
}
c.LoadConfig(ConfigTestFile)
c.LoadConfig(ConfigTestFile, true)
err = c.CheckLoggerConfig()
if err != nil {
t.Errorf("Failed to create logger with user settings: reason: %v", err)
@@ -1779,7 +1779,7 @@ func TestDisableNTPCheck(t *testing.T) {
t.Parallel()
c := GetConfig()
err := c.LoadConfig(ConfigTestFile)
err := c.LoadConfig(ConfigTestFile, true)
if err != nil {
t.Fatal(err)
}

View File

@@ -53,7 +53,7 @@ func New() (*Engine, error) {
var b Engine
b.Config = &config.Cfg
err := b.Config.LoadConfig("")
err := b.Config.LoadConfig("", false)
if err != nil {
return nil, fmt.Errorf("failed to load config. Err: %s", err)
}
@@ -69,9 +69,13 @@ func NewFromSettings(settings *Settings) (*Engine, error) {
var b Engine
b.Config = &config.Cfg
filePath, err := config.GetFilePath(settings.ConfigFile)
if err != nil {
return nil, err
}
log.Debugf(log.Global, "Loading config file %s..\n", settings.ConfigFile)
err := b.Config.LoadConfig(settings.ConfigFile)
log.Debugf(log.Global, "Loading config file %s..\n", filePath)
err = b.Config.LoadConfig(filePath, settings.EnableDryRun)
if err != nil {
return nil, fmt.Errorf("failed to load config. Err: %s", err)
}
@@ -86,7 +90,7 @@ func NewFromSettings(settings *Settings) (*Engine, error) {
log.SetupSubLoggers(b.Config.Logging.SubLoggers)
}
b.Settings.ConfigFile = settings.ConfigFile
b.Settings.ConfigFile = filePath
b.Settings.DataDir = settings.DataDir
err = utils.AdjustGoMaxProcs(settings.GoMaxProcs)
@@ -433,7 +437,7 @@ func (e *Engine) Stop() {
}
if !e.Settings.EnableDryRun {
err := e.Config.SaveConfig(e.Settings.ConfigFile)
err := e.Config.SaveConfig(e.Settings.ConfigFile, false)
if err != nil {
log.Errorln(log.Global, "Unable to save config.")
} else {

View File

@@ -14,7 +14,7 @@ func SetupTest(t *testing.T) {
Bot = new(Engine)
}
Bot.Config = &config.Cfg
err := Bot.Config.LoadConfig("")
err := Bot.Config.LoadConfig("", true)
if err != nil {
t.Fatalf("Test failed. SetupTest: Failed to load config: %s", err)
}

View File

@@ -29,7 +29,7 @@ func SetupTestHelpers(t *testing.T) {
Bot = new(Engine)
}
Bot.Config = &config.Cfg
err := Bot.Config.LoadConfig("../testdata/configtest.json")
err := Bot.Config.LoadConfig("../testdata/configtest.json", true)
if err != nil {
t.Fatalf("Test failed. SetupTest: Failed to load config: %s", err)
}

View File

@@ -42,7 +42,7 @@ func RESTSaveAllSettings(w http.ResponseWriter, r *http.Request) {
RESTfulError(r.Method, err)
}
// Save change the settings
err = Bot.Config.UpdateConfig(Bot.Settings.ConfigFile, &responseData.Data)
err = Bot.Config.UpdateConfig(Bot.Settings.ConfigFile, &responseData.Data, false)
if err != nil {
RESTfulError(r.Method, err)
}

View File

@@ -13,7 +13,7 @@ import (
func loadConfig(t *testing.T) *config.Config {
cfg := config.GetConfig()
err := cfg.LoadConfig("")
err := cfg.LoadConfig("", true)
if err != nil {
t.Error("Test failed. GetCurrencyConfig LoadConfig error", err)
}

View File

@@ -14,7 +14,7 @@ func TestNewCurrencyPairSyncer(t *testing.T) {
Bot = new(Engine)
}
Bot.Config = &config.Cfg
err := Bot.Config.LoadConfig("")
err := Bot.Config.LoadConfig("", true)
if err != nil {
t.Fatalf("Test failed. TestNewExchangeSyncer: Failed to load config: %s", err)
}

View File

@@ -310,7 +310,7 @@ func wsSaveConfig(client *WebsocketClient, data interface{}) error {
return err
}
err = Bot.Config.UpdateConfig(Bot.Settings.ConfigFile, &cfg)
err = Bot.Config.UpdateConfig(Bot.Settings.ConfigFile, &cfg, Bot.Settings.EnableDryRun)
if err != nil {
wsResp.Error = err.Error()
client.SendWebsocketMessage(wsResp)

View File

@@ -17,7 +17,10 @@ var mockTests = false
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatalf("Test Failed - ANX Setup() load config error: %s", err)
}
anxConfig, err := cfg.GetExchangeConfig("ANX")
if err != nil {
log.Fatalf("Test Failed - ANX Setup() init error: %s", err)
@@ -26,7 +29,10 @@ func TestMain(m *testing.M) {
anxConfig.API.Credentials.Key = apiKey
anxConfig.API.Credentials.Secret = apiSecret
a.SetDefaults()
a.Setup(anxConfig)
err = a.Setup(anxConfig)
if err != nil {
log.Fatal("Test Failed - ANX setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, a.GetName(), a.API.Endpoints.URL)
os.Exit(m.Run())
}

View File

@@ -20,7 +20,10 @@ var mockTests = true
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - ANX load config error", err)
}
anxConfig, err := cfg.GetExchangeConfig("ANX")
if err != nil {
log.Fatal("Test Failed - Mock server error", err)
@@ -30,7 +33,10 @@ func TestMain(m *testing.M) {
anxConfig.API.Credentials.Key = apiKey
anxConfig.API.Credentials.Secret = apiSecret
a.SetDefaults()
a.Setup(anxConfig)
err = a.Setup(anxConfig)
if err != nil {
log.Fatal("Test Failed - ANX setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockFile)
if err != nil {

View File

@@ -17,7 +17,10 @@ var mockTests = false
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Binance load config error", err)
}
binanceConfig, err := cfg.GetExchangeConfig("Binance")
if err != nil {
log.Fatal("Test Failed - Binance Setup() init error", err)
@@ -26,7 +29,10 @@ func TestMain(m *testing.M) {
binanceConfig.API.Credentials.Key = apiKey
binanceConfig.API.Credentials.Secret = apiSecret
b.SetDefaults()
b.Setup(binanceConfig)
err = b.Setup(binanceConfig)
if err != nil {
log.Fatal("Test Failed - Binance setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, b.GetName(), b.API.Endpoints.URL)
os.Exit(m.Run())
}

View File

@@ -20,7 +20,10 @@ var mockTests = true
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Binance load config error", err)
}
binanceConfig, err := cfg.GetExchangeConfig("Binance")
if err != nil {
log.Fatal("Test Failed - Binance Setup() init error", err)
@@ -30,7 +33,10 @@ func TestMain(m *testing.M) {
binanceConfig.API.Credentials.Key = apiKey
binanceConfig.API.Credentials.Secret = apiSecret
b.SetDefaults()
b.Setup(binanceConfig)
err = b.Setup(binanceConfig)
if err != nil {
log.Fatal("Test Failed - Binance setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
if err != nil {

View File

@@ -28,12 +28,18 @@ var b Bitfinex
func TestSetup(t *testing.T) {
b.SetDefaults()
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bitfinex load config error", err)
}
bfxConfig, err := cfg.GetExchangeConfig("Bitfinex")
if err != nil {
t.Error("Test Failed - Bitfinex Setup() init error")
}
b.Setup(bfxConfig)
err = b.Setup(bfxConfig)
if err != nil {
t.Fatal("Test Failed - Bitfinex setup error", err)
}
b.API.Credentials.Key = apiKey
b.API.Credentials.Secret = apiSecret
if !b.Enabled || b.API.AuthenticatedSupport ||

View File

@@ -26,7 +26,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bitflyer load config error", err)
}
bitflyerConfig, err := cfg.GetExchangeConfig("Bitflyer")
if err != nil {
t.Error("Test Failed - bitflyer Setup() init error")
@@ -36,7 +39,10 @@ func TestSetup(t *testing.T) {
bitflyerConfig.API.Credentials.Key = apiKey
bitflyerConfig.API.Credentials.Secret = apiSecret
b.Setup(bitflyerConfig)
err = b.Setup(bitflyerConfig)
if err != nil {
t.Fatal("Test Failed - Bitflyer setup error", err)
}
}
func TestGetLatestBlockCA(t *testing.T) {

View File

@@ -24,7 +24,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bithumb load config error", err)
}
bitConfig, err := cfg.GetExchangeConfig("Bithumb")
if err != nil {
t.Error("Test Failed - Bithumb Setup() init error")
@@ -34,7 +37,10 @@ func TestSetup(t *testing.T) {
bitConfig.API.Credentials.Key = apiKey
bitConfig.API.Credentials.Secret = apiSecret
b.Setup(bitConfig)
err = b.Setup(bitConfig)
if err != nil {
t.Fatal("Test Failed - Bithumb setup error", err)
}
}
func TestGetTradablePairs(t *testing.T) {

View File

@@ -30,7 +30,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bitmex load config error", err)
}
bitmexConfig, err := cfg.GetExchangeConfig("Bitmex")
if err != nil {
t.Error("Test Failed - Bitmex Setup() init error")
@@ -41,7 +44,10 @@ func TestSetup(t *testing.T) {
bitmexConfig.API.Credentials.Key = apiKey
bitmexConfig.API.Credentials.Secret = apiSecret
b.Setup(bitmexConfig)
err = b.Setup(bitmexConfig)
if err != nil {
t.Fatal("Test Failed - Bitmex setup error", err)
}
}
func TestStart(t *testing.T) {

View File

@@ -17,7 +17,10 @@ var mockTests = false
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Bitstamp load config error", err)
}
bitstampConfig, err := cfg.GetExchangeConfig("Bitstamp")
if err != nil {
log.Fatal("Test Failed - Bitstamp Setup() init error", err)
@@ -27,7 +30,10 @@ func TestMain(m *testing.M) {
bitstampConfig.API.Credentials.Secret = apiSecret
bitstampConfig.API.Credentials.ClientID = customerID
b.SetDefaults()
b.Setup(bitstampConfig)
err = b.Setup(bitstampConfig)
if err != nil {
log.Fatal("Test Failed - Bitstamp setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, b.GetName(), b.API.Endpoints.URL)
os.Exit(m.Run())
}

View File

@@ -20,7 +20,10 @@ var mockTests = true
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Bitstamp load config error", err)
}
bitstampConfig, err := cfg.GetExchangeConfig("Bitstamp")
if err != nil {
log.Fatal("Test Failed - Bitstamp Setup() init error", err)
@@ -31,7 +34,10 @@ func TestMain(m *testing.M) {
bitstampConfig.API.Credentials.Secret = apiSecret
bitstampConfig.API.Credentials.ClientID = customerID
b.SetDefaults()
b.Setup(bitstampConfig)
err = b.Setup(bitstampConfig)
if err != nil {
log.Fatal("Test Failed - Bitstamp setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
if err != nil {

View File

@@ -27,7 +27,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bittrex load config error", err)
}
bConfig, err := cfg.GetExchangeConfig("Bittrex")
if err != nil {
t.Error("Test Failed - Bittrex Setup() init error")
@@ -36,7 +39,10 @@ func TestSetup(t *testing.T) {
bConfig.API.Credentials.Secret = apiSecret
bConfig.API.AuthenticatedSupport = true
b.Setup(bConfig)
err = b.Setup(bConfig)
if err != nil {
t.Fatal("Test Failed - Bittrex setup error", err)
}
if !b.IsEnabled() || !b.API.AuthenticatedSupport ||
b.Verbose || len(b.BaseCurrencies) < 1 {

View File

@@ -25,7 +25,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - BTC Markets load config error", err)
}
bConfig, err := cfg.GetExchangeConfig("BTC Markets")
if err != nil {
t.Error("Test Failed - BTC Markets Setup() init error")
@@ -34,7 +37,10 @@ func TestSetup(t *testing.T) {
bConfig.API.Credentials.Secret = apiSecret
bConfig.API.AuthenticatedSupport = true
b.Setup(bConfig)
err = b.Setup(bConfig)
if err != nil {
t.Fatal("Test Failed - BTC Markets setup error", err)
}
}
func TestGetMarkets(t *testing.T) {

View File

@@ -1,6 +1,7 @@
package btse
import (
"log"
"testing"
"github.com/thrasher-corp/gocryptotrader/common"
@@ -24,7 +25,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - BTSE load config error", err)
}
btseConfig, err := cfg.GetExchangeConfig("BTSE")
if err != nil {
t.Error("Test Failed - BTSE Setup() init error")
@@ -34,7 +38,10 @@ func TestSetup(t *testing.T) {
btseConfig.API.Credentials.Key = apiKey
btseConfig.API.Credentials.Secret = apiSecret
b.Setup(btseConfig)
err = b.Setup(btseConfig)
if err != nil {
t.Fatal("Test Failed - BTSE setup error", err)
}
}
func TestGetMarkets(t *testing.T) {

View File

@@ -30,7 +30,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - coinbasepro load config error", err)
}
gdxConfig, err := cfg.GetExchangeConfig("CoinbasePro")
if err != nil {
t.Error("Test Failed - coinbasepro Setup() init error")
@@ -40,7 +43,10 @@ func TestSetup(t *testing.T) {
gdxConfig.API.Credentials.ClientID = clientID
gdxConfig.API.AuthenticatedSupport = true
gdxConfig.API.AuthenticatedWebsocketSupport = true
c.Setup(gdxConfig)
err = c.Setup(gdxConfig)
if err != nil {
t.Fatal("Test Failed - CoinbasePro setup error", err)
}
}
func TestGetProducts(t *testing.T) {

View File

@@ -29,7 +29,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Coinut load config error", err)
}
bConfig, err := cfg.GetExchangeConfig("COINUT")
if err != nil {
t.Error("Test Failed - Coinut Setup() init error")
@@ -39,7 +42,10 @@ func TestSetup(t *testing.T) {
bConfig.API.Credentials.Key = apiKey
bConfig.API.Credentials.ClientID = clientID
bConfig.Verbose = true
c.Setup(bConfig)
err = c.Setup(bConfig)
if err != nil {
t.Fatal("Test Failed - Coinut setup error", err)
}
if !c.IsEnabled() || !c.Verbose ||
c.Websocket.IsEnabled() || len(c.BaseCurrencies) < 1 {

View File

@@ -110,7 +110,7 @@ func TestSetClientProxyAddress(t *testing.T) {
func TestSetAutoPairDefaults(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
err := cfg.LoadConfig(config.ConfigTestFile, true)
if err != nil {
t.Fatalf("Test failed. TestSetAutoPairDefaults failed to load config file. Error: %s", err)
}
@@ -163,7 +163,7 @@ func TestGetLastPairsUpdateTime(t *testing.T) {
func TestSetAssetTypes(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
err := cfg.LoadConfig(config.ConfigTestFile, true)
if err != nil {
t.Fatalf("Test failed. TestSetAssetTypes failed to load config file. Error: %s", err)
}
@@ -222,7 +222,7 @@ func TestSetCurrencyPairFormat(t *testing.T) {
t.Skip()
// TO-DO
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
err := cfg.LoadConfig(config.ConfigTestFile, true)
if err != nil {
t.Fatalf("Test failed. TestSetCurrencyPairFormat failed to load config file. Error: %s", err)
}
@@ -578,7 +578,7 @@ func TestSetPairs(t *testing.T) {
t.Skip()
// TO-DO
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
err := cfg.LoadConfig(config.ConfigTestFile, true)
if err != nil {
t.Fatal("Test failed. TestSetPairs failed to load config")
}
@@ -621,7 +621,7 @@ func TestSetPairs(t *testing.T) {
func TestUpdatePairs(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
err := cfg.LoadConfig(config.ConfigTestFile, true)
if err != nil {
t.Fatal("Test failed. TestUpdatePairs failed to load config")
}

View File

@@ -1,6 +1,7 @@
package exmo
import (
"log"
"testing"
"github.com/thrasher-corp/gocryptotrader/common"
@@ -25,13 +26,19 @@ func TestDefault(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Exmo load config error", err)
}
exmoConf, err := cfg.GetExchangeConfig("EXMO")
if err != nil {
t.Error("Test Failed - OKCoin Setup() init error")
t.Error("Test Failed - Exmo Setup() init error")
}
e.Setup(exmoConf)
err = e.Setup(exmoConf)
if err != nil {
t.Fatal("Test Failed - Exmo setup error", err)
}
e.API.AuthenticatedSupport = true
e.API.Credentials.Key = APIKey

View File

@@ -30,7 +30,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - GateIO load config error", err)
}
gateioConfig, err := cfg.GetExchangeConfig("GateIO")
if err != nil {
t.Error("Test Failed - GateIO Setup() init error")
@@ -40,7 +43,10 @@ func TestSetup(t *testing.T) {
gateioConfig.API.Credentials.Key = apiKey
gateioConfig.API.Credentials.Secret = apiSecret
g.Setup(gateioConfig)
err = g.Setup(gateioConfig)
if err != nil {
t.Fatal("Test Failed - GateIO setup error", err)
}
}
func TestGetSymbols(t *testing.T) {

View File

@@ -17,7 +17,10 @@ var mockTests = false
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Gemini load config error", err)
}
geminiConfig, err := cfg.GetExchangeConfig("Gemini")
if err != nil {
log.Fatal("Test Failed - Gemini Setup() init error", err)
@@ -26,7 +29,10 @@ func TestMain(m *testing.M) {
geminiConfig.API.Credentials.Key = apiKey
geminiConfig.API.Credentials.Secret = apiSecret
g.SetDefaults()
g.Setup(geminiConfig)
err = g.Setup(geminiConfig)
if err != nil {
log.Fatal("Test Failed - Gemini setup error", err)
}
g.API.Endpoints.URL = geminiSandboxAPIURL
log.Printf(sharedtestvalues.LiveTesting, g.GetName(), g.API.Endpoints.URL)
os.Exit(m.Run())

View File

@@ -20,7 +20,10 @@ var mockTests = true
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Gemini load config error", err)
}
geminiConfig, err := cfg.GetExchangeConfig("Gemini")
if err != nil {
log.Fatal("Test Failed - Mock server error", err)
@@ -30,7 +33,10 @@ func TestMain(m *testing.M) {
geminiConfig.API.Credentials.Key = apiKey
geminiConfig.API.Credentials.Secret = apiSecret
g.SetDefaults()
g.Setup(geminiConfig)
err = g.Setup(geminiConfig)
if err != nil {
log.Fatal("Test Failed - Gemini setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockFile)
if err != nil {

View File

@@ -31,7 +31,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - HitBTC load config error", err)
}
hitbtcConfig, err := cfg.GetExchangeConfig("HitBTC")
if err != nil {
t.Error("Test Failed - HitBTC Setup() init error")
@@ -41,7 +44,10 @@ func TestSetup(t *testing.T) {
hitbtcConfig.API.Credentials.Key = apiKey
hitbtcConfig.API.Credentials.Secret = apiSecret
h.Setup(hitbtcConfig)
err = h.Setup(hitbtcConfig)
if err != nil {
t.Fatal("Test Failed - HitBTC setup error", err)
}
}
func TestGetOrderbook(t *testing.T) {

View File

@@ -6,6 +6,7 @@ import (
"crypto/x509"
"encoding/pem"
"io/ioutil"
"log"
"strconv"
"strings"
"testing"
@@ -37,7 +38,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Huobi load config error", err)
}
hConfig, err := cfg.GetExchangeConfig("Huobi")
if err != nil {
t.Error("Test Failed - Huobi Setup() init error")
@@ -47,7 +51,10 @@ func TestSetup(t *testing.T) {
hConfig.API.Credentials.Key = apiKey
hConfig.API.Credentials.Secret = apiSecret
h.Setup(hConfig)
err = h.Setup(hConfig)
if err != nil {
t.Fatal("Test Failed - Huobi setup error", err)
}
}
func setupWsTests(t *testing.T) {

View File

@@ -26,17 +26,23 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Itbit load config error", err)
}
itbitConfig, err := cfg.GetExchangeConfig("ITBIT")
if err != nil {
t.Error("Test Failed - Gemini Setup() init error")
t.Error("Test Failed - Itbit Setup() init error")
}
itbitConfig.API.AuthenticatedSupport = true
itbitConfig.API.Credentials.Key = apiKey
itbitConfig.API.Credentials.Secret = apiSecret
itbitConfig.API.Credentials.ClientID = clientID
i.Setup(itbitConfig)
err = i.Setup(itbitConfig)
if err != nil {
t.Fatal("Test Failed - Itbit setup error", err)
}
}
func TestGetTicker(t *testing.T) {

View File

@@ -1,6 +1,7 @@
package kraken
import (
"log"
"net/http"
"testing"
@@ -31,7 +32,10 @@ func TestSetDefaults(t *testing.T) {
// TestSetup setup func
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Kraken load config error", err)
}
krakenConfig, err := cfg.GetExchangeConfig("Kraken")
if err != nil {
t.Error("Test Failed - kraken Setup() init error", err)
@@ -43,7 +47,10 @@ func TestSetup(t *testing.T) {
krakenConfig.API.Endpoints.WebsocketURL = k.API.Endpoints.WebsocketURL
subscribeToDefaultChannels = false
k.Setup(krakenConfig)
err = k.Setup(krakenConfig)
if err != nil {
t.Fatal("Test Failed - Kraken setup error", err)
}
}
// TestGetServerTime API endpoint test

View File

@@ -2,6 +2,7 @@ package lakebtc
import (
"fmt"
"log"
"testing"
"github.com/thrasher-corp/gocryptotrader/common"
@@ -32,7 +33,10 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
if !setupRan {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - LakeBTC load config error", err)
}
lakebtcConfig, err := cfg.GetExchangeConfig("LakeBTC")
if err != nil {
t.Error("Test Failed - LakeBTC Setup() init error")
@@ -41,7 +45,10 @@ func TestSetup(t *testing.T) {
lakebtcConfig.API.Credentials.Key = apiKey
lakebtcConfig.API.Credentials.Secret = apiSecret
lakebtcConfig.Features.Enabled.Websocket = true
l.Setup(lakebtcConfig)
err = l.Setup(lakebtcConfig)
if err != nil {
t.Fatal("Test Failed - LakeBTC setup error", err)
}
l.API.Endpoints.WebsocketURL = lakeBTCWSURL
setupRan = true
}

View File

@@ -32,18 +32,21 @@ func TestSetup(t *testing.T) {
}
l.SetDefaults()
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Errorf("Test Failed - Lbank Setup() init error:, %v", err)
t.Fatalf("Test Failed - Lbank Setup() init error:, %v", err)
}
lbankConfig, err := cfg.GetExchangeConfig("Lbank")
if err != nil {
t.Errorf("Test Failed - Lbank Setup() init error: %v", err)
t.Fatalf("Test Failed - Lbank Setup() init error: %v", err)
}
lbankConfig.API.AuthenticatedSupport = true
lbankConfig.API.Credentials.Secret = testAPISecret
lbankConfig.API.Credentials.Key = testAPIKey
l.Setup(lbankConfig)
err = l.Setup(lbankConfig)
if err != nil {
t.Fatal("Test Failed - LBank setup error", err)
}
setupRan = true
}

View File

@@ -17,7 +17,10 @@ var mockTests = false
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - LocalBitcoins load config error", err)
}
localbitcoinsConfig, err := cfg.GetExchangeConfig("LocalBitcoins")
if err != nil {
log.Fatal("Test Failed - LocalBitcoins Setup() init error", err)
@@ -26,7 +29,10 @@ func TestMain(m *testing.M) {
localbitcoinsConfig.API.Credentials.Key = apiKey
localbitcoinsConfig.API.Credentials.Secret = apiSecret
l.SetDefaults()
l.Setup(localbitcoinsConfig)
err = l.Setup(localbitcoinsConfig)
if err != nil {
log.Fatal("Test Failed - Localbitcoins setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, l.GetName(), l.API.Endpoints.URL)
os.Exit(m.Run())
}

View File

@@ -20,7 +20,10 @@ var mockTests = true
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Localbitcoins load config error", err)
}
localbitcoinsConfig, err := cfg.GetExchangeConfig("LocalBitcoins")
if err != nil {
log.Fatal("Test Failed - Localbitcoins Setup() init error", err)
@@ -30,7 +33,10 @@ func TestMain(m *testing.M) {
localbitcoinsConfig.API.Credentials.Key = apiKey
localbitcoinsConfig.API.Credentials.Secret = apiSecret
l.SetDefaults()
l.Setup(localbitcoinsConfig)
err = l.Setup(localbitcoinsConfig)
if err != nil {
log.Fatal("Test Failed - Localbitcoins setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
if err != nil {

View File

@@ -62,7 +62,10 @@ func TestSetup(t *testing.T) {
}
o.ExchangeName = OKGroupExchange
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Okcoin load config error", err)
}
okcoinConfig, err := cfg.GetExchangeConfig(OKGroupExchange)
if err != nil {
t.Fatalf("Test Failed - %v Setup() init error", OKGroupExchange)
@@ -77,7 +80,10 @@ func TestSetup(t *testing.T) {
okcoinConfig.API.Credentials.Secret = apiSecret
okcoinConfig.API.Credentials.ClientID = passphrase
okcoinConfig.API.Endpoints.WebsocketURL = o.API.Endpoints.WebsocketURL
o.Setup(okcoinConfig)
err = o.Setup(okcoinConfig)
if err != nil {
t.Fatal("Test Failed - OKCoin setup error", err)
}
testSetupRan = true
o.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
o.Websocket.TrafficAlert = sharedtestvalues.GetWebsocketStructChannelOverride()

View File

@@ -63,7 +63,10 @@ func TestSetup(t *testing.T) {
}
o.ExchangeName = OKGroupExchange
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Okex load config error", err)
}
okexConfig, err := cfg.GetExchangeConfig(OKGroupExchange)
if err != nil {
@@ -78,7 +81,10 @@ func TestSetup(t *testing.T) {
okexConfig.API.Credentials.Secret = apiSecret
okexConfig.API.Credentials.ClientID = passphrase
okexConfig.API.Endpoints.WebsocketURL = o.API.Endpoints.WebsocketURL
o.Setup(okexConfig)
err = o.Setup(okexConfig)
if err != nil {
t.Fatal("Test Failed - Okex setup error", err)
}
testSetupRan = true
o.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
o.Websocket.TrafficAlert = sharedtestvalues.GetWebsocketStructChannelOverride()

View File

@@ -17,7 +17,10 @@ var mockTests = false
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Poloniex load config error", err)
}
poloniexConfig, err := cfg.GetExchangeConfig("Poloniex")
if err != nil {
log.Fatal("Test Failed - Poloniex Setup() init error", err)
@@ -26,7 +29,10 @@ func TestMain(m *testing.M) {
poloniexConfig.API.Credentials.Key = apiKey
poloniexConfig.API.Credentials.Secret = apiSecret
p.SetDefaults()
p.Setup(poloniexConfig)
err = p.Setup(poloniexConfig)
if err != nil {
log.Fatal("Test Failed - Poloniex setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, p.GetName(), p.API.Endpoints.URL)
os.Exit(m.Run())
}

View File

@@ -20,7 +20,10 @@ var mockTests = true
func TestMain(m *testing.M) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Poloniex load config error", err)
}
poloniexConfig, err := cfg.GetExchangeConfig("Poloniex")
if err != nil {
log.Fatal("Test Failed - Poloniex Setup() init error", err)
@@ -30,7 +33,10 @@ func TestMain(m *testing.M) {
poloniexConfig.API.Credentials.Key = apiKey
poloniexConfig.API.Credentials.Secret = apiSecret
p.SetDefaults()
p.Setup(poloniexConfig)
err = p.Setup(poloniexConfig)
if err != nil {
log.Fatal("Test Failed - Poloniex setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
if err != nil {

View File

@@ -27,16 +27,22 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
yobitConfig := config.GetConfig()
yobitConfig.LoadConfig("../../testdata/configtest.json")
err := yobitConfig.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Yobit load config error", err)
}
conf, err := yobitConfig.GetExchangeConfig("Yobit")
if err != nil {
t.Error("Test Failed - Yobit init error")
t.Fatal("Test Failed - Yobit init error", err)
}
conf.API.Credentials.Key = apiKey
conf.API.Credentials.Secret = apiSecret
conf.API.AuthenticatedSupport = true
y.Setup(conf)
err = y.Setup(conf)
if err != nil {
t.Fatal("Test Failed - Yobit setup error", err)
}
}
func TestFetchTradablePairs(t *testing.T) {

View File

@@ -29,17 +29,23 @@ func TestSetDefaults(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - ZB load config error", err)
}
zbConfig, err := cfg.GetExchangeConfig("ZB")
if err != nil {
t.Error("Test Failed - ZB Setup() init error")
t.Fatal("Test Failed - ZB Setup() init error", err)
}
zbConfig.API.AuthenticatedSupport = true
zbConfig.API.AuthenticatedWebsocketSupport = true
zbConfig.API.Credentials.Key = apiKey
zbConfig.API.Credentials.Secret = apiSecret
z.Setup(zbConfig)
err = z.Setup(zbConfig)
if err != nil {
t.Fatal("Test Failed - ZB setup error", err)
}
}
func setupWsAuth(t *testing.T) {

10
main.go
View File

@@ -8,7 +8,6 @@ import (
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/core"
mg "github.com/thrasher-corp/gocryptotrader/database/migration"
"github.com/thrasher-corp/gocryptotrader/engine"
@@ -18,18 +17,12 @@ import (
)
func main() {
defaultPath, err := config.GetFilePath("")
if err != nil {
log.Errorln(log.Global, err)
os.Exit(1)
}
// Handle flags
var settings engine.Settings
versionFlag := flag.Bool("version", false, "retrieves current GoCryptoTrader version")
// Core settings
flag.StringVar(&settings.ConfigFile, "config", defaultPath, "config file to load")
flag.StringVar(&settings.ConfigFile, "config", "", "config file to load")
flag.StringVar(&settings.DataDir, "datadir", common.GetDefaultDataDir(runtime.GOOS), "default data directory for GoCryptoTrader files")
flag.StringVar(&settings.MigrationDir, "migrationdir", mg.MigrationDir, "override migration folder")
flag.IntVar(&settings.GoMaxProcs, "gomaxprocs", runtime.NumCPU(), "sets the runtime GOMAXPROCS value")
@@ -92,6 +85,7 @@ func main() {
fmt.Println(core.Banner)
fmt.Println(core.Version(false))
var err error
engine.Bot, err = engine.NewFromSettings(&settings)
if engine.Bot == nil || err != nil {
log.Errorf(log.Global, "Unable to initialise bot engine. Error: %s\n", err)