Skip to content

Commit

Permalink
fix: gateio test and symbol handling
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Feb 24, 2024
1 parent 379319d commit 4646886
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 7 additions & 8 deletions feeder/priceprovider/sources/gateio.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"net/http"
"strconv"
"strings"

"github.com/NibiruChain/nibiru/x/common/set"
"github.com/NibiruChain/pricefeeder/types"
Expand Down Expand Up @@ -40,17 +39,17 @@ func GateIoPriceUpdate(symbols set.Set[types.Symbol]) (rawPrices map[types.Symbo

rawPrices = make(map[types.Symbol]float64)
for _, ticker := range tickers {
pair := ticker["currency_pair"].(string)
symbol := types.Symbol(strings.Replace(pair, "_", "", -1))
symbol := types.Symbol(ticker["currency_pair"].(string))
if !symbols.Has(symbol) {
continue
}

lastPrice, err := strconv.ParseFloat(ticker["last"].(string), 64)
price, err := strconv.ParseFloat(ticker["last"].(string), 64)
if err != nil {
return rawPrices, err
}
if _, ok := symbols[symbol]; ok {
rawPrices[symbol] = lastPrice
price = -1
}

rawPrices[symbol] = price
}

return rawPrices, nil
Expand Down
7 changes: 3 additions & 4 deletions feeder/priceprovider/sources/gateio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (

func TestGateIoSource(t *testing.T) {
t.Run("success", func(t *testing.T) {
rawPrices, err := GateIoPriceUpdate(set.New[types.Symbol]("BTCUSD", "ETHUSD"))
rawPrices, err := GateIoPriceUpdate(set.New[types.Symbol]("BTC_USDT", "ETH_USDT"))
require.NoError(t, err)
require.Equal(t, 2, len(rawPrices))
require.NotZero(t, rawPrices["BTCUSD"])
require.NotZero(t, rawPrices["ETHUSD"])
require.NotZero(t, rawPrices["BTC_USDT"])
require.NotZero(t, rawPrices["ETH_USDT"])
})

}

0 comments on commit 4646886

Please sign in to comment.