mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
fix: mark flags as required during PreRunE
This commit is contained in:
parent
9c36e59f84
commit
a33b748563
|
@ -3,7 +3,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -25,18 +24,12 @@ var accountCmd = &cobra.Command{
|
||||||
Use: "account [--session=[exchange_name]]",
|
Use: "account [--session=[exchange_name]]",
|
||||||
Short: "show user account details (ex: balance)",
|
Short: "show user account details (ex: balance)",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
configFile, err := cmd.Flags().GetString("config")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(configFile) == 0 {
|
|
||||||
return errors.New("--config option is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
showTotal, err := cmd.Flags().GetBool("total")
|
showTotal, err := cmd.Flags().GetBool("total")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -47,21 +40,6 @@ var accountCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var userConfig *bbgo.Config
|
|
||||||
if _, err := os.Stat(configFile); err == nil {
|
|
||||||
// load successfully
|
|
||||||
userConfig, err = bbgo.Load(configFile, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if os.IsNotExist(err) {
|
|
||||||
// config file doesn't exist
|
|
||||||
userConfig = &bbgo.Config{}
|
|
||||||
} else {
|
|
||||||
// other error
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureDatabase(ctx); err != nil {
|
if err := environ.ConfigureDatabase(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -20,6 +20,10 @@ var balancesCmd = &cobra.Command{
|
||||||
Use: "balances [--session SESSION]",
|
Use: "balances [--session SESSION]",
|
||||||
Short: "Show user account balances",
|
Short: "Show user account balances",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -28,10 +32,6 @@ var balancesCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return fmt.Errorf("user config is not loaded")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
|
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ var cancelOrderCmd = &cobra.Command{
|
||||||
|
|
||||||
// SilenceUsage is an option to silence usage when an error occurs.
|
// SilenceUsage is an option to silence usage when an error occurs.
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{"config"}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -70,10 +69,6 @@ var cancelOrderCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("config file is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/bbgo"
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
"github.com/c9s/bbgo/pkg/cmd/cmdutil"
|
"github.com/c9s/bbgo/pkg/cmd/cmdutil"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
"github.com/pkg/errors"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -17,13 +16,15 @@ import (
|
||||||
var klineCmd = &cobra.Command{
|
var klineCmd = &cobra.Command{
|
||||||
Use: "kline",
|
Use: "kline",
|
||||||
Short: "connect to the kline market data streaming service of an exchange",
|
Short: "connect to the kline market data streaming service of an exchange",
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
"symbol",
|
||||||
|
"interval",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("--config option or config file is missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -19,6 +18,11 @@ import (
|
||||||
var orderbookCmd = &cobra.Command{
|
var orderbookCmd = &cobra.Command{
|
||||||
Use: "orderbook --session=[exchange_name] --symbol=[pair_name]",
|
Use: "orderbook --session=[exchange_name] --symbol=[pair_name]",
|
||||||
Short: "connect to the order book market data streaming service of an exchange",
|
Short: "connect to the order book market data streaming service of an exchange",
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
"symbol",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -41,10 +45,6 @@ var orderbookCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("--config option or config file is missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -114,13 +114,13 @@ var orderbookCmd = &cobra.Command{
|
||||||
var orderUpdateCmd = &cobra.Command{
|
var orderUpdateCmd = &cobra.Command{
|
||||||
Use: "orderupdate",
|
Use: "orderupdate",
|
||||||
Short: "Listen to order update events",
|
Short: "Listen to order update events",
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("--config option or config file is missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -23,13 +23,14 @@ var getOrderCmd = &cobra.Command{
|
||||||
Use: "get-order --session SESSION --order-id ORDER_ID",
|
Use: "get-order --session SESSION --order-id ORDER_ID",
|
||||||
Short: "Get order status",
|
Short: "Get order status",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"order-id",
|
||||||
|
"symbol",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("config file is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -76,13 +77,14 @@ var listOrdersCmd = &cobra.Command{
|
||||||
// default is open which means we query open orders if you haven't provided args.
|
// default is open which means we query open orders if you haven't provided args.
|
||||||
ValidArgs: []string{"", "open", "closed"},
|
ValidArgs: []string{"", "open", "closed"},
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
"symbol",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("config file is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -146,13 +148,16 @@ var executeOrderCmd = &cobra.Command{
|
||||||
Use: "execute-order --session SESSION --symbol SYMBOL --side SIDE --target-quantity TOTAL_QUANTITY --slice-quantity SLICE_QUANTITY",
|
Use: "execute-order --session SESSION --symbol SYMBOL --side SIDE --target-quantity TOTAL_QUANTITY --slice-quantity SLICE_QUANTITY",
|
||||||
Short: "execute buy/sell on the balance/position you have on specific symbol",
|
Short: "execute buy/sell on the balance/position you have on specific symbol",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"symbol",
|
||||||
|
"side",
|
||||||
|
"target-quantity",
|
||||||
|
"slice-quantity",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("config file is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionName, err := cmd.Flags().GetString("session")
|
sessionName, err := cmd.Flags().GetString("session")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -294,13 +299,17 @@ var submitOrderCmd = &cobra.Command{
|
||||||
Use: "submit-order --session SESSION --symbol SYMBOL --side SIDE --quantity QUANTITY [--price PRICE]",
|
Use: "submit-order --session SESSION --symbol SYMBOL --side SIDE --quantity QUANTITY [--price PRICE]",
|
||||||
Short: "place order to the exchange",
|
Short: "place order to the exchange",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
"symbol",
|
||||||
|
"side",
|
||||||
|
"price",
|
||||||
|
"quantity",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("config file is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionName, err := cmd.Flags().GetString("session")
|
sessionName, err := cmd.Flags().GetString("session")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -40,6 +40,9 @@ var RunCmd = &cobra.Command{
|
||||||
|
|
||||||
// SilenceUsage is an option to silence usage when an error occurs.
|
// SilenceUsage is an option to silence usage when an error occurs.
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
}),
|
||||||
RunE: run,
|
RunE: run,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +231,6 @@ func run(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var userConfig = &bbgo.Config{}
|
|
||||||
|
|
||||||
if !setup {
|
if !setup {
|
||||||
// if it's not setup, then the config file option is required.
|
// if it's not setup, then the config file option is required.
|
||||||
if len(configFile) == 0 {
|
if len(configFile) == 0 {
|
||||||
|
@ -240,10 +241,6 @@ func run(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
userConfig, err = bbgo.Load(configFile, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -259,6 +256,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||||
return runSetup(ctx, userConfig, true)
|
return runSetup(ctx, userConfig, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default setting is false, here load as true
|
||||||
userConfig, err = bbgo.Load(configFile, true)
|
userConfig, err = bbgo.Load(configFile, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,11 +3,9 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -21,35 +19,14 @@ var tradesCmd = &cobra.Command{
|
||||||
Use: "trades --session=[exchange_name] --symbol=[pair_name]",
|
Use: "trades --session=[exchange_name] --symbol=[pair_name]",
|
||||||
Short: "Query trading history",
|
Short: "Query trading history",
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
"symbol",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
configFile, err := cmd.Flags().GetString("config")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(configFile) == 0 {
|
|
||||||
return errors.New("--config 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
|
|
||||||
if _, err := os.Stat(configFile); err == nil {
|
|
||||||
// load successfully
|
|
||||||
userConfig, err = bbgo.Load(configFile, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if os.IsNotExist(err) {
|
|
||||||
// config file doesn't exist
|
|
||||||
userConfig = &bbgo.Config{}
|
|
||||||
} else {
|
|
||||||
// other error
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
|
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
|
@ -120,35 +97,13 @@ var tradesCmd = &cobra.Command{
|
||||||
var tradeUpdateCmd = &cobra.Command{
|
var tradeUpdateCmd = &cobra.Command{
|
||||||
Use: "tradeupdate --session=[exchange_name]",
|
Use: "tradeupdate --session=[exchange_name]",
|
||||||
Short: "Listen to trade update events",
|
Short: "Listen to trade update events",
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
configFile, err := cmd.Flags().GetString("config")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(configFile) == 0 {
|
|
||||||
return errors.New("--config 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
|
|
||||||
if _, err := os.Stat(configFile); err == nil {
|
|
||||||
// load successfully
|
|
||||||
userConfig, err = bbgo.Load(configFile, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if os.IsNotExist(err) {
|
|
||||||
// config file doesn't exist
|
|
||||||
userConfig = &bbgo.Config{}
|
|
||||||
} else {
|
|
||||||
// other error
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
environ := bbgo.NewEnvironment()
|
environ := bbgo.NewEnvironment()
|
||||||
|
|
||||||
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -19,13 +18,13 @@ import (
|
||||||
var userDataStreamCmd = &cobra.Command{
|
var userDataStreamCmd = &cobra.Command{
|
||||||
Use: "userdatastream",
|
Use: "userdatastream",
|
||||||
Short: "Listen to session events (orderUpdate, tradeUpdate, balanceUpdate, balanceSnapshot)",
|
Short: "Listen to session events (orderUpdate, tradeUpdate, balanceUpdate, balanceSnapshot)",
|
||||||
|
PreRunE: cobraInitRequired([]string{
|
||||||
|
"config",
|
||||||
|
"session",
|
||||||
|
}),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
if userConfig == nil {
|
|
||||||
return errors.New("--config option or config file is missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionName, err := cmd.Flags().GetString("session")
|
sessionName, err := cmd.Flags().GetString("session")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -8,8 +8,21 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/exchange/ftx"
|
"github.com/c9s/bbgo/pkg/exchange/ftx"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func cobraInitRequired(required []string) func(cmd *cobra.Command, args []string) error {
|
||||||
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
|
for _, key := range required {
|
||||||
|
if err := cmd.MarkFlagRequired(key); err != nil {
|
||||||
|
log.WithError(err).Errorf("cannot mark --%s option required", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func inQuoteAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value {
|
func inQuoteAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value {
|
||||||
quote := balances[market.QuoteCurrency]
|
quote := balances[market.QuoteCurrency]
|
||||||
base := balances[market.BaseCurrency]
|
base := balances[market.BaseCurrency]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user