Skip to content

Commit

Permalink
fix: okx breaking URL change (backport #244) (#252)
Browse files Browse the repository at this point in the history
* fix: okx breaking URL change (#244)

fix okx provider

(cherry picked from commit adbec7a)

# Conflicts:
#	tests/integration/provider_test.go

* resolve conflicts & config incompatibility

---------

Co-authored-by: Kyle <[email protected]>
Co-authored-by: Adam Wozniak <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent 407460c commit 8508b1c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
9 changes: 5 additions & 4 deletions oracle/provider/okx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion oracle/provider/websocket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"net/url"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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,
Expand Down
59 changes: 32 additions & 27 deletions tests/integration/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
)
}
}
}

0 comments on commit 8508b1c

Please sign in to comment.