diff --git a/protocol/daemons/pricefeed/client/constants/exchange_common/exchange_id.go b/protocol/daemons/pricefeed/client/constants/exchange_common/exchange_id.go index 1769a190c3..f763988493 100644 --- a/protocol/daemons/pricefeed/client/constants/exchange_common/exchange_id.go +++ b/protocol/daemons/pricefeed/client/constants/exchange_common/exchange_id.go @@ -35,4 +35,6 @@ const ( EXCHANGE_ID_TEST_EXCHANGE types.ExchangeId = "TestExchange" // EXCHANGE_ID_TEST_VOLATILE_EXCHANGE is the id for test volatile exchange. EXCHANGE_ID_TEST_VOLATILE_EXCHANGE types.ExchangeId = "TestVolatileExchange" + // EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE is the id for test fixed price exchange. + EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE types.ExchangeId = "TestFixedPriceExchange" ) diff --git a/protocol/daemons/pricefeed/client/constants/static_exchange_details.go b/protocol/daemons/pricefeed/client/constants/static_exchange_details.go index 0581117e2d..a5ea5860fd 100644 --- a/protocol/daemons/pricefeed/client/constants/static_exchange_details.go +++ b/protocol/daemons/pricefeed/client/constants/static_exchange_details.go @@ -14,6 +14,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function/kucoin" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function/mexc" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function/okx" + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function/test_volatile_exchange" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function/testexchange" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/types" @@ -22,20 +23,21 @@ import ( var ( // StaticExchangeDetails is the static mapping of `ExchangeId` to its `ExchangeQueryDetails`. StaticExchangeDetails = map[types.ExchangeId]types.ExchangeQueryDetails{ - exchange_common.EXCHANGE_ID_BINANCE: binance.BinanceDetails, - exchange_common.EXCHANGE_ID_BINANCE_US: binance.BinanceUSDetails, - exchange_common.EXCHANGE_ID_BITFINEX: bitfinex.BitfinexDetails, - exchange_common.EXCHANGE_ID_KRAKEN: kraken.KrakenDetails, - exchange_common.EXCHANGE_ID_GATE: gate.GateDetails, - exchange_common.EXCHANGE_ID_BITSTAMP: bitstamp.BitstampDetails, - exchange_common.EXCHANGE_ID_BYBIT: bybit.BybitDetails, - exchange_common.EXCHANGE_ID_CRYPTO_COM: crypto_com.CryptoComDetails, - exchange_common.EXCHANGE_ID_HUOBI: huobi.HuobiDetails, - exchange_common.EXCHANGE_ID_KUCOIN: kucoin.KucoinDetails, - exchange_common.EXCHANGE_ID_OKX: okx.OkxDetails, - exchange_common.EXCHANGE_ID_MEXC: mexc.MexcDetails, - exchange_common.EXCHANGE_ID_COINBASE_PRO: coinbase_pro.CoinbaseProDetails, - exchange_common.EXCHANGE_ID_TEST_EXCHANGE: testexchange.TestExchangeDetails, - exchange_common.EXCHANGE_ID_TEST_VOLATILE_EXCHANGE: test_volatile_exchange.TestVolatileExchangeDetails, + exchange_common.EXCHANGE_ID_BINANCE: binance.BinanceDetails, + exchange_common.EXCHANGE_ID_BINANCE_US: binance.BinanceUSDetails, + exchange_common.EXCHANGE_ID_BITFINEX: bitfinex.BitfinexDetails, + exchange_common.EXCHANGE_ID_KRAKEN: kraken.KrakenDetails, + exchange_common.EXCHANGE_ID_GATE: gate.GateDetails, + exchange_common.EXCHANGE_ID_BITSTAMP: bitstamp.BitstampDetails, + exchange_common.EXCHANGE_ID_BYBIT: bybit.BybitDetails, + exchange_common.EXCHANGE_ID_CRYPTO_COM: crypto_com.CryptoComDetails, + exchange_common.EXCHANGE_ID_HUOBI: huobi.HuobiDetails, + exchange_common.EXCHANGE_ID_KUCOIN: kucoin.KucoinDetails, + exchange_common.EXCHANGE_ID_OKX: okx.OkxDetails, + exchange_common.EXCHANGE_ID_MEXC: mexc.MexcDetails, + exchange_common.EXCHANGE_ID_COINBASE_PRO: coinbase_pro.CoinbaseProDetails, + exchange_common.EXCHANGE_ID_TEST_EXCHANGE: testexchange.TestExchangeDetails, + exchange_common.EXCHANGE_ID_TEST_VOLATILE_EXCHANGE: test_volatile_exchange.TestVolatileExchangeDetails, + exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE: test_fixed_price_exchange.TestFixedPriceExchangeDetails, } ) diff --git a/protocol/daemons/pricefeed/client/constants/static_exchange_market_config.go b/protocol/daemons/pricefeed/client/constants/static_exchange_market_config.go index 2d37293218..4378d2786f 100644 --- a/protocol/daemons/pricefeed/client/constants/static_exchange_market_config.go +++ b/protocol/daemons/pricefeed/client/constants/static_exchange_market_config.go @@ -39,6 +39,9 @@ func GenerateExchangeConfigJson( if id == exchange_common.EXCHANGE_ID_TEST_EXCHANGE { continue } + if id == exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE { + continue + } for marketId, config := range exchangeConfig.MarketToMarketConfig { marketExchangeConfigs, ok := marketToExchangeMarketConfigs[marketId] if !ok { diff --git a/protocol/daemons/pricefeed/client/constants/static_exchange_query_config.go b/protocol/daemons/pricefeed/client/constants/static_exchange_query_config.go index cf1a89747e..0bee6b63ba 100644 --- a/protocol/daemons/pricefeed/client/constants/static_exchange_query_config.go +++ b/protocol/daemons/pricefeed/client/constants/static_exchange_query_config.go @@ -127,5 +127,11 @@ var ( TimeoutMs: defaultTimeoutMs, MaxQueries: defaultMaxQueries, }, + exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE: { + ExchangeId: exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE, + IntervalMs: defaultIntervalMs, + TimeoutMs: defaultTimeoutMs, + MaxQueries: defaultMaxQueries, + }, } ) diff --git a/protocol/daemons/pricefeed/client/constants/static_exchange_query_config_test.go b/protocol/daemons/pricefeed/client/constants/static_exchange_query_config_test.go index 55011e5b60..81d6bac95a 100644 --- a/protocol/daemons/pricefeed/client/constants/static_exchange_query_config_test.go +++ b/protocol/daemons/pricefeed/client/constants/static_exchange_query_config_test.go @@ -164,5 +164,5 @@ func TestStaticExchangeQueryConfigCache(t *testing.T) { } func TestStaticExchangeQueryConfigCacheLength(t *testing.T) { - require.Len(t, constants.StaticExchangeQueryConfig, 14) + require.Len(t, constants.StaticExchangeQueryConfig, 15) } diff --git a/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange/exchange_query_details.go b/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange/exchange_query_details.go new file mode 100644 index 0000000000..7ec5f6ef65 --- /dev/null +++ b/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange/exchange_query_details.go @@ -0,0 +1,33 @@ +package test_fixed_price_exchange + +import ( + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/constants/exchange_common" + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/types" +) + +// Fixed prices for BTC-USD, ETH-USD, SOL-USD +const ( + BTC_USD_PRICE = 50000 + ETH_USD_PRICE = 4000 + SOL_USD_PRICE = 100 +) + +type FixedPriceExchangeParams struct { + BTCUSDPrice float64 + ETHUSDPrice float64 + SOLUSDPrice float64 +} + +var ( + TestFixedPriceExchangeParams = FixedPriceExchangeParams{ + BTCUSDPrice: BTC_USD_PRICE, + ETHUSDPrice: ETH_USD_PRICE, + SOLUSDPrice: SOL_USD_PRICE, + } + TestFixedPriceExchangeDetails = types.ExchangeQueryDetails{ + Exchange: exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE, + Url: "https://jsonplaceholder.typicode.com/users", + PriceFunction: FixedExchangePriceFunction, + IsMultiMarket: false, + } +) diff --git a/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange/fixed_price_function.go b/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange/fixed_price_function.go new file mode 100644 index 0000000000..f92c27e58d --- /dev/null +++ b/protocol/daemons/pricefeed/client/price_function/test_fixed_price_exchange/fixed_price_function.go @@ -0,0 +1,56 @@ +package test_fixed_price_exchange + +import ( + "fmt" + "net/http" + + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/price_function" + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/types" +) + +type FixedPriceTicker struct { + Pair string + Price string +} + +var _ price_function.Ticker = (*FixedPriceTicker)(nil) + +func (t FixedPriceTicker) GetPair() string { + return t.Pair +} + +func (t FixedPriceTicker) GetAskPrice() string { + return t.Price +} + +func (t FixedPriceTicker) GetBidPrice() string { + return t.Price +} + +func (t FixedPriceTicker) GetLastPrice() string { + return t.Price +} + +func FixedExchangePriceFunction( + response *http.Response, + tickerToExponent map[string]int32, + resolver types.Resolver, +) (tickerToPrice map[string]uint64, unavailableTickers map[string]error, err error) { + btcTicker := FixedPriceTicker{ + Pair: "BTC-USD", + Price: fmt.Sprintf("%f", TestFixedPriceExchangeParams.BTCUSDPrice), + } + ethTicker := FixedPriceTicker{ + Pair: "ETH-USD", + Price: fmt.Sprintf("%f", TestFixedPriceExchangeParams.ETHUSDPrice), + } + solTicker := FixedPriceTicker{ + Pair: "SOL-USD", + Price: fmt.Sprintf("%f", TestFixedPriceExchangeParams.SOLUSDPrice), + } + return price_function.GetMedianPricesFromTickers( + []FixedPriceTicker{btcTicker, ethTicker, solTicker}, + tickerToExponent, + resolver, + ) +} diff --git a/protocol/testutil/daemons/pricefeed/exchange_config/testnet_exchange_market_config.go b/protocol/testutil/daemons/pricefeed/exchange_config/testnet_exchange_market_config.go index 12ce2e83bc..99f167a954 100644 --- a/protocol/testutil/daemons/pricefeed/exchange_config/testnet_exchange_market_config.go +++ b/protocol/testutil/daemons/pricefeed/exchange_config/testnet_exchange_market_config.go @@ -1077,6 +1077,20 @@ var ( }, }, }, + exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE: { + Id: exchange_common.EXCHANGE_ID_TEST_FIXED_PRICE_EXCHANGE, + MarketToMarketConfig: map[types.MarketId]types.MarketConfig{ + MARKET_BTC_USD: { + Ticker: "BTC-USD", + }, + MARKET_ETH_USD: { + Ticker: "ETH-USD", + }, + MARKET_SOL_USD: { + Ticker: "SOL-USD", + }, + }, + }, } )