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,17 +62,30 @@ var accountCmd = &cobra.Command{
return err
}
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
if len(sessionName) > 0 {
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
}
a, err := session.Exchange.QueryAccount(ctx)
if err != nil {
return err
}
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()
}
}
a, err := session.Exchange.QueryAccount(ctx)
if err != nil {
return err
}
log.Infof("account info: %+v", a)
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,17 +64,32 @@ var balancesCmd = &cobra.Command{
}
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
if len(sessionName) > 0 {
session, ok := environ.Session(sessionName)
if !ok {
return fmt.Errorf("session %s not found", sessionName)
}
b, err := session.Exchange.QueryAccountBalances(ctx)
if err != nil {
return err
}
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()
}
}
b, err := session.Exchange.QueryAccountBalances(ctx)
if err != nil {
return err
}
log.Infof("balances: %+v", b)
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()
}