11package exchange
22
33import (
4+ "fmt"
5+
6+ oc "github.com/cordialsys/offchain"
47 "github.com/cordialsys/offchain/client"
58 "github.com/cordialsys/offchain/loader"
9+ "github.com/sirupsen/logrus"
610 "github.com/spf13/cobra"
711)
812
913func NewListBalancesCmd () * cobra.Command {
10- var account string
14+ var accountType string
1115 cmd := & cobra.Command {
1216 SilenceUsage : true ,
1317 Use : "balances" ,
1418 Short : "List your balances on the exchange" ,
1519 RunE : func (cmd * cobra.Command , args []string ) error {
1620 exchangeConfig , secrets := unwrapAccountConfig (cmd .Context ())
17- cli , err := loader .NewClient (exchangeConfig . ExchangeId , & exchangeConfig . ExchangeClientConfig , secrets )
21+ cli , err := loader .NewClient (exchangeConfig , secrets )
1822 if err != nil {
1923 return err
2024 }
21- accountType := client .AccountType ("" ) //client.CoreFunding
22- if account != "" {
23- accountType = client .AccountType (account )
25+ balanceArgs := client .NewGetBalanceArgs ("" )
26+ if accountType != "" {
27+ at , ok , message := exchangeConfig .ResolveAccountType (accountType )
28+ if ! ok {
29+ return fmt .Errorf ("%s" , message )
30+ }
31+ balanceArgs .SetAccountType (at .Type )
32+ } else {
33+ // try taking the first account type
34+ defaults , ok := oc .GetDefaultConfig (exchangeConfig .ExchangeId )
35+ if ok {
36+ if len (defaults .AccountTypes ) > 0 {
37+ logrus .WithFields (logrus.Fields {
38+ "type" : defaults .AccountTypes [0 ].Type ,
39+ }).Infof ("using default account type" )
40+ balanceArgs .SetAccountType (defaults .AccountTypes [0 ].Type )
41+ }
42+ }
2443 }
25- balanceArgs := client .NewGetBalanceArgs (accountType )
2644
2745 assets , err := cli .ListBalances (balanceArgs )
2846 if err != nil {
@@ -33,10 +51,10 @@ func NewListBalancesCmd() *cobra.Command {
3351 },
3452 }
3553 cmd .Flags ().StringVar (
36- & account ,
37- "account " ,
54+ & accountType ,
55+ "type " ,
3856 "" ,
39- "the account to get balances for" ,
57+ "the account type to get balances for" ,
4058 )
4159 return cmd
4260}
0 commit comments