diff --git a/README.md b/README.md index 4c48fe1f..49a38e3a 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Download and install Go from [Go Downloads](https://golang.org/dl/) go get github.com/thrasher-/gocryptotrader cd $GOPATH/src/github.com/thrasher-/gocryptotrader go install -cp $GOPATH/src/github.com/thrasher-/gocryptotrader/config_example.dat $GOPATH/bin/config.dat +cp $GOPATH/src/github.com/thrasher-/gocryptotrader/config_example.json $GOPATH/bin/config.json ``` Make any neccessary changes to the config file. diff --git a/config/config.go b/config/config.go index d944cddf..ec87ed57 100644 --- a/config/config.go +++ b/config/config.go @@ -19,9 +19,9 @@ import ( // Constants declared here are filename strings and test strings const ( - ConfigFile = "config.dat" - OldConfigFile = "config.json" - ConfigTestFile = "../testdata/configtest.dat" + EncryptedConfigFile = "config.dat" + ConfigFile = "config.json" + ConfigTestFile = "../testdata/configtest.json" configFileEncryptionPrompt = 0 configFileEncryptionEnabled = 1 configFileEncryptionDisabled = -1 @@ -47,7 +47,6 @@ var ( WarningWebserverRootWebFolderNotFound = "WARNING -- Webserver support disabled due to missing web folder." WarningExchangeAuthAPIDefaultOrEmptyValues = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values." WarningCurrencyExchangeProvider = "WARNING -- Currency exchange provider invalid valid. Reset to Fixer." - RenamingConfigFile = "Renaming config file %s to %s." Cfg Config ) @@ -317,34 +316,37 @@ func GetFilePath(file string) string { return file } if flag.Lookup("test.v") == nil { - return ConfigFile + data, err := common.ReadFile(EncryptedConfigFile) + if err == nil { + if ConfirmECS(data) { + return EncryptedConfigFile + } + err = os.Rename(EncryptedConfigFile, ConfigFile) + if err != nil { + log.Fatalf("Unable to rename config file: %s", err) + } + log.Printf("Renaming non-encrypted config file from %s to %s", + EncryptedConfigFile, ConfigFile) + return ConfigFile + } + if !ConfirmECS(data) { + return ConfigFile + } + err = os.Rename(ConfigFile, EncryptedConfigFile) + if err != nil { + log.Fatalf("Unable to rename config file: %s", err) + } + log.Printf("Renaming encrypted config file from %s to %s", ConfigFile, + EncryptedConfigFile) + return EncryptedConfigFile } return ConfigTestFile } -// CheckConfig checks to see if there is an old configuration filename and path -// if found it will change it to correct filename. -func CheckConfig() error { - _, err := common.ReadFile(OldConfigFile) - if err == nil { - err = os.Rename(OldConfigFile, ConfigFile) - if err != nil { - return err - } - log.Printf(RenamingConfigFile+"\n", OldConfigFile, ConfigFile) - } - return nil -} - // ReadConfig verifies and checks for encryption and verifies the unencrypted // file contains JSON. func (c *Config) ReadConfig(configPath string) error { defaultPath := GetFilePath(configPath) - err := CheckConfig() - if err != nil { - return err - } - file, err := common.ReadFile(defaultPath) if err != nil { return err diff --git a/config_example.dat b/config_example.json similarity index 100% rename from config_example.dat rename to config_example.json diff --git a/exchanges/anx/anx_test.go b/exchanges/anx/anx_test.go index c5ede53e..cb7ff28f 100644 --- a/exchanges/anx/anx_test.go +++ b/exchanges/anx/anx_test.go @@ -37,7 +37,7 @@ func TestSetup(t *testing.T) { setup := ANX{} setup.Name = "ANX" anxSetupConfig := config.GetConfig() - anxSetupConfig.LoadConfig("../../testdata/configtest.dat") + anxSetupConfig.LoadConfig("../../testdata/configtest.json") anxConfig, err := anxSetupConfig.GetExchangeConfig("ANX") if err != nil { t.Error("Test Failed - ANX Setup() init error") diff --git a/exchanges/bitfinex/bitfinex_test.go b/exchanges/bitfinex/bitfinex_test.go index 03363c5d..f81f439c 100644 --- a/exchanges/bitfinex/bitfinex_test.go +++ b/exchanges/bitfinex/bitfinex_test.go @@ -32,7 +32,7 @@ func TestSetup(t *testing.T) { setup := Bitfinex{} setup.Name = "Bitfinex" cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") bfxConfig, err := cfg.GetExchangeConfig("Bitfinex") if err != nil { t.Error("Test Failed - Bitfinex Setup() init error") diff --git a/exchanges/bitfinex/bitfinex_wrapper.go b/exchanges/bitfinex/bitfinex_wrapper.go index 8108e0b5..cb432330 100644 --- a/exchanges/bitfinex/bitfinex_wrapper.go +++ b/exchanges/bitfinex/bitfinex_wrapper.go @@ -79,10 +79,10 @@ func (b *Bitfinex) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderb // UpdateOrderbook updates and returns the orderbook for a currency pair func (b *Bitfinex) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) { var orderBook orderbook.Base - var vals url.Values - vals.Set("limit_bids", "100") - vals.Set("limit_asks", "100") - orderbookNew, err := b.GetOrderbook(p.Pair().String(), vals) + urlVals := url.Values{} + urlVals.Set("limit_bids", "100") + urlVals.Set("limit_asks", "100") + orderbookNew, err := b.GetOrderbook(p.Pair().String(), urlVals) if err != nil { return orderBook, err } diff --git a/exchanges/bitstamp/bitstamp_test.go b/exchanges/bitstamp/bitstamp_test.go index ce298211..3eb2ad3d 100644 --- a/exchanges/bitstamp/bitstamp_test.go +++ b/exchanges/bitstamp/bitstamp_test.go @@ -42,7 +42,7 @@ func TestSetup(t *testing.T) { b := Bitstamp{} b.Name = "Bitstamp" cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") bConfig, err := cfg.GetExchangeConfig("Bitstamp") if err != nil { t.Error("Test Failed - Bitstamp Setup() init error") diff --git a/exchanges/bittrex/bittrex_test.go b/exchanges/bittrex/bittrex_test.go index 99e5e209..f16fc2c4 100644 --- a/exchanges/bittrex/bittrex_test.go +++ b/exchanges/bittrex/bittrex_test.go @@ -27,7 +27,7 @@ func TestSetup(t *testing.T) { b := Bittrex{} b.Name = "Bittrex" cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") bConfig, err := cfg.GetExchangeConfig("Bittrex") if err != nil { t.Error("Test Failed - Bittrex Setup() init error") diff --git a/exchanges/btcc/btcc_test.go b/exchanges/btcc/btcc_test.go index 56826455..ba52fdff 100644 --- a/exchanges/btcc/btcc_test.go +++ b/exchanges/btcc/btcc_test.go @@ -23,7 +23,7 @@ func TestSetup(t *testing.T) { t.Parallel() b.Name = "BTCC" cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") bConfig, err := cfg.GetExchangeConfig("BTCC") if err != nil { t.Error("Test Failed - BTCC Setup() init error") diff --git a/exchanges/btcmarkets/btcmarkets_test.go b/exchanges/btcmarkets/btcmarkets_test.go index bc0e9776..7740f253 100644 --- a/exchanges/btcmarkets/btcmarkets_test.go +++ b/exchanges/btcmarkets/btcmarkets_test.go @@ -25,7 +25,7 @@ func TestSetup(t *testing.T) { b := BTCMarkets{} b.Name = "BTC Markets" cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") bConfig, err := cfg.GetExchangeConfig("BTC Markets") if err != nil { t.Error("Test Failed - BTC Markets Setup() init error") diff --git a/exchanges/gdax/gdax_test.go b/exchanges/gdax/gdax_test.go index fd2ae99a..e4ec5d58 100644 --- a/exchanges/gdax/gdax_test.go +++ b/exchanges/gdax/gdax_test.go @@ -21,7 +21,7 @@ func TestSetDefaults(t *testing.T) { func TestSetup(t *testing.T) { cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") gdxConfig, err := cfg.GetExchangeConfig("Bitfinex") if err != nil { t.Error("Test Failed - GDAX Setup() init error") diff --git a/exchanges/gemini/gemini_test.go b/exchanges/gemini/gemini_test.go index 1f139f3a..5b583c1e 100644 --- a/exchanges/gemini/gemini_test.go +++ b/exchanges/gemini/gemini_test.go @@ -47,7 +47,7 @@ func TestSetDefaults(t *testing.T) { func TestSetup(t *testing.T) { cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") geminiConfig, err := cfg.GetExchangeConfig("Gemini") if err != nil { t.Error("Test Failed - Gemini Setup() init error") diff --git a/exchanges/itbit/itbit_test.go b/exchanges/itbit/itbit_test.go index 88c51689..2ae18ab7 100644 --- a/exchanges/itbit/itbit_test.go +++ b/exchanges/itbit/itbit_test.go @@ -22,7 +22,7 @@ func TestSetDefaults(t *testing.T) { func TestSetup(t *testing.T) { cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") itbitConfig, err := cfg.GetExchangeConfig("ITBIT") if err != nil { t.Error("Test Failed - Gemini Setup() init error") @@ -124,6 +124,7 @@ func TestGetOrder(t *testing.T) { } func TestCancelOrder(t *testing.T) { + t.Skip() err := i.CancelOrder("1337", "1337order") if err == nil { t.Error("Test Failed - CancelOrder() error", err) diff --git a/exchanges/liqui/liqui_test.go b/exchanges/liqui/liqui_test.go index eaddeb06..dcb28cbd 100644 --- a/exchanges/liqui/liqui_test.go +++ b/exchanges/liqui/liqui_test.go @@ -20,7 +20,7 @@ func TestSetDefaults(t *testing.T) { func TestSetup(t *testing.T) { cfg := config.GetConfig() - cfg.LoadConfig("../../testdata/configtest.dat") + cfg.LoadConfig("../../testdata/configtest.json") liquiConfig, err := cfg.GetExchangeConfig("Liqui") if err != nil { t.Error("Test Failed - liqui Setup() init error") diff --git a/exchanges/wex/wex_test.go b/exchanges/wex/wex_test.go index 200e5270..6e81be91 100644 --- a/exchanges/wex/wex_test.go +++ b/exchanges/wex/wex_test.go @@ -20,7 +20,7 @@ func TestSetDefaults(t *testing.T) { func TestSetup(t *testing.T) { wexConfig := config.GetConfig() - wexConfig.LoadConfig("../../testdata/configtest.dat") + wexConfig.LoadConfig("../../testdata/configtest.json") conf, err := wexConfig.GetExchangeConfig("WEX") if err != nil { t.Error("Test Failed - WEX init error") diff --git a/testdata/configtest.dat b/testdata/configtest.json similarity index 97% rename from testdata/configtest.dat rename to testdata/configtest.json index ca7b90f1..79c8ac01 100644 --- a/testdata/configtest.dat +++ b/testdata/configtest.json @@ -62,6 +62,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -84,6 +85,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -104,6 +106,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -125,6 +128,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -147,6 +151,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -167,6 +172,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -189,6 +195,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -209,6 +216,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -231,6 +239,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -251,6 +260,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -271,6 +281,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -292,6 +303,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -313,6 +325,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -333,6 +346,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -356,6 +370,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -376,6 +391,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -397,6 +413,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", @@ -418,6 +435,7 @@ "Enabled": true, "Verbose": false, "Websocket": false, + "UseSandbox": false, "RESTPollingDelay": 10, "AuthenticatedAPISupport": false, "APIKey": "Key", diff --git a/tools/config/config.go b/tools/config/config.go index a9eeea50..49201a67 100644 --- a/tools/config/config.go +++ b/tools/config/config.go @@ -20,8 +20,9 @@ func main() { var inFile, outFile, key string var encrypt bool var err error - flag.StringVar(&inFile, "infile", "config.dat", "The config input file to process.") - flag.StringVar(&outFile, "outfile", "config.dat.out", "The config output file.") + configFile := config.GetFilePath("") + flag.StringVar(&inFile, "infile", configFile, "The config input file to process.") + flag.StringVar(&outFile, "outfile", configFile+".out", "The config output file.") flag.BoolVar(&encrypt, "encrypt", true, "Wether to encrypt or decrypt.") flag.StringVar(&key, "key", "", "The key to use for AES encryption.") flag.Parse() diff --git a/tools/portfolio/portfolio.go b/tools/portfolio/portfolio.go index bc47dbd1..509057e8 100644 --- a/tools/portfolio/portfolio.go +++ b/tools/portfolio/portfolio.go @@ -57,7 +57,7 @@ func getOnlineOfflinePortfolio(coins []portfolio.Coin, online bool) { func main() { var inFile, key string - flag.StringVar(&inFile, "infile", "config.dat", "The config input file to process.") + flag.StringVar(&inFile, "infile", config.GetFilePath(""), "The config input file to process.") flag.StringVar(&key, "key", "", "The key to use for AES encryption.") flag.Parse()