From 7b7811bbc304fd683bd998ff2bf57281d76586cc Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 15 Mar 2021 10:23:53 +0800 Subject: [PATCH] revise orderbook command options --- pkg/cmd/orderbook.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/orderbook.go b/pkg/cmd/orderbook.go index ba2a99f52..e0a0fb09d 100644 --- a/pkg/cmd/orderbook.go +++ b/pkg/cmd/orderbook.go @@ -12,26 +12,35 @@ import ( "github.com/c9s/bbgo/pkg/types" ) -// go run ./cmd/bbgo orderbook --session=ftx --symbol=BTC/USDT +// go run ./cmd/bbgo orderbook --exchange=ftx --symbol=BTC/USDT var orderbookCmd = &cobra.Command{ - Use: "orderbook", + Use: "orderbook", + Short: "connect to the order book market data streaming service of an exchange", RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() - session, err := cmd.Flags().GetString("session") + + exName, err := cmd.Flags().GetString("exchange") if err != nil { - return fmt.Errorf("can't get session from flags: %w", err) + return fmt.Errorf("can not get exchange from flags: %w", err) } - ex, err := newExchange(session) + + exchangeName, err := types.ValidExchangeName(exName) + if err != nil { + return err + } + + ex, err := cmdutil.NewExchange(exchangeName) if err != nil { return err } symbol, err := cmd.Flags().GetString("symbol") if err != nil { - return fmt.Errorf("can't get the symbol from flags: %w", err) + return fmt.Errorf("can not get the symbol from flags: %w", err) } + if symbol == "" { - return fmt.Errorf("symbol is not found") + return fmt.Errorf("--symbol option is required") } s := ex.NewStream() @@ -43,8 +52,9 @@ var orderbookCmd = &cobra.Command{ log.Infof("orderbook update: %s", book.String()) }) + log.Infof("connecting...") if err := s.Connect(ctx); err != nil { - return fmt.Errorf("failed to connect to %s", session) + return fmt.Errorf("failed to connect to %s", exchangeName) } cmdutil.WaitForSignal(ctx, syscall.SIGINT, syscall.SIGTERM) @@ -53,8 +63,8 @@ var orderbookCmd = &cobra.Command{ } func init() { - orderbookCmd.Flags().String("session", "", "the exchange session name for sync") - orderbookCmd.Flags().String("symbol", "", "the trading pair, like btcusdt") - + // since the public data does not require trading authentication, we use --exchange option here. + orderbookCmd.Flags().String("exchange", "", "the exchange name for sync") + orderbookCmd.Flags().String("symbol", "", "the trading pair. e.g, BTCUSDT, LTCUSDT...") RootCmd.AddCommand(orderbookCmd) }