mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
add okex to the exchange factory
This commit is contained in:
parent
29ad95a639
commit
2381df5009
|
@ -196,7 +196,7 @@ func (environ *Environment) ConfigureExchangeSessions(userConfig *Config) error
|
|||
}
|
||||
|
||||
func (environ *Environment) AddExchangesByViperKeys() error {
|
||||
for _, n := range SupportedExchanges {
|
||||
for _, n := range types.SupportedExchanges {
|
||||
if viper.IsSet(string(n) + "-api-key") {
|
||||
exchange, err := cmdutil.NewExchangeWithEnvVarPrefix(n, "")
|
||||
if err != nil {
|
||||
|
@ -224,7 +224,7 @@ func InitExchangeSession(name string, session *ExchangeSession) error {
|
|||
}
|
||||
}
|
||||
|
||||
exchange, err = cmdutil.NewExchangeStandard(exchangeName, session.Key, session.Secret, session.SubAccount)
|
||||
exchange, err = cmdutil.NewExchangeStandard(exchangeName, session.Key, session.Secret, "", session.SubAccount)
|
||||
} else {
|
||||
exchange, err = cmdutil.NewExchangeWithEnvVarPrefix(exchangeName, session.EnvVarPrefix)
|
||||
}
|
||||
|
|
|
@ -9,13 +9,9 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
var SupportedExchanges = []types.ExchangeName{"binance", "max", "ftx"}
|
||||
|
||||
// SingleExchangeStrategy represents the single Exchange strategy
|
||||
type SingleExchangeStrategy interface {
|
||||
ID() string
|
||||
|
|
|
@ -8,10 +8,11 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/exchange/binance"
|
||||
"github.com/c9s/bbgo/pkg/exchange/ftx"
|
||||
"github.com/c9s/bbgo/pkg/exchange/max"
|
||||
"github.com/c9s/bbgo/pkg/exchange/okex"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func NewExchangeStandard(n types.ExchangeName, key, secret, subAccount string) (types.Exchange, error) {
|
||||
func NewExchangeStandard(n types.ExchangeName, key, secret, passphrase, subAccount string) (types.Exchange, error) {
|
||||
switch n {
|
||||
|
||||
case types.ExchangeFTX:
|
||||
|
@ -23,8 +24,8 @@ func NewExchangeStandard(n types.ExchangeName, key, secret, subAccount string) (
|
|||
case types.ExchangeMax:
|
||||
return max.New(key, secret), nil
|
||||
|
||||
// case types.ExchangeOKEx:
|
||||
// return okex.New(key, secret, ""), nil
|
||||
case types.ExchangeOKEx:
|
||||
return okex.New(key, secret, passphrase), nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported exchange: %v", n)
|
||||
|
@ -45,8 +46,9 @@ func NewExchangeWithEnvVarPrefix(n types.ExchangeName, varPrefix string) (types.
|
|||
return nil, fmt.Errorf("can not initialize exchange %s: empty key or secret, env var prefix: %s", n, varPrefix)
|
||||
}
|
||||
|
||||
passphrase := os.Getenv(varPrefix + "_API_PASSPHRASE")
|
||||
subAccount := os.Getenv(varPrefix + "_SUBACCOUNT")
|
||||
return NewExchangeStandard(n, key, secret, subAccount)
|
||||
return NewExchangeStandard(n, key, secret, passphrase, subAccount)
|
||||
}
|
||||
|
||||
// NewExchange constructor exchange object from viper config.
|
||||
|
|
|
@ -160,3 +160,11 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
|
|||
func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (e *Exchange) NewStream() types.Stream {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ const (
|
|||
ExchangeBacktest = ExchangeName("backtest")
|
||||
)
|
||||
|
||||
var SupportedExchanges = []ExchangeName{"binance", "max", "ftx", "okex"}
|
||||
|
||||
func ValidExchangeName(a string) (ExchangeName, error) {
|
||||
switch strings.ToLower(a) {
|
||||
case "max":
|
||||
|
|
Loading…
Reference in New Issue
Block a user