cmd: move simple session factory to cmd/utils.go

This commit is contained in:
ycdesu 2021-02-27 18:40:53 +08:00
parent 5196df9620
commit 282ce3ee99
2 changed files with 17 additions and 17 deletions

View File

@ -6,10 +6,6 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/exchange/ftx"
"github.com/c9s/bbgo/pkg/types"
) )
//godotenv -f .env.local go run ./cmd/bbgo balances --session=ftx //godotenv -f .env.local go run ./cmd/bbgo balances --session=ftx
@ -41,16 +37,3 @@ func init() {
RootCmd.AddCommand(balancesCmd) RootCmd.AddCommand(balancesCmd)
} }
func newExchange(session string) (types.Exchange, error) {
switch session {
case "ftx":
return ftx.NewExchange(
viper.GetString("ftx-api-key"),
viper.GetString("ftx-api-secret"),
viper.GetString("ftx-subaccount-name"),
), nil
}
return nil, fmt.Errorf("unsupported session %s", session)
}

View File

@ -1,6 +1,11 @@
package cmd package cmd
import ( import (
"fmt"
"github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/exchange/ftx"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
@ -10,3 +15,15 @@ func inBaseAsset(balances types.BalanceMap, market types.Market, price float64)
return (base.Locked.Float64() + base.Available.Float64()) + ((quote.Locked.Float64() + quote.Available.Float64()) / price) return (base.Locked.Float64() + base.Available.Float64()) + ((quote.Locked.Float64() + quote.Available.Float64()) / price)
} }
func newExchange(session string) (types.Exchange, error) {
switch session {
case "ftx":
return ftx.NewExchange(
viper.GetString("ftx-api-key"),
viper.GetString("ftx-api-secret"),
viper.GetString("ftx-subaccount-name"),
), nil
}
return nil, fmt.Errorf("unsupported session %s", session)
}