-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IND-515] add fixed price exchange for e2e testing purposes (#852)
- Loading branch information
Showing
8 changed files
with
132 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...emons/pricefeed/client/price_function/test_fixed_price_exchange/exchange_query_details.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
) |
56 changes: 56 additions & 0 deletions
56
...daemons/pricefeed/client/price_function/test_fixed_price_exchange/fixed_price_function.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters