From 4dc478590fdc165d4c4fb923df84fecce00ba7b3 Mon Sep 17 00:00:00 2001 From: Larry850806 Date: Wed, 17 Mar 2021 14:35:00 +0800 Subject: [PATCH 1/2] Remove configuring database in balances cmd --- pkg/cmd/balances.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/cmd/balances.go b/pkg/cmd/balances.go index f6d0335f6..85f14b7e3 100644 --- a/pkg/cmd/balances.go +++ b/pkg/cmd/balances.go @@ -43,9 +43,6 @@ var balancesCmd = &cobra.Command{ } environ := bbgo.NewEnvironment() - if err := environ.ConfigureDatabase(ctx); err != nil { - return err - } if err := environ.ConfigureExchangeSessions(userConfig); err != nil { return err From 28f458419156d5a306be99a0f51227f414d1320d Mon Sep 17 00:00:00 2001 From: Larry850806 Date: Wed, 17 Mar 2021 20:03:27 +0800 Subject: [PATCH 2/2] Use empty config if config file doesn't exist --- pkg/cmd/balances.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/balances.go b/pkg/cmd/balances.go index 85f14b7e3..3694b1da8 100644 --- a/pkg/cmd/balances.go +++ b/pkg/cmd/balances.go @@ -33,12 +33,20 @@ var balancesCmd = &cobra.Command{ return errors.New("--config option is required") } - if _, err := os.Stat(configFile); os.IsNotExist(err) { - return err - } - - userConfig, err := bbgo.Load(configFile, false) - if err != nil { + // if config file exists, use the config loaded from the config file. + // otherwise, use a empty config object + var userConfig *bbgo.Config + if _, err := os.Stat(configFile); err == nil { + // load successfully + userConfig, err = bbgo.Load(configFile, false) + if err != nil { + return err + } + } else if os.IsNotExist(err) { + // config file doesn't exist + userConfig = &bbgo.Config{} + } else { + // other error return err }