From 8508b1cfde49629056fc68dfee2cf3fd46522cf0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 30 Aug 2023 10:00:23 -0700 Subject: [PATCH] fix: okx breaking URL change (backport #244) (#252) * fix: okx breaking URL change (#244) fix okx provider (cherry picked from commit adbec7af13cde09cd38692cab6f413b3d4877a6b) # Conflicts: # tests/integration/provider_test.go * resolve conflicts & config incompatibility --------- Co-authored-by: Kyle Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> --- oracle/provider/okx.go | 9 ++-- oracle/provider/websocket_controller.go | 10 ++++- tests/integration/provider_test.go | 59 ++++++++++++++----------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/oracle/provider/okx.go b/oracle/provider/okx.go index 04d9ca41..2ce26fd6 100644 --- a/oracle/provider/okx.go +++ b/oracle/provider/okx.go @@ -16,10 +16,11 @@ import ( ) const ( - okxWSHost = "ws.okx.com:8443" - okxWSPath = "/ws/v5/public" - okxRestHost = "https://www.okx.com" - okxRestPath = "/api/v5/market/tickers?instType=SPOT" + okxWSHost = "ws.okx.com:8443" + okxWSPath = "/ws/v5/public" + okxWSPathBusiness = "/ws/v5/business" + okxRestHost = "https://www.okx.com" + okxRestPath = "/api/v5/market/tickers?instType=SPOT" ) var _ Provider = (*OkxProvider)(nil) diff --git a/oracle/provider/websocket_controller.go b/oracle/provider/websocket_controller.go index 3be27c31..91bce4ea 100644 --- a/oracle/provider/websocket_controller.go +++ b/oracle/provider/websocket_controller.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "net/url" + "strings" "sync" "time" @@ -66,10 +67,17 @@ func NewWebsocketController( connections := make([]*WebsocketConnection, 0) for _, subMsg := range subscriptionMsgs { + wsURL := websocketURL + + // Use a different URL for okx candle subscriptions + if providerName == ProviderOkx && strings.Contains(fmt.Sprintf("%v", subMsg), "candle") { + wsURL = url.URL{Scheme: "wss", Host: okxWSHost, Path: okxWSPathBusiness} + } + connection := &WebsocketConnection{ parentCtx: ctx, providerName: providerName, - websocketURL: websocketURL, + websocketURL: wsURL, subscriptionMsg: subMsg, messageHandler: messageHandler, pingDuration: pingDuration, diff --git a/tests/integration/provider_test.go b/tests/integration/provider_test.go index a9be1f40..2a37b05b 100644 --- a/tests/integration/provider_test.go +++ b/tests/integration/provider_test.go @@ -12,6 +12,7 @@ import ( "github.com/ojo-network/price-feeder/oracle/provider" "github.com/ojo-network/price-feeder/oracle/types" "github.com/rs/zerolog" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -96,32 +97,36 @@ func checkForPrices(t *testing.T, pvd provider.Provider, currencyPairs []types.C for _, cp := range currencyPairs { currencyPairKey := cp.String() - require.False(t, - tickerPrices[cp].Price.IsNil(), - "no ticker price for %s pair %s", - providerName, - currencyPairKey, - ) - - require.True(t, - tickerPrices[cp].Price.GT(sdk.NewDec(0)), - "ticker price is zero for %s pair %s", - providerName, - currencyPairKey, - ) - - require.NotEmpty(t, - candlePrices[cp], - "no candle prices for %s pair %s", - providerName, - currencyPairKey, - ) - - require.True(t, - candlePrices[cp][0].Price.GT(sdk.NewDec(0)), - "candle price is zero for %s pair %s", - providerName, - currencyPairKey, - ) + if tickerPrices[cp].Price.IsNil() { + assert.Failf(t, + "no ticker price", + "provider %s pair %s", + providerName, + currencyPairKey, + ) + } else { + assert.True(t, + tickerPrices[cp].Price.GT(sdk.NewDec(0)), + "ticker price is zero for %s pair %s", + providerName, + currencyPairKey, + ) + } + + if len(candlePrices[cp]) == 0 { + assert.Failf(t, + "no candle prices", + "provider %s pair %s", + providerName, + currencyPairKey, + ) + } else { + assert.True(t, + candlePrices[cp][0].Price.GT(sdk.NewDec(0)), + "candle price is zero for %s pair %s", + providerName, + currencyPairKey, + ) + } } }