diff --git a/pkg/cmd/account.go b/pkg/cmd/account.go index 31d39fdea..94861e5cf 100644 --- a/pkg/cmd/account.go +++ b/pkg/cmd/account.go @@ -33,6 +33,15 @@ var accountCmd = &cobra.Command{ return errors.New("--config option is required") } + sessionName, err := cmd.Flags().GetString("session") + if err != nil { + return err + } + + if len(sessionName) == 0 { + return errors.New("--session option is required") + } + var userConfig *bbgo.Config if _, err := os.Stat(configFile); err == nil { // load successfully @@ -57,11 +66,6 @@ var accountCmd = &cobra.Command{ return err } - sessionName, err := cmd.Flags().GetString("session") - if err != nil { - return err - } - session, ok := environ.Session(sessionName) if !ok { return fmt.Errorf("session %s not found", sessionName) diff --git a/pkg/cmd/balances.go b/pkg/cmd/balances.go index 3694b1da8..b84d83eca 100644 --- a/pkg/cmd/balances.go +++ b/pkg/cmd/balances.go @@ -24,6 +24,7 @@ var balancesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() + configFile, err := cmd.Flags().GetString("config") if err != nil { return err @@ -33,6 +34,15 @@ var balancesCmd = &cobra.Command{ return errors.New("--config option is required") } + sessionName, err := cmd.Flags().GetString("session") + if err != nil { + return err + } + + if len(sessionName) == 0 { + return errors.New("--session option is required") + } + // if config file exists, use the config loaded from the config file. // otherwise, use a empty config object var userConfig *bbgo.Config @@ -56,10 +66,6 @@ var balancesCmd = &cobra.Command{ return err } - sessionName, err := cmd.Flags().GetString("session") - if err != nil { - return err - } session, ok := environ.Session(sessionName) if !ok {