cmd: use MarkFlagRequired

This commit is contained in:
c9s 2022-03-03 11:36:06 +08:00
parent 2845e03100
commit 21ae48c975
2 changed files with 18 additions and 1 deletions

View File

@ -12,12 +12,17 @@ import (
func init() { func init() {
balancesCmd.Flags().String("session", "", "the exchange session name for querying balances") balancesCmd.Flags().String("session", "", "the exchange session name for querying balances")
if err := balancesCmd.MarkFlagRequired("config") ; err != nil {
log.WithError(err).Errorf("can not mark --config option required")
}
RootCmd.AddCommand(balancesCmd) RootCmd.AddCommand(balancesCmd)
} }
// go run ./cmd/bbgo balances --session=ftx // go run ./cmd/bbgo balances --session=ftx
var balancesCmd = &cobra.Command{ 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,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

View File

@ -381,16 +381,25 @@ var submitOrderCmd = &cobra.Command{
func init() { func init() {
listOrdersCmd.Flags().String("session", "", "the exchange session name for sync") listOrdersCmd.Flags().String("session", "", "the exchange session name for sync")
listOrdersCmd.Flags().String("symbol", "", "the trading pair, like btcusdt") listOrdersCmd.Flags().String("symbol", "", "the trading pair, like btcusdt")
if err := listOrdersCmd.MarkFlagRequired("config") ; err != nil {
log.WithError(err).Errorf("can not mark --config option required")
}
getOrderCmd.Flags().String("session", "", "the exchange session name for sync") getOrderCmd.Flags().String("session", "", "the exchange session name for sync")
getOrderCmd.Flags().String("symbol", "", "the trading pair, like btcusdt") getOrderCmd.Flags().String("symbol", "", "the trading pair, like btcusdt")
getOrderCmd.Flags().String("order-id", "", "order id") getOrderCmd.Flags().String("order-id", "", "order id")
if err := getOrderCmd.MarkFlagRequired("config") ; err != nil {
log.WithError(err).Errorf("can not mark --config option required")
}
submitOrderCmd.Flags().String("session", "", "the exchange session name for sync") submitOrderCmd.Flags().String("session", "", "the exchange session name for sync")
submitOrderCmd.Flags().String("symbol", "", "the trading pair, like btcusdt") submitOrderCmd.Flags().String("symbol", "", "the trading pair, like btcusdt")
submitOrderCmd.Flags().String("side", "", "the trading side: buy or sell") submitOrderCmd.Flags().String("side", "", "the trading side: buy or sell")
submitOrderCmd.Flags().String("price", "", "the trading price") submitOrderCmd.Flags().String("price", "", "the trading price")
submitOrderCmd.Flags().String("quantity", "", "the trading quantity") submitOrderCmd.Flags().String("quantity", "", "the trading quantity")
if err := submitOrderCmd.MarkFlagRequired("config") ; err != nil {
log.WithError(err).Errorf("can not mark --config option required")
}
executeOrderCmd.Flags().String("session", "", "the exchange session name for sync") executeOrderCmd.Flags().String("session", "", "the exchange session name for sync")
executeOrderCmd.Flags().String("symbol", "", "the trading pair, like btcusdt") executeOrderCmd.Flags().String("symbol", "", "the trading pair, like btcusdt")
@ -401,6 +410,9 @@ func init() {
executeOrderCmd.Flags().Duration("update-interval", time.Second*10, "order update time") executeOrderCmd.Flags().Duration("update-interval", time.Second*10, "order update time")
executeOrderCmd.Flags().Duration("deadline", 0, "deadline of the order execution") executeOrderCmd.Flags().Duration("deadline", 0, "deadline of the order execution")
executeOrderCmd.Flags().Int("price-ticks", 0, "the number of price tick for the jump spread, default to 0") executeOrderCmd.Flags().Int("price-ticks", 0, "the number of price tick for the jump spread, default to 0")
if err := executeOrderCmd.MarkFlagRequired("config") ; err != nil {
log.WithError(err).Errorf("can not mark --config option required")
}
RootCmd.AddCommand(listOrdersCmd) RootCmd.AddCommand(listOrdersCmd)
RootCmd.AddCommand(getOrderCmd) RootCmd.AddCommand(getOrderCmd)