bbgo_origin/pkg/cmd/exchangetest.go

64 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-05-17 06:26:25 +00:00
//go:build exchangetest
// +build exchangetest
package cmd
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
2023-05-17 06:26:25 +00:00
"github.com/c9s/bbgo/pkg/exchange"
"github.com/c9s/bbgo/pkg/types"
)
// go run ./cmd/bbgo kline --exchange=binance --symbol=BTCUSDT
var exchangeTestCmd = &cobra.Command{
Use: "exchange-test",
Short: "test the exchange",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
2023-05-17 06:26:25 +00:00
exchangeNameStr, err := cmd.Flags().GetString("exchange")
if err != nil {
return err
}
2023-05-17 06:26:25 +00:00
exchangeName, err := types.ValidExchangeName(exchangeNameStr)
if err != nil {
return err
}
2023-05-17 06:26:25 +00:00
exMinimal, err := exchange.NewWithEnvVarPrefix(exchangeName, "")
if err != nil {
return err
}
2023-05-17 06:26:25 +00:00
log.Infof("types.ExchangeMinimal: ✅")
2023-05-17 06:26:25 +00:00
if service, ok := exMinimal.(types.ExchangeAccountService); ok {
log.Infof("types.ExchangeAccountService: ✅ (%T)", service)
}
2023-05-17 06:26:25 +00:00
if service, ok := exMinimal.(types.ExchangeMarketDataService); ok {
log.Infof("types.ExchangeMarketDataService: ✅ (%T)", service)
}
2023-05-17 06:26:25 +00:00
if ex, ok := exMinimal.(types.Exchange); ok {
log.Infof("types.Exchange: ✅ (%T)", ex)
}
2023-05-17 06:26:25 +00:00
_ = ctx
// cmdutil.WaitForSignal(ctx, syscall.SIGINT, syscall.SIGTERM)
return nil
},
}
func init() {
2023-05-17 06:26:25 +00:00
exchangeTestCmd.Flags().String("exchange", "", "session name")
exchangeTestCmd.MarkFlagRequired("exchange")
RootCmd.AddCommand(exchangeTestCmd)
}