2020-10-12 14:46:06 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2020-10-21 09:10:47 +00:00
|
|
|
// NewExchange constructor exchange object from viper config.
|
2020-10-12 14:46:06 +00:00
|
|
|
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 {
|
2020-10-15 14:36:22 +00:00
|
|
|
return nil, errors.New("binance: empty key or secret")
|
2020-10-12 14:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-10-15 14:36:22 +00:00
|
|
|
return nil, errors.New("max: empty key or secret")
|
2020-10-12 14:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return max.New(key, secret), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|