2023-05-17 06:26:25 +00:00
|
|
|
//go:build exchangetest
|
|
|
|
// +build exchangetest
|
|
|
|
|
2023-05-16 10:15:27 +00:00
|
|
|
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"
|
2023-05-16 10:15:27 +00:00
|
|
|
"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")
|
2023-05-16 10:15:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
exchangeName, err := types.ValidExchangeName(exchangeNameStr)
|
2023-05-16 10:15:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
exMinimal, err := exchange.NewWithEnvVarPrefix(exchangeName, "")
|
2023-05-16 10:15:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
log.Infof("types.ExchangeMinimal: ✅")
|
2023-05-16 10:15:27 +00:00
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
if service, ok := exMinimal.(types.ExchangeAccountService); ok {
|
|
|
|
log.Infof("types.ExchangeAccountService: ✅ (%T)", service)
|
|
|
|
}
|
2023-05-16 10:15:27 +00:00
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
if service, ok := exMinimal.(types.ExchangeMarketDataService); ok {
|
|
|
|
log.Infof("types.ExchangeMarketDataService: ✅ (%T)", service)
|
2023-05-16 10:15:27 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
if ex, ok := exMinimal.(types.Exchange); ok {
|
|
|
|
log.Infof("types.Exchange: ✅ (%T)", ex)
|
|
|
|
}
|
2023-05-16 10:15:27 +00:00
|
|
|
|
2023-05-17 06:26:25 +00:00
|
|
|
_ = ctx
|
|
|
|
// cmdutil.WaitForSignal(ctx, syscall.SIGINT, syscall.SIGTERM)
|
2023-05-16 10:15:27 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2023-05-17 06:26:25 +00:00
|
|
|
exchangeTestCmd.Flags().String("exchange", "", "session name")
|
|
|
|
exchangeTestCmd.MarkFlagRequired("exchange")
|
|
|
|
|
2023-05-16 10:15:27 +00:00
|
|
|
RootCmd.AddCommand(exchangeTestCmd)
|
|
|
|
}
|