From eddcaecc925d43d57325343f5bf1387112adb362 Mon Sep 17 00:00:00 2001 From: lychiyu Date: Thu, 12 Sep 2024 23:27:22 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E6=96=B0=E5=A2=9E=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E4=BA=A4=E6=98=93=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/bbgo/session.go | 3 ++- pkg/exchange/factory.go | 9 +++++---- pkg/exchange/okex/exchange.go | 10 +++++----- pkg/exchange/okex/okexapi/client.go | 12 ++++++++++++ pkg/exchange/okex/query_kline_test.go | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 16518a0..3e4935d 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -43,6 +43,7 @@ type ExchangeSession struct { Secret string `json:"secret,omitempty" yaml:"secret,omitempty"` Passphrase string `json:"passphrase,omitempty" yaml:"passphrase,omitempty"` Proxy string `json:"proxy,omitempty" yaml:"proxy,omitempty"` + Simulated string `json:"simulated,omitempty" yaml:"simulated,omitempty"` SubAccount string `json:"subAccount,omitempty" yaml:"subAccount,omitempty"` // Withdrawal is used for enabling withdrawal functions @@ -796,7 +797,7 @@ func (session *ExchangeSession) newBasicPrivateExchange(exchangeName types.Excha var err error var exMinimal types.ExchangeMinimal if session.Key != "" && session.Secret != "" { - exMinimal, err = exchange2.New(exchangeName, session.Key, session.Secret, session.Passphrase, session.Proxy) + exMinimal, err = exchange2.New(exchangeName, session.Key, session.Secret, session.Passphrase, session.Proxy, session.Simulated) } else { exMinimal, err = exchange2.NewWithEnvVarPrefix(exchangeName, session.EnvVarPrefix) } diff --git a/pkg/exchange/factory.go b/pkg/exchange/factory.go index 6332166..9816a6d 100644 --- a/pkg/exchange/factory.go +++ b/pkg/exchange/factory.go @@ -15,7 +15,7 @@ import ( ) func NewPublic(exchangeName types.ExchangeName) (types.Exchange, error) { - exMinimal, err := New(exchangeName, "", "", "", "") + exMinimal, err := New(exchangeName, "", "", "", "", "0") if err != nil { return nil, err } @@ -27,7 +27,7 @@ func NewPublic(exchangeName types.ExchangeName) (types.Exchange, error) { return nil, fmt.Errorf("exchange %T does not implement types.Exchange", exMinimal) } -func New(n types.ExchangeName, key, secret, passphrase, proxy string) (types.ExchangeMinimal, error) { +func New(n types.ExchangeName, key, secret, passphrase, proxy, simulated string) (types.ExchangeMinimal, error) { switch n { case types.ExchangeBinance: @@ -37,7 +37,7 @@ func New(n types.ExchangeName, key, secret, passphrase, proxy string) (types.Exc return max.New(key, secret), nil case types.ExchangeOKEx: - return okex.New(key, secret, passphrase), nil + return okex.New(key, secret, passphrase, simulated), nil case types.ExchangeKucoin: return kucoin.New(key, secret, passphrase), nil @@ -71,5 +71,6 @@ func NewWithEnvVarPrefix(n types.ExchangeName, varPrefix string) (types.Exchange passphrase := os.Getenv(varPrefix + "_API_PASSPHRASE") proxy := os.Getenv(varPrefix + "_PROXY") - return New(n, key, secret, passphrase, proxy) + simulated := os.Getenv(varPrefix + "_SIMULATED") + return New(n, key, secret, passphrase, proxy, simulated) } diff --git a/pkg/exchange/okex/exchange.go b/pkg/exchange/okex/exchange.go index ad93464..1d1066a 100644 --- a/pkg/exchange/okex/exchange.go +++ b/pkg/exchange/okex/exchange.go @@ -65,13 +65,12 @@ var log = logrus.WithFields(logrus.Fields{ var ErrSymbolRequired = errors.New("symbol is a required parameter") type Exchange struct { - key, secret, passphrase string - - client *okexapi.RestClient - timeNowFunc func() time.Time + key, secret, passphrase, simulated string + client *okexapi.RestClient + timeNowFunc func() time.Time } -func New(key, secret, passphrase string) *Exchange { +func New(key, secret, passphrase, simulated string) *Exchange { client := okexapi.NewClient() if len(key) > 0 && len(secret) > 0 { @@ -82,6 +81,7 @@ func New(key, secret, passphrase string) *Exchange { key: key, secret: secret, passphrase: passphrase, + simulated: simulated, client: client, timeNowFunc: time.Now, } diff --git a/pkg/exchange/okex/okexapi/client.go b/pkg/exchange/okex/okexapi/client.go index 8a3d96a..54216cf 100644 --- a/pkg/exchange/okex/okexapi/client.go +++ b/pkg/exchange/okex/okexapi/client.go @@ -24,6 +24,18 @@ const PublicWebSocketURL = "wss://wsaws.okx.com:8443/ws/v5/public" const PrivateWebSocketURL = "wss://wsaws.okx.com:8443/ws/v5/private" const PublicBusinessWebSocketURL = "wss://wsaws.okx.com:8443/ws/v5/business" +/* +模拟交易 +REST:https://www.okx.com +WebSocket公共频道:wss://wspap.okx.com:8443/ws/v5/public +WebSocket私有频道:wss://wspap.okx.com:8443/ws/v5/private +WebSocket业务频道:wss://wspap.okx.com:8443/ws/v5/business +*/ +const SimulatedRestBaseURL = "https://www.okx.com/" +const SimulatedPublicWebSocketURL = "wss://wspap.okx.com:8443/ws/v5/public" +const SimulatedPrivateWebSocketURL = "wss://wspap.okx.com:8443/ws/v5/private" +const SimulatedPublicBusinessWebSocketURL = "wss://wspap.okx.com:8443/ws/v5/business" + type SideType string const ( diff --git a/pkg/exchange/okex/query_kline_test.go b/pkg/exchange/okex/query_kline_test.go index 6b87eeb..523e543 100644 --- a/pkg/exchange/okex/query_kline_test.go +++ b/pkg/exchange/okex/query_kline_test.go @@ -16,7 +16,7 @@ func Test_QueryKlines(t *testing.T) { t.Skip("Please configure all credentials about OKEX") } - e := New(key, secret, passphrase) + e := New(key, secret, passphrase, "0") queryOrder := types.OrderQuery{ Symbol: "BTC-USDT",