Implement dry run mode, won't save config (to be used in future modes)
@@ -28,6 +28,7 @@ type Bot struct {
portfolio *portfolio.Base
exchanges []exchange.IBotExchange
shutdown chan bool
+ dryRun bool
configFile string
}
@@ -38,6 +39,7 @@ func main() {
//Handle flags
flag.StringVar(&bot.configFile, "config", config.GetFilePath(""), "config file to load")
+ dryrun := flag.Bool("dryrun", false, "dry runs bot, doesn't save config file")
version := flag.Bool("version", false, "retrieves current GoCryptoTrader version")
flag.Parse()
@@ -46,6 +48,10 @@ func main() {
os.Exit(0)
}
+ if *dryrun {
+ bot.dryRun = true
+ }
+
bot.config = &config.Cfg
fmt.Println(BuildVersion(false))
log.Printf("Loading config file %s..\n", bot.configFile)
@@ -58,6 +64,7 @@ func main() {
AdjustGoMaxProcs()
log.Printf("Bot '%s' started.\n", bot.config.Name)
log.Printf("Fiat display currency: %s.", bot.config.FiatDisplayCurrency)
+ log.Printf("Bot dry run mode: %v\n", common.IsEnabled(bot.dryRun))
if bot.config.SMS.Enabled {
bot.smsglobal = smsglobal.New(bot.config.SMS.Username, bot.config.SMS.Password,
@@ -166,6 +173,8 @@ func HandleInterrupt() {
func Shutdown() {
log.Println("Bot shutting down..")
bot.config.Portfolio = portfolio.Portfolio
+
+ if !bot.dryRun {
err := bot.config.SaveConfig(bot.configFile)
if err != nil {
@@ -173,6 +182,7 @@ func Shutdown() {
} else {
log.Println("Config file saved successfully.")
}
+ }
log.Println("Exiting.")
os.Exit(1)
