From 2381df5009347e8f156ec87b93a9388fcd236b02 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 27 May 2021 00:35:51 +0800 Subject: [PATCH] add okex to the exchange factory --- pkg/bbgo/environment.go | 4 ++-- pkg/bbgo/trader.go | 4 ---- pkg/cmd/cmdutil/exchange.go | 10 ++++++---- pkg/exchange/okex/exchange.go | 8 ++++++++ pkg/types/exchange.go | 2 ++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index 1da768466..ca38cb6e1 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -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) } diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index 91240d9fb..94a48fbf5 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -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 diff --git a/pkg/cmd/cmdutil/exchange.go b/pkg/cmd/cmdutil/exchange.go index 3df840c7b..e746047d9 100644 --- a/pkg/cmd/cmdutil/exchange.go +++ b/pkg/cmd/cmdutil/exchange.go @@ -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. diff --git a/pkg/exchange/okex/exchange.go b/pkg/exchange/okex/exchange.go index 42cc79726..564c1d450 100644 --- a/pkg/exchange/okex/exchange.go +++ b/pkg/exchange/okex/exchange.go @@ -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") +} diff --git a/pkg/types/exchange.go b/pkg/types/exchange.go index e23edb46a..7c816639b 100644 --- a/pkg/types/exchange.go +++ b/pkg/types/exchange.go @@ -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":