bbgo_origin/cmd/cmdutil/exchange.go

37 lines
799 B
Go
Raw Normal View History

package cmdutil
import (
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/exchange/binance"
"github.com/c9s/bbgo/pkg/exchange/max"
"github.com/c9s/bbgo/pkg/types"
)
func NewExchange(n types.ExchangeName) (types.Exchange, error) {
switch n {
case types.ExchangeBinance:
key := viper.GetString("binance-api-key")
secret := viper.GetString("binance-api-secret")
if len(key) == 0 || len(secret) == 0 {
return nil, errors.New("empty key or secret")
}
return binance.New(key, secret), nil
case types.ExchangeMax:
key := viper.GetString("max-api-key")
secret := viper.GetString("max-api-secret")
if len(key) == 0 || len(secret) == 0 {
return nil, errors.New("empty key or secret")
}
return max.New(key, secret), nil
}
return nil, nil
}