improve balances, account command usability

This commit is contained in:
c9s 2021-05-06 23:50:26 +08:00
parent 1a81813e17
commit 1264c50e83
3 changed files with 52 additions and 28 deletions

View File

@ -38,10 +38,6 @@ var accountCmd = &cobra.Command{
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
@ -66,6 +62,7 @@ var accountCmd = &cobra.Command{
return err
}
if len(sessionName) > 0 {
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
@ -76,7 +73,19 @@ var accountCmd = &cobra.Command{
return err
}
log.Infof("account info: %+v", a)
a.Print()
} else {
for _, session := range environ.Sessions() {
a, err := session.Exchange.QueryAccount(ctx)
if err != nil {
return err
}
log.Infof("SESSION %s", session.Name)
a.Print()
}
}
return nil
},
}

View File

@ -39,9 +39,6 @@ var balancesCmd = &cobra.Command{
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
@ -67,6 +64,7 @@ var balancesCmd = &cobra.Command{
}
if len(sessionName) > 0 {
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
@ -77,7 +75,21 @@ var balancesCmd = &cobra.Command{
return err
}
log.Infof("balances: %+v", b)
b.Print()
} else {
for _, session := range environ.Sessions() {
b, err := session.Exchange.QueryAccountBalances(ctx)
if err != nil {
return err
}
log.Infof("SESSION %s", session.Name)
b.Print()
}
}
return nil
},
}

View File

@ -229,9 +229,12 @@ func (a *Account) Print() {
a.Lock()
defer a.Unlock()
for _, balance := range a.balances {
if balance.Available != 0 {
logrus.Infof("account balance %s %f", balance.Currency, balance.Available.Float64())
}
if a.AccountType != "" {
logrus.Infof("account type: %s", a.AccountType)
}
logrus.Infof("maker commission: %f", a.MakerCommission.Float64())
logrus.Infof("taker commission: %f", a.TakerCommission.Float64())
a.balances.Print()
}