From f4a14d5e083a3da231f56c1778fff3c8d81bbd03 Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Wed, 25 Sep 2024 12:35:13 -0400 Subject: [PATCH 1/8] crypto.com working --- .../sources/price/spot/cryptodotcom.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/telliot_feeds/sources/price/spot/cryptodotcom.py diff --git a/src/telliot_feeds/sources/price/spot/cryptodotcom.py b/src/telliot_feeds/sources/price/spot/cryptodotcom.py new file mode 100644 index 00000000..a26d3c2f --- /dev/null +++ b/src/telliot_feeds/sources/price/spot/cryptodotcom.py @@ -0,0 +1,69 @@ +from dataclasses import dataclass +from dataclasses import field +from typing import Any + +from telliot_feeds.dtypes.datapoint import datetime_now_utc +from telliot_feeds.dtypes.datapoint import OptionalDataPoint +from telliot_feeds.pricing.price_service import WebPriceService +from telliot_feeds.pricing.price_source import PriceSource +from telliot_feeds.utils.log import get_logger + + +logger = get_logger(__name__) + + +class CryptodotcomSpotPriceService(WebPriceService): + """Crypto.com Price Service""" + + def __init__(self, **kwargs: Any) -> None: + kwargs["name"] = "Crypto.com Price Service" + kwargs["url"] = "https://api.crypto.com" + super().__init__(**kwargs) + + async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]: + """Implement PriceServiceInterface + + This implementation gets the price from the Cryto.com api. + e.g. request https://api.crypto.com/v2/public/get-ticker?instrument_name=TRB_USDT + https://github.com/IgorJakovljevic/crypto-exchange?tab=readme-ov-file#endpoint + """ + + market_symbol = f"{format(asset.upper())}_{format(currency.upper())}" + request_url = f"/v2/public/get-ticker?instrument_name={market_symbol}" + + d = self.get_url(request_url) + + if "error" in d: + logger.error(d) + return None, None + + elif "response" in d: + response = d["response"] + + if "message" in response: + logger.error(f"API ERROR ({self.name}): {response['message']}") + return None, None + + else: + raise Exception("Invalid response from get_url") + + price = float(response['result']['data'][0]['a']) + return price, datetime_now_utc() + + +@dataclass +class cryptodotcomSpotPriceSource(PriceSource): + asset: str = "" + currency: str = "" + service: CryptodotcomSpotPriceService = field(default_factory=CryptodotcomSpotPriceService, init=False) + + +if __name__ == "__main__": + import asyncio + + async def main() -> None: + source = cryptodotcomSpotPriceSource(asset="eth", currency="usd") + v, _ = await source.fetch_new_datapoint() + print(v) + + asyncio.run(main()) From d747f864fc4edfdab62d79c70452b181135157eb Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Wed, 25 Sep 2024 13:36:30 -0400 Subject: [PATCH 2/8] okx source and test --- src/telliot_feeds/feeds/trb_usd_feed.py | 4 ++ .../sources/price/spot/cryptodotcom.py | 4 +- src/telliot_feeds/sources/price/spot/okx.py | 69 +++++++++++++++++++ tests/feeds/test_trb_usd_feed.py | 3 +- tests/feeds/test_usdt_usd_feed.py | 4 +- 5 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 src/telliot_feeds/sources/price/spot/okx.py diff --git a/src/telliot_feeds/feeds/trb_usd_feed.py b/src/telliot_feeds/feeds/trb_usd_feed.py index 25771fb3..d53a4433 100644 --- a/src/telliot_feeds/feeds/trb_usd_feed.py +++ b/src/telliot_feeds/feeds/trb_usd_feed.py @@ -1,8 +1,10 @@ """Datafeed for current price of TRB in USD.""" from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice +from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource +from telliot_feeds.sources.price.spot.cryptodotcom import CryptodotcomSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator trb_usd_median_feed = DataFeed( @@ -12,8 +14,10 @@ currency="usd", algorithm="median", sources=[ + BinanceSpotPriceSource(asset="trb", currency="usd"), CoinGeckoSpotPriceSource(asset="trb", currency="usd"), CoinpaprikaSpotPriceSource(asset="trb-tellor", currency="usd"), + CryptodotcomSpotPriceSource(asset="trb", currency="usd"), ], ), ) diff --git a/src/telliot_feeds/sources/price/spot/cryptodotcom.py b/src/telliot_feeds/sources/price/spot/cryptodotcom.py index a26d3c2f..580d3b2b 100644 --- a/src/telliot_feeds/sources/price/spot/cryptodotcom.py +++ b/src/telliot_feeds/sources/price/spot/cryptodotcom.py @@ -52,7 +52,7 @@ async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float] @dataclass -class cryptodotcomSpotPriceSource(PriceSource): +class CryptodotcomSpotPriceSource(PriceSource): asset: str = "" currency: str = "" service: CryptodotcomSpotPriceService = field(default_factory=CryptodotcomSpotPriceService, init=False) @@ -62,7 +62,7 @@ class cryptodotcomSpotPriceSource(PriceSource): import asyncio async def main() -> None: - source = cryptodotcomSpotPriceSource(asset="eth", currency="usd") + source = CryptodotcomSpotPriceSource(asset="eth", currency="usd") v, _ = await source.fetch_new_datapoint() print(v) diff --git a/src/telliot_feeds/sources/price/spot/okx.py b/src/telliot_feeds/sources/price/spot/okx.py new file mode 100644 index 00000000..14c4813b --- /dev/null +++ b/src/telliot_feeds/sources/price/spot/okx.py @@ -0,0 +1,69 @@ +from dataclasses import dataclass +from dataclasses import field +from typing import Any + +from telliot_feeds.dtypes.datapoint import datetime_now_utc +from telliot_feeds.dtypes.datapoint import OptionalDataPoint +from telliot_feeds.pricing.price_service import WebPriceService +from telliot_feeds.pricing.price_source import PriceSource +from telliot_feeds.utils.log import get_logger + + +logger = get_logger(__name__) + + +class OKXSpotPriceService(WebPriceService): + """OKX Price Service""" + + def __init__(self, **kwargs: Any) -> None: + kwargs["name"] = "OKX Price Service" + kwargs["url"] = "https://www.okx.com/api" + super().__init__(**kwargs) + + async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]: + """Implement PriceServiceInterface + + This implementation gets the price from the Cryto.com api. + e.g. request https://www.okx.com/api/v5/market/ticker?instId=TRB-USDT + """ + + market_symbol = f"{format(asset.upper())}-{format(currency.upper())}" + request_url = f"/v5/market/ticker?instId={market_symbol}" + + d = self.get_url(request_url) + logger.info(f"d={d}") + + if "error" in d: + logger.error(d) + return None, None + + elif "response" in d: + response = d["response"] + + if "message" in response: + logger.error(f"API ERROR ({self.name}): {response['message']}") + return None, None + + else: + raise Exception("Invalid response from get_url") + + price = float(response['data'][0]['last']) + return price, datetime_now_utc() + + +@dataclass +class OKXSpotPriceSource(PriceSource): + asset: str = "" + currency: str = "" + service: OKXSpotPriceService = field(default_factory=OKXSpotPriceService, init=False) + + +if __name__ == "__main__": + import asyncio + + async def main() -> None: + source = OKXSpotPriceSource(asset="trb", currency="usdt") + v, _ = await source.fetch_new_datapoint() + print(v) + + asyncio.run(main()) diff --git a/tests/feeds/test_trb_usd_feed.py b/tests/feeds/test_trb_usd_feed.py index 9b96a58f..08f1107e 100644 --- a/tests/feeds/test_trb_usd_feed.py +++ b/tests/feeds/test_trb_usd_feed.py @@ -6,12 +6,13 @@ @pytest.mark.asyncio -async def test_trb_asset_price_feed(): +async def test_trb_asset_price_feed(caplog): """Retrieve median TRB/USD price.""" v, _ = await trb_usd_median_feed.source.fetch_new_datapoint() assert v is not None assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() print(f"TRB/USD Price: {v}") # Get list of data sources from sources dict diff --git a/tests/feeds/test_usdt_usd_feed.py b/tests/feeds/test_usdt_usd_feed.py index 6cad26b4..f8036f02 100644 --- a/tests/feeds/test_usdt_usd_feed.py +++ b/tests/feeds/test_usdt_usd_feed.py @@ -14,9 +14,9 @@ async def test_usdt_usd_median_feed(caplog): assert v > 0 assert "sources used in aggregate: 4" in caplog.text.lower() print(f"usdt/usd Price: {v}") - + source_prices = trb_usd_median_feed.source.latest[0] # Get list of data sources from sources dict - source_prices = [source.latest[0] for source in usdt_usd_median_feed.source.sources if source.latest[0]] + # source_prices = [source.latest[0] for source in usdt_usd_median_feed.source.sources if source.latest[0]] # Make sure error is less than decimal tolerance assert (v - statistics.median(source_prices)) < 10**-6 From 987c99aa894059d55baec2090b372126f7e83bd2 Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Wed, 25 Sep 2024 14:20:06 -0400 Subject: [PATCH 3/8] improved sources --- src/telliot_feeds/feeds/badger_usd_feed.py | 5 ++++ src/telliot_feeds/feeds/bch_usd_feed.py | 5 ++++ src/telliot_feeds/feeds/btc_usd_feed.py | 7 ++++-- src/telliot_feeds/feeds/comp_usd_feed.py | 2 ++ src/telliot_feeds/feeds/crv_usd_feed.py | 2 ++ src/telliot_feeds/feeds/trb_usd_feed.py | 7 ++++-- .../sources/price/spot/coingecko.py | 2 +- .../sources/price/spot/cryptodotcom.py | 2 +- .../sources/price/spot/kraken.py | 2 +- src/telliot_feeds/sources/price/spot/okx.py | 5 ++-- tests/feeds/test_aave_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_avax_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_badger_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_bch_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_btc_usd_feed.py | 1 - tests/feeds/test_comp_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_crv_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_trb_usd_feed.py | 2 +- tests/feeds/test_usdt_usd_feed.py | 2 +- 19 files changed, 169 insertions(+), 13 deletions(-) create mode 100644 tests/feeds/test_aave_usd_feed.py create mode 100644 tests/feeds/test_avax_usd_feed.py create mode 100644 tests/feeds/test_badger_usd_feed.py create mode 100644 tests/feeds/test_bch_usd_feed.py create mode 100644 tests/feeds/test_comp_usd_feed.py create mode 100644 tests/feeds/test_crv_usd_feed.py diff --git a/src/telliot_feeds/feeds/badger_usd_feed.py b/src/telliot_feeds/feeds/badger_usd_feed.py index 6fa66648..bd09021a 100644 --- a/src/telliot_feeds/feeds/badger_usd_feed.py +++ b/src/telliot_feeds/feeds/badger_usd_feed.py @@ -2,8 +2,11 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + badger_usd_median_feed = DataFeed( query=SpotPrice(asset="BADGER", currency="USD"), source=PriceAggregator( @@ -11,8 +14,10 @@ currency="usd", algorithm="median", sources=[ + # BinanceSpotPriceSource(asset="badger", currency="usd"), CoinGeckoSpotPriceSource(asset="badger", currency="usd"), KrakenSpotPriceSource(asset="badger", currency="usd"), + OKXSpotPriceSource(asset="badger", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/bch_usd_feed.py b/src/telliot_feeds/feeds/bch_usd_feed.py index d7b32515..3df4d8d2 100644 --- a/src/telliot_feeds/feeds/bch_usd_feed.py +++ b/src/telliot_feeds/feeds/bch_usd_feed.py @@ -2,8 +2,11 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + bch_usd_median_feed = DataFeed( query=SpotPrice(asset="BCH", currency="USD"), source=PriceAggregator( @@ -11,8 +14,10 @@ currency="usd", algorithm="median", sources=[ + # BinanceSpotPriceSource(asset="bch", currency="usd"), CoinGeckoSpotPriceSource(asset="bch", currency="usd"), KrakenSpotPriceSource(asset="bch", currency="usd"), + OKXSpotPriceSource(asset="bch", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/btc_usd_feed.py b/src/telliot_feeds/feeds/btc_usd_feed.py index 47d19198..1ab2cde1 100644 --- a/src/telliot_feeds/feeds/btc_usd_feed.py +++ b/src/telliot_feeds/feeds/btc_usd_feed.py @@ -1,11 +1,13 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + btc_usd_median_feed = DataFeed( query=SpotPrice(asset="BTC", currency="USD"), source=PriceAggregator( @@ -13,10 +15,11 @@ currency="usd", algorithm="median", sources=[ + # BinanceSpotPriceSource(asset="bch", currency="usdt"), CoinGeckoSpotPriceSource(asset="btc", currency="usd"), - BinanceSpotPriceSource(asset="btc", currency="usdt"), GeminiSpotPriceSource(asset="btc", currency="usd"), KrakenSpotPriceSource(asset="xbt", currency="usd"), + OKXSpotPriceSource(asset="btc", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/comp_usd_feed.py b/src/telliot_feeds/feeds/comp_usd_feed.py index 8c1c7d14..041950ee 100644 --- a/src/telliot_feeds/feeds/comp_usd_feed.py +++ b/src/telliot_feeds/feeds/comp_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator comp_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="comp", currency="usd"), GeminiSpotPriceSource(asset="comp", currency="usd"), + OKXSpotPriceSource(asset="comp", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/crv_usd_feed.py b/src/telliot_feeds/feeds/crv_usd_feed.py index 6b1c98ae..f405f0e5 100644 --- a/src/telliot_feeds/feeds/crv_usd_feed.py +++ b/src/telliot_feeds/feeds/crv_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator crv_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="crv", currency="usd"), KrakenSpotPriceSource(asset="crv", currency="usd"), + OKXSpotPriceSource(asset="crv", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/trb_usd_feed.py b/src/telliot_feeds/feeds/trb_usd_feed.py index d53a4433..469bf164 100644 --- a/src/telliot_feeds/feeds/trb_usd_feed.py +++ b/src/telliot_feeds/feeds/trb_usd_feed.py @@ -1,12 +1,14 @@ """Datafeed for current price of TRB in USD.""" from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource from telliot_feeds.sources.price.spot.cryptodotcom import CryptodotcomSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + trb_usd_median_feed = DataFeed( query=SpotPrice(asset="trb", currency="usd"), source=PriceAggregator( @@ -14,10 +16,11 @@ currency="usd", algorithm="median", sources=[ - BinanceSpotPriceSource(asset="trb", currency="usd"), + # BinanceSpotPriceSource(asset="trb", currency="usd"), CoinGeckoSpotPriceSource(asset="trb", currency="usd"), CoinpaprikaSpotPriceSource(asset="trb-tellor", currency="usd"), CryptodotcomSpotPriceSource(asset="trb", currency="usd"), + OKXSpotPriceSource(asset="trb", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/sources/price/spot/coingecko.py b/src/telliot_feeds/sources/price/spot/coingecko.py index bc316670..ce18d067 100644 --- a/src/telliot_feeds/sources/price/spot/coingecko.py +++ b/src/telliot_feeds/sources/price/spot/coingecko.py @@ -38,7 +38,7 @@ "albt": "allianceblock", "rai": "rai", "xdai": "xdai", - "avax": "avalanche", + "avax": "avalanche-2", "aave": "aave", "badger": "badger-dao", "bch": "bitcoin-cash", diff --git a/src/telliot_feeds/sources/price/spot/cryptodotcom.py b/src/telliot_feeds/sources/price/spot/cryptodotcom.py index 580d3b2b..23f6df08 100644 --- a/src/telliot_feeds/sources/price/spot/cryptodotcom.py +++ b/src/telliot_feeds/sources/price/spot/cryptodotcom.py @@ -47,7 +47,7 @@ async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float] else: raise Exception("Invalid response from get_url") - price = float(response['result']['data'][0]['a']) + price = float(response["result"]["data"][0]["a"]) return price, datetime_now_utc() diff --git a/src/telliot_feeds/sources/price/spot/kraken.py b/src/telliot_feeds/sources/price/spot/kraken.py index 333b6933..1e8e4b21 100644 --- a/src/telliot_feeds/sources/price/spot/kraken.py +++ b/src/telliot_feeds/sources/price/spot/kraken.py @@ -15,7 +15,7 @@ # Hardcoded supported assets & currencies # Search for supported assets here: https://api.kraken.com/0/public/Assets -KRAKEN_ASSETS = {"ETH", "MATIC", "MKR", "SUSHI", "USDC", "XBT", "WBTC"} +KRAKEN_ASSETS = {"ETH", "MATIC", "MKR", "SUSHI", "USDC", "XBT", "WBTC", "BADGER", "AVAX", "AAVE", "BCH", "CRV"} KRAKEN_CURRENCIES = {"USD"} diff --git a/src/telliot_feeds/sources/price/spot/okx.py b/src/telliot_feeds/sources/price/spot/okx.py index 14c4813b..7f382ec2 100644 --- a/src/telliot_feeds/sources/price/spot/okx.py +++ b/src/telliot_feeds/sources/price/spot/okx.py @@ -23,7 +23,7 @@ def __init__(self, **kwargs: Any) -> None: async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]: """Implement PriceServiceInterface - This implementation gets the price from the Cryto.com api. + This implementation gets the price from the OKX api. e.g. request https://www.okx.com/api/v5/market/ticker?instId=TRB-USDT """ @@ -31,7 +31,6 @@ async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float] request_url = f"/v5/market/ticker?instId={market_symbol}" d = self.get_url(request_url) - logger.info(f"d={d}") if "error" in d: logger.error(d) @@ -47,7 +46,7 @@ async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float] else: raise Exception("Invalid response from get_url") - price = float(response['data'][0]['last']) + price = float(response["data"][0]["last"]) return price, datetime_now_utc() diff --git a/tests/feeds/test_aave_usd_feed.py b/tests/feeds/test_aave_usd_feed.py new file mode 100644 index 00000000..19aa7385 --- /dev/null +++ b/tests/feeds/test_aave_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.aave_usd_feed import aave_usd_median_feed + + +@pytest.mark.asyncio +async def test_aave_usd_median_feed(caplog): + """Retrieve median aave/USD price.""" + v, _ = await aave_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"aave/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in aave_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_avax_usd_feed.py b/tests/feeds/test_avax_usd_feed.py new file mode 100644 index 00000000..65db0e93 --- /dev/null +++ b/tests/feeds/test_avax_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.avax_usd_feed import avax_usd_median_feed + + +@pytest.mark.asyncio +async def test_avax_usd_median_feed(caplog): + """Retrieve median avax/USD price.""" + v, _ = await avax_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"avax/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in avax_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_badger_usd_feed.py b/tests/feeds/test_badger_usd_feed.py new file mode 100644 index 00000000..1e82730f --- /dev/null +++ b/tests/feeds/test_badger_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.badger_usd_feed import badger_usd_median_feed + + +@pytest.mark.asyncio +async def test_badger_usd_median_feed(): + """Retrieve median badger/USD price.""" + v, _ = await badger_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"badger/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in badger_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_bch_usd_feed.py b/tests/feeds/test_bch_usd_feed.py new file mode 100644 index 00000000..279b2b0d --- /dev/null +++ b/tests/feeds/test_bch_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.bch_usd_feed import bch_usd_median_feed + + +@pytest.mark.asyncio +async def test_bch_usd_median_feed(caplog): + """Retrieve median bch/USD price.""" + v, _ = await bch_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"bch/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in bch_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_btc_usd_feed.py b/tests/feeds/test_btc_usd_feed.py index 656ff0b4..c0b25056 100644 --- a/tests/feeds/test_btc_usd_feed.py +++ b/tests/feeds/test_btc_usd_feed.py @@ -6,7 +6,6 @@ from telliot_feeds.queries.query import OracleQuery -@pytest.mark.skip("Skip while gemini rate limiting") @pytest.mark.asyncio async def test_AssetPriceFeed(): """Retrieve median BTC price from example datafeed & diff --git a/tests/feeds/test_comp_usd_feed.py b/tests/feeds/test_comp_usd_feed.py new file mode 100644 index 00000000..ce672753 --- /dev/null +++ b/tests/feeds/test_comp_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.comp_usd_feed import comp_usd_median_feed + + +@pytest.mark.asyncio +async def test_comp_usd_median_feed(caplog): + """Retrieve median comp/USD price.""" + v, _ = await comp_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"comp/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in comp_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_crv_usd_feed.py b/tests/feeds/test_crv_usd_feed.py new file mode 100644 index 00000000..047fa20f --- /dev/null +++ b/tests/feeds/test_crv_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.crv_usd_feed import crv_usd_median_feed + + +@pytest.mark.asyncio +async def test_crv_usd_median_feed(caplog): + """Retrieve median crv/USD price.""" + v, _ = await crv_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"crv/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in crv_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_trb_usd_feed.py b/tests/feeds/test_trb_usd_feed.py index 08f1107e..eb360cc0 100644 --- a/tests/feeds/test_trb_usd_feed.py +++ b/tests/feeds/test_trb_usd_feed.py @@ -12,7 +12,7 @@ async def test_trb_asset_price_feed(caplog): assert v is not None assert v > 0 - assert "sources used in aggregate: 3" in caplog.text.lower() + assert "sources used in aggregate: 4" in caplog.text.lower() print(f"TRB/USD Price: {v}") # Get list of data sources from sources dict diff --git a/tests/feeds/test_usdt_usd_feed.py b/tests/feeds/test_usdt_usd_feed.py index f8036f02..36402208 100644 --- a/tests/feeds/test_usdt_usd_feed.py +++ b/tests/feeds/test_usdt_usd_feed.py @@ -14,7 +14,7 @@ async def test_usdt_usd_median_feed(caplog): assert v > 0 assert "sources used in aggregate: 4" in caplog.text.lower() print(f"usdt/usd Price: {v}") - source_prices = trb_usd_median_feed.source.latest[0] + source_prices = usdt_usd_median_feed.source.latest[0] # Get list of data sources from sources dict # source_prices = [source.latest[0] for source in usdt_usd_median_feed.source.sources if source.latest[0]] From c56e26e7c8f1ea49393c51e79b1517f7d631ce47 Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Wed, 25 Sep 2024 14:42:15 -0400 Subject: [PATCH 4/8] improved tests and sources --- src/telliot_feeds/feeds/comp_usd_feed.py | 3 +++ src/telliot_feeds/feeds/crv_usd_feed.py | 3 +++ src/telliot_feeds/feeds/dai_usd_feed.py | 5 ++-- src/telliot_feeds/feeds/doge_usd_feed.py | 2 ++ src/telliot_feeds/feeds/dot_usd_feed.py | 2 ++ src/telliot_feeds/feeds/eth_btc_feed.py | 6 ++++- src/telliot_feeds/feeds/eth_usd_feed.py | 5 ++++ src/telliot_feeds/feeds/eul_usd_feed.py | 4 ++-- src/telliot_feeds/feeds/fil_usd_feed.py | 2 ++ .../sources/price/spot/kraken.py | 2 +- .../sources/price/spot/uniswapV3.py | 1 + tests/feeds/test_badger_usd_feed.py | 2 +- tests/feeds/test_brl_usd_feed.py | 3 ++- tests/feeds/test_doge_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_dot_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_eth_usd_feed.py | 2 +- tests/feeds/test_eul_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_fil_usd_feed.py | 23 +++++++++++++++++++ 18 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 tests/feeds/test_doge_usd_feed.py create mode 100644 tests/feeds/test_dot_usd_feed.py create mode 100644 tests/feeds/test_eul_usd_feed.py create mode 100644 tests/feeds/test_fil_usd_feed.py diff --git a/src/telliot_feeds/feeds/comp_usd_feed.py b/src/telliot_feeds/feeds/comp_usd_feed.py index 041950ee..c3fb7c43 100644 --- a/src/telliot_feeds/feeds/comp_usd_feed.py +++ b/src/telliot_feeds/feeds/comp_usd_feed.py @@ -5,6 +5,8 @@ from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + comp_usd_median_feed = DataFeed( query=SpotPrice(asset="COMP", currency="USD"), source=PriceAggregator( @@ -12,6 +14,7 @@ currency="usd", algorithm="median", sources=[ + # BinanceSpotPriceSource(asset="bch", currency="usd"), CoinGeckoSpotPriceSource(asset="comp", currency="usd"), GeminiSpotPriceSource(asset="comp", currency="usd"), OKXSpotPriceSource(asset="comp", currency="usdt"), diff --git a/src/telliot_feeds/feeds/crv_usd_feed.py b/src/telliot_feeds/feeds/crv_usd_feed.py index f405f0e5..0c8dc7e0 100644 --- a/src/telliot_feeds/feeds/crv_usd_feed.py +++ b/src/telliot_feeds/feeds/crv_usd_feed.py @@ -5,6 +5,8 @@ from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + crv_usd_median_feed = DataFeed( query=SpotPrice(asset="CRV", currency="USD"), source=PriceAggregator( @@ -12,6 +14,7 @@ currency="usd", algorithm="median", sources=[ + # BinanceSpotPriceSource(asset="bch", currency="usd"), CoinGeckoSpotPriceSource(asset="crv", currency="usd"), KrakenSpotPriceSource(asset="crv", currency="usd"), OKXSpotPriceSource(asset="crv", currency="usdt"), diff --git a/src/telliot_feeds/feeds/dai_usd_feed.py b/src/telliot_feeds/feeds/dai_usd_feed.py index de0bd341..c8be9367 100644 --- a/src/telliot_feeds/feeds/dai_usd_feed.py +++ b/src/telliot_feeds/feeds/dai_usd_feed.py @@ -1,11 +1,12 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + dai_usd_median_feed = DataFeed( query=SpotPrice(asset="DAI", currency="USD"), source=PriceAggregator( @@ -14,7 +15,7 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="dai", currency="usd"), - BinanceSpotPriceSource(asset="dai", currency="usdt"), + # BinanceSpotPriceSource(asset="dai", currency="usdt"), GeminiSpotPriceSource(asset="dai", currency="usd"), UniswapV3PriceSource(asset="dai", currency="usd"), ], diff --git a/src/telliot_feeds/feeds/doge_usd_feed.py b/src/telliot_feeds/feeds/doge_usd_feed.py index f257b498..c62f4f18 100644 --- a/src/telliot_feeds/feeds/doge_usd_feed.py +++ b/src/telliot_feeds/feeds/doge_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator doge_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="doge", currency="usd"), GeminiSpotPriceSource(asset="doge", currency="usd"), + OKXSpotPriceSource(asset="doge", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/dot_usd_feed.py b/src/telliot_feeds/feeds/dot_usd_feed.py index 70cd6594..4216caec 100644 --- a/src/telliot_feeds/feeds/dot_usd_feed.py +++ b/src/telliot_feeds/feeds/dot_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator dot_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="dot", currency="usd"), GeminiSpotPriceSource(asset="dot", currency="usd"), + OKXSpotPriceSource(asset="dot", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/eth_btc_feed.py b/src/telliot_feeds/feeds/eth_btc_feed.py index 82f4ab56..3a5383e5 100644 --- a/src/telliot_feeds/feeds/eth_btc_feed.py +++ b/src/telliot_feeds/feeds/eth_btc_feed.py @@ -3,8 +3,11 @@ from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + eth_btc_median_feed = DataFeed( query=SpotPrice(asset="ETH", currency="BTC"), source=PriceAggregator( @@ -13,8 +16,9 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="eth", currency="btc"), - BinanceSpotPriceSource(asset="eth", currency="btc"), + # BinanceSpotPriceSource(asset="eth", currency="btc"), GeminiSpotPriceSource(asset="eth", currency="btc"), + OKXSpotPriceSource(asset="eth", currency="btc"), ], ), ) diff --git a/src/telliot_feeds/feeds/eth_usd_feed.py b/src/telliot_feeds/feeds/eth_usd_feed.py index 6a69161e..3f13d335 100644 --- a/src/telliot_feeds/feeds/eth_usd_feed.py +++ b/src/telliot_feeds/feeds/eth_usd_feed.py @@ -3,8 +3,11 @@ from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + eth_usd_median_feed = DataFeed( query=SpotPrice(asset="ETH", currency="USD"), source=PriceAggregator( @@ -12,9 +15,11 @@ currency="usd", algorithm="median", sources=[ + # BinanceSpotPriceSource(asset="eth", currency="btc"), CoinGeckoSpotPriceSource(asset="eth", currency="usd"), GeminiSpotPriceSource(asset="eth", currency="usd"), KrakenSpotPriceSource(asset="eth", currency="usd"), + OKXSpotPriceSource(asset="eth", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/eul_usd_feed.py b/src/telliot_feeds/feeds/eul_usd_feed.py index 7f2a7b04..17e34105 100644 --- a/src/telliot_feeds/feeds/eul_usd_feed.py +++ b/src/telliot_feeds/feeds/eul_usd_feed.py @@ -1,8 +1,8 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource -from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator eul_usd_median_feed = DataFeed( @@ -13,8 +13,8 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="eul", currency="usd"), - GeminiSpotPriceSource(asset="eul", currency="usd"), KrakenSpotPriceSource(asset="eul", currency="usd"), + UniswapV3PriceSource(asset="eul", currency="usd"), ], ), ) diff --git a/src/telliot_feeds/feeds/fil_usd_feed.py b/src/telliot_feeds/feeds/fil_usd_feed.py index 3c4f4016..464e7493 100644 --- a/src/telliot_feeds/feeds/fil_usd_feed.py +++ b/src/telliot_feeds/feeds/fil_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator fil_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="fil", currency="usd"), KrakenSpotPriceSource(asset="fil", currency="usd"), + OKXSpotPriceSource(asset="fil", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/sources/price/spot/kraken.py b/src/telliot_feeds/sources/price/spot/kraken.py index 1e8e4b21..0ea15c49 100644 --- a/src/telliot_feeds/sources/price/spot/kraken.py +++ b/src/telliot_feeds/sources/price/spot/kraken.py @@ -15,7 +15,7 @@ # Hardcoded supported assets & currencies # Search for supported assets here: https://api.kraken.com/0/public/Assets -KRAKEN_ASSETS = {"ETH", "MATIC", "MKR", "SUSHI", "USDC", "XBT", "WBTC", "BADGER", "AVAX", "AAVE", "BCH", "CRV"} +KRAKEN_ASSETS = {"ETH", "MATIC", "MKR", "SUSHI", "USDC", "XBT", "WBTC", "BADGER", "AVAX", "AAVE", "BCH", "CRV", "EUL", "FIL"} KRAKEN_CURRENCIES = {"USD"} diff --git a/src/telliot_feeds/sources/price/spot/uniswapV3.py b/src/telliot_feeds/sources/price/spot/uniswapV3.py index 7f764c19..a9597f81 100644 --- a/src/telliot_feeds/sources/price/spot/uniswapV3.py +++ b/src/telliot_feeds/sources/price/spot/uniswapV3.py @@ -34,6 +34,7 @@ "wrseth": "0xd2671165570f41bbb3b0097893300b6eb6101e6c", "rseth": "0xa1290d69c65a6fe4df752f95823fae25cb99e5a7", "pufeth": "0xd9a442856c234a39a81a089c06451ebaa4306a72", + "eul": "0xd9fcd98c322942075a5c3860693e9f4f03aae07b", } API_KEY = TelliotConfig().api_keys.find(name="thegraph")[0].key diff --git a/tests/feeds/test_badger_usd_feed.py b/tests/feeds/test_badger_usd_feed.py index 1e82730f..6cc36944 100644 --- a/tests/feeds/test_badger_usd_feed.py +++ b/tests/feeds/test_badger_usd_feed.py @@ -6,7 +6,7 @@ @pytest.mark.asyncio -async def test_badger_usd_median_feed(): +async def test_badger_usd_median_feed(caplog): """Retrieve median badger/USD price.""" v, _ = await badger_usd_median_feed.source.fetch_new_datapoint() diff --git a/tests/feeds/test_brl_usd_feed.py b/tests/feeds/test_brl_usd_feed.py index 1d4b4e66..34fb562c 100644 --- a/tests/feeds/test_brl_usd_feed.py +++ b/tests/feeds/test_brl_usd_feed.py @@ -6,12 +6,13 @@ @pytest.mark.asyncio -async def test_brl_usd_median_feed(): +async def test_brl_usd_median_feed(caplog): """Retrieve median BRL/USD price.""" v, _ = await brl_usd_median_feed.source.fetch_new_datapoint() assert v is not None assert v > 0 + assert "sources used in aggregate: 2" in caplog.text.lower() print(f"BRL/USD Price: {v}") # Get list of data sources from sources dict diff --git a/tests/feeds/test_doge_usd_feed.py b/tests/feeds/test_doge_usd_feed.py new file mode 100644 index 00000000..508c9fcb --- /dev/null +++ b/tests/feeds/test_doge_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.doge_usd_feed import doge_usd_median_feed + + +@pytest.mark.asyncio +async def test_doge_usd_median_feed(caplog): + """Retrieve median doge/USD price.""" + v, _ = await doge_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"doge/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in doge_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_dot_usd_feed.py b/tests/feeds/test_dot_usd_feed.py new file mode 100644 index 00000000..a70e3eb2 --- /dev/null +++ b/tests/feeds/test_dot_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.dot_usd_feed import dot_usd_median_feed + + +@pytest.mark.asyncio +async def test_dot_usd_median_feed(caplog): + """Retrieve median dot/USD price.""" + v, _ = await dot_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"dot/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in dot_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_eth_usd_feed.py b/tests/feeds/test_eth_usd_feed.py index 744177e6..f01cfc9e 100644 --- a/tests/feeds/test_eth_usd_feed.py +++ b/tests/feeds/test_eth_usd_feed.py @@ -13,7 +13,7 @@ async def test_eth_usd_median_feed(caplog): assert v is not None assert v > 0 assert ( - "sources used in aggregate: 3" in caplog.text.lower() or "sources used in aggregate: 5" in caplog.text.lower() + "sources used in aggregate: 4" in caplog.text.lower() or "sources used in aggregate: 5" in caplog.text.lower() ) print(f"ETH/USD Price: {v}") diff --git a/tests/feeds/test_eul_usd_feed.py b/tests/feeds/test_eul_usd_feed.py new file mode 100644 index 00000000..614c8ed2 --- /dev/null +++ b/tests/feeds/test_eul_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.eul_usd_feed import eul_usd_median_feed + + +@pytest.mark.asyncio +async def test_eul_usd_median_feed(caplog): + """Retrieve median eul/USD price.""" + v, _ = await eul_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"eul/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in eul_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_fil_usd_feed.py b/tests/feeds/test_fil_usd_feed.py new file mode 100644 index 00000000..01d707f3 --- /dev/null +++ b/tests/feeds/test_fil_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.fil_usd_feed import fil_usd_median_feed + + +@pytest.mark.asyncio +async def test_fil_usd_median_feed(caplog): + """Retrieve median fil/USD price.""" + v, _ = await fil_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"fil/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in fil_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 From db391125d74f9d0e3a65eb2ef739a8fff45f4028 Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Wed, 25 Sep 2024 15:18:03 -0400 Subject: [PATCH 5/8] source and test improvements --- src/telliot_feeds/feeds/eth_btc_feed.py | 1 - src/telliot_feeds/feeds/grt_usd_feed.py | 2 ++ src/telliot_feeds/feeds/idle_usd_feed.py | 2 -- src/telliot_feeds/feeds/link_usd_feed.py | 2 ++ src/telliot_feeds/feeds/ltc_usd_feed.py | 2 ++ src/telliot_feeds/feeds/matic_usd_feed.py | 5 ++-- src/telliot_feeds/feeds/mkr_usd_feed.py | 5 ++-- src/telliot_feeds/feeds/op_usd_feed.py | 2 ++ src/telliot_feeds/feeds/pyth_usd_feed.py | 2 ++ src/telliot_feeds/feeds/rai_usd_feed.py | 2 ++ src/telliot_feeds/feeds/uni_usd_feed.py | 2 ++ .../sources/price/spot/kraken.py | 19 ++++++++++++++- .../sources/price/spot/uniswapV3.py | 1 + tests/feeds/test_link_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_ltc_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_op_usd_feed.py | 3 ++- tests/feeds/test_pyth_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_rai_usd_feed.py | 23 +++++++++++++++++++ tests/feeds/test_uni_usd_feed.py | 23 +++++++++++++++++++ 19 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 tests/feeds/test_link_usd_feed.py create mode 100644 tests/feeds/test_ltc_usd_feed.py create mode 100644 tests/feeds/test_pyth_usd_feed.py create mode 100644 tests/feeds/test_rai_usd_feed.py create mode 100644 tests/feeds/test_uni_usd_feed.py diff --git a/src/telliot_feeds/feeds/eth_btc_feed.py b/src/telliot_feeds/feeds/eth_btc_feed.py index 3a5383e5..45a9aac1 100644 --- a/src/telliot_feeds/feeds/eth_btc_feed.py +++ b/src/telliot_feeds/feeds/eth_btc_feed.py @@ -1,6 +1,5 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource diff --git a/src/telliot_feeds/feeds/grt_usd_feed.py b/src/telliot_feeds/feeds/grt_usd_feed.py index 23b86668..e256ae89 100644 --- a/src/telliot_feeds/feeds/grt_usd_feed.py +++ b/src/telliot_feeds/feeds/grt_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator grt_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="grt", currency="usd"), GeminiSpotPriceSource(asset="grt", currency="usd"), + OKXSpotPriceSource(asset="grt", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/idle_usd_feed.py b/src/telliot_feeds/feeds/idle_usd_feed.py index 9b5fcdf1..bbb8d724 100644 --- a/src/telliot_feeds/feeds/idle_usd_feed.py +++ b/src/telliot_feeds/feeds/idle_usd_feed.py @@ -1,7 +1,6 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource -from telliot_feeds.sources.price.spot.nomics import NomicsSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator idle_usd_median_feed = DataFeed( @@ -12,7 +11,6 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="idle", currency="usd"), - NomicsSpotPriceSource(asset="idle", currency="usd"), ], ), ) diff --git a/src/telliot_feeds/feeds/link_usd_feed.py b/src/telliot_feeds/feeds/link_usd_feed.py index f80f6452..f54392aa 100644 --- a/src/telliot_feeds/feeds/link_usd_feed.py +++ b/src/telliot_feeds/feeds/link_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator link_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="link", currency="usd"), KrakenSpotPriceSource(asset="link", currency="usd"), + OKXSpotPriceSource(asset="link", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/ltc_usd_feed.py b/src/telliot_feeds/feeds/ltc_usd_feed.py index 6f45d016..76088230 100644 --- a/src/telliot_feeds/feeds/ltc_usd_feed.py +++ b/src/telliot_feeds/feeds/ltc_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator ltc_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="ltc", currency="usd"), GeminiSpotPriceSource(asset="ltc", currency="usd"), + OKXSpotPriceSource(asset="ltc", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/matic_usd_feed.py b/src/telliot_feeds/feeds/matic_usd_feed.py index dbe2bcf9..bb02b718 100644 --- a/src/telliot_feeds/feeds/matic_usd_feed.py +++ b/src/telliot_feeds/feeds/matic_usd_feed.py @@ -1,11 +1,12 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + matic_usd_median_feed = DataFeed( query=SpotPrice(asset="MATIC", currency="USD"), source=PriceAggregator( @@ -14,7 +15,7 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="matic", currency="usd"), - BinanceSpotPriceSource(asset="matic", currency="usdt"), + # BinanceSpotPriceSource(asset="matic", currency="usdt"), GeminiSpotPriceSource(asset="matic", currency="usd"), KrakenSpotPriceSource(asset="matic", currency="usd"), ], diff --git a/src/telliot_feeds/feeds/mkr_usd_feed.py b/src/telliot_feeds/feeds/mkr_usd_feed.py index b72566ff..786f8cc5 100644 --- a/src/telliot_feeds/feeds/mkr_usd_feed.py +++ b/src/telliot_feeds/feeds/mkr_usd_feed.py @@ -1,11 +1,12 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + mkr_usd_median_feed = DataFeed( query=SpotPrice(asset="MKR", currency="USD"), source=PriceAggregator( @@ -14,7 +15,7 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="mkr", currency="usd"), - BinanceSpotPriceSource(asset="mkr", currency="usdt"), + # BinanceSpotPriceSource(asset="mkr", currency="usdt"), GeminiSpotPriceSource(asset="mkr", currency="usd"), KrakenSpotPriceSource(asset="mkr", currency="usd"), ], diff --git a/src/telliot_feeds/feeds/op_usd_feed.py b/src/telliot_feeds/feeds/op_usd_feed.py index c2934f5b..76dc76e5 100644 --- a/src/telliot_feeds/feeds/op_usd_feed.py +++ b/src/telliot_feeds/feeds/op_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator op_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="op", currency="usd"), CoinpaprikaSpotPriceSource(asset="op-optimism", currency="usd"), + OKXSpotPriceSource(asset="op", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/pyth_usd_feed.py b/src/telliot_feeds/feeds/pyth_usd_feed.py index 8cc60873..9c362706 100644 --- a/src/telliot_feeds/feeds/pyth_usd_feed.py +++ b/src/telliot_feeds/feeds/pyth_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator pyth_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="pyth", currency="usd"), KrakenSpotPriceSource(asset="pyth", currency="usd"), + OKXSpotPriceSource(asset="pyth", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/rai_usd_feed.py b/src/telliot_feeds/feeds/rai_usd_feed.py index 0f900dda..fe0b6bcf 100644 --- a/src/telliot_feeds/feeds/rai_usd_feed.py +++ b/src/telliot_feeds/feeds/rai_usd_feed.py @@ -4,6 +4,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource +from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator @@ -16,6 +17,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="rai", currency="usd"), CoinpaprikaSpotPriceSource(asset="rai-rai-reflex-index", currency="usd"), + UniswapV3PriceSource(asset="rai", currency="usd"), ], ), ) diff --git a/src/telliot_feeds/feeds/uni_usd_feed.py b/src/telliot_feeds/feeds/uni_usd_feed.py index 352826e1..03ef1d54 100644 --- a/src/telliot_feeds/feeds/uni_usd_feed.py +++ b/src/telliot_feeds/feeds/uni_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator uni_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="uni", currency="usd"), GeminiSpotPriceSource(asset="uni", currency="usd"), + OKXSpotPriceSource(asset="uni", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/sources/price/spot/kraken.py b/src/telliot_feeds/sources/price/spot/kraken.py index 0ea15c49..1bc7d8da 100644 --- a/src/telliot_feeds/sources/price/spot/kraken.py +++ b/src/telliot_feeds/sources/price/spot/kraken.py @@ -15,7 +15,24 @@ # Hardcoded supported assets & currencies # Search for supported assets here: https://api.kraken.com/0/public/Assets -KRAKEN_ASSETS = {"ETH", "MATIC", "MKR", "SUSHI", "USDC", "XBT", "WBTC", "BADGER", "AVAX", "AAVE", "BCH", "CRV", "EUL", "FIL"} +KRAKEN_ASSETS = { + "ETH", + "MATIC", + "MKR", + "SUSHI", + "USDC", + "XBT", + "WBTC", + "BADGER", + "AVAX", + "AAVE", + "BCH", + "CRV", + "EUL", + "FIL", + "LINK", + "PYTH", +} KRAKEN_CURRENCIES = {"USD"} diff --git a/src/telliot_feeds/sources/price/spot/uniswapV3.py b/src/telliot_feeds/sources/price/spot/uniswapV3.py index a9597f81..476dfa85 100644 --- a/src/telliot_feeds/sources/price/spot/uniswapV3.py +++ b/src/telliot_feeds/sources/price/spot/uniswapV3.py @@ -35,6 +35,7 @@ "rseth": "0xa1290d69c65a6fe4df752f95823fae25cb99e5a7", "pufeth": "0xd9a442856c234a39a81a089c06451ebaa4306a72", "eul": "0xd9fcd98c322942075a5c3860693e9f4f03aae07b", + "rai": "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919", } API_KEY = TelliotConfig().api_keys.find(name="thegraph")[0].key diff --git a/tests/feeds/test_link_usd_feed.py b/tests/feeds/test_link_usd_feed.py new file mode 100644 index 00000000..ea175216 --- /dev/null +++ b/tests/feeds/test_link_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.link_usd_feed import link_usd_median_feed + + +@pytest.mark.asyncio +async def test_link_usd_median_feed(caplog): + """Retrieve median link/USD price.""" + v, _ = await link_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"link/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in link_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_ltc_usd_feed.py b/tests/feeds/test_ltc_usd_feed.py new file mode 100644 index 00000000..6a8f082e --- /dev/null +++ b/tests/feeds/test_ltc_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.ltc_usd_feed import ltc_usd_median_feed + + +@pytest.mark.asyncio +async def test_ltc_usd_median_feed(caplog): + """Retrieve median ltc/USD price.""" + v, _ = await ltc_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"ltc/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in ltc_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_op_usd_feed.py b/tests/feeds/test_op_usd_feed.py index 7a6e1832..2888c7c2 100644 --- a/tests/feeds/test_op_usd_feed.py +++ b/tests/feeds/test_op_usd_feed.py @@ -6,12 +6,13 @@ @pytest.mark.asyncio -async def test_op_asset_price_feed(): +async def test_op_asset_price_feed(caplog): """Retrieve median OP/USD price.""" v, _ = await op_usd_median_feed.source.fetch_new_datapoint() assert v is not None assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() print(f"OP/USD Price: {v}") # Get list of data sources from sources dict diff --git a/tests/feeds/test_pyth_usd_feed.py b/tests/feeds/test_pyth_usd_feed.py new file mode 100644 index 00000000..51eec1ba --- /dev/null +++ b/tests/feeds/test_pyth_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.pyth_usd_feed import pyth_usd_median_feed + + +@pytest.mark.asyncio +async def test_pyth_usd_median_feed(caplog): + """Retrieve median pyth/USD price.""" + v, _ = await pyth_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"pyth/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in pyth_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_rai_usd_feed.py b/tests/feeds/test_rai_usd_feed.py new file mode 100644 index 00000000..d6a61419 --- /dev/null +++ b/tests/feeds/test_rai_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.rai_usd_feed import rai_usd_median_feed + + +@pytest.mark.asyncio +async def test_rai_usd_median_feed(caplog): + """Retrieve median rai/USD price.""" + v, _ = await rai_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"rai/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in rai_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 diff --git a/tests/feeds/test_uni_usd_feed.py b/tests/feeds/test_uni_usd_feed.py new file mode 100644 index 00000000..c89b2556 --- /dev/null +++ b/tests/feeds/test_uni_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.uni_usd_feed import uni_usd_median_feed + + +@pytest.mark.asyncio +async def test_uni_usd_median_feed(caplog): + """Retrieve median uni/USD price.""" + v, _ = await uni_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"uni/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in uni_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 From c30f691567abf9038272195902a3e09e64816d05 Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Wed, 25 Sep 2024 15:25:18 -0400 Subject: [PATCH 6/8] shib --- src/telliot_feeds/feeds/ric_usd_feed.py | 2 -- src/telliot_feeds/feeds/shib_usd_feed.py | 2 ++ tests/feeds/test_shib_usd_feed.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/feeds/test_shib_usd_feed.py diff --git a/src/telliot_feeds/feeds/ric_usd_feed.py b/src/telliot_feeds/feeds/ric_usd_feed.py index 3fb448c5..c1028460 100644 --- a/src/telliot_feeds/feeds/ric_usd_feed.py +++ b/src/telliot_feeds/feeds/ric_usd_feed.py @@ -1,7 +1,6 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource -from telliot_feeds.sources.price.spot.nomics import NomicsSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator ric_usd_median_feed = DataFeed( @@ -12,7 +11,6 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="ric", currency="usd"), - NomicsSpotPriceSource(asset="ric", currency="usd"), ], ), ) diff --git a/src/telliot_feeds/feeds/shib_usd_feed.py b/src/telliot_feeds/feeds/shib_usd_feed.py index 4e0269eb..33107590 100644 --- a/src/telliot_feeds/feeds/shib_usd_feed.py +++ b/src/telliot_feeds/feeds/shib_usd_feed.py @@ -2,6 +2,7 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator shib_usd_median_feed = DataFeed( @@ -13,6 +14,7 @@ sources=[ CoinGeckoSpotPriceSource(asset="shib", currency="usd"), GeminiSpotPriceSource(asset="shib", currency="usd"), + OKXSpotPriceSource(asset="shib", currency="usdt"), ], ), ) diff --git a/tests/feeds/test_shib_usd_feed.py b/tests/feeds/test_shib_usd_feed.py new file mode 100644 index 00000000..6d72fd2b --- /dev/null +++ b/tests/feeds/test_shib_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.shib_usd_feed import shib_usd_median_feed + + +@pytest.mark.asyncio +async def test_shib_usd_median_feed(caplog): + """Retrieve median shib/USD price.""" + v, _ = await shib_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + assert "sources used in aggregate: 3" in caplog.text.lower() + print(f"shib/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in shib_usd_median_feed.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6 From 5b7ee2ca8bb928fd357d9f1b790f85521d88a8ac Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Thu, 26 Sep 2024 09:43:23 -0400 Subject: [PATCH 7/8] sources fixes --- src/telliot_feeds/feeds/sushi_usd_feed.py | 5 +++-- src/telliot_feeds/feeds/usdc_usd_feed.py | 4 ++-- src/telliot_feeds/feeds/usdt_usd_feed.py | 4 ++++ tests/feeds/test_usdt_usd_feed.py | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/telliot_feeds/feeds/sushi_usd_feed.py b/src/telliot_feeds/feeds/sushi_usd_feed.py index 75ad34e7..c17062d8 100644 --- a/src/telliot_feeds/feeds/sushi_usd_feed.py +++ b/src/telliot_feeds/feeds/sushi_usd_feed.py @@ -1,11 +1,12 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource + sushi_usd_median_feed = DataFeed( query=SpotPrice(asset="SUSHI", currency="USD"), source=PriceAggregator( @@ -14,7 +15,7 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="sushi", currency="usd"), - BinanceSpotPriceSource(asset="sushi", currency="usdt"), + # BinanceSpotPriceSource(asset="sushi", currency="usdt"), GeminiSpotPriceSource(asset="sushi", currency="usd"), KrakenSpotPriceSource(asset="sushi", currency="usd"), ], diff --git a/src/telliot_feeds/feeds/usdc_usd_feed.py b/src/telliot_feeds/feeds/usdc_usd_feed.py index 7a8711b2..a826be69 100644 --- a/src/telliot_feeds/feeds/usdc_usd_feed.py +++ b/src/telliot_feeds/feeds/usdc_usd_feed.py @@ -1,9 +1,9 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator usdc_usd_median_feed = DataFeed( @@ -14,9 +14,9 @@ algorithm="median", sources=[ CoinGeckoSpotPriceSource(asset="usdc", currency="usd"), - BinanceSpotPriceSource(asset="usdc", currency="usdt"), GeminiSpotPriceSource(asset="usdc", currency="usd"), KrakenSpotPriceSource(asset="usdc", currency="usd"), + OKXSpotPriceSource(asset="usdc", currency="usdt"), ], ), ) diff --git a/src/telliot_feeds/feeds/usdt_usd_feed.py b/src/telliot_feeds/feeds/usdt_usd_feed.py index dcd575e3..c09134b0 100644 --- a/src/telliot_feeds/feeds/usdt_usd_feed.py +++ b/src/telliot_feeds/feeds/usdt_usd_feed.py @@ -2,7 +2,9 @@ from telliot_feeds.queries.price.spot_price import SpotPrice from telliot_feeds.sources.price.spot.agni import agniFinancePriceSource from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource +from telliot_feeds.sources.price.spot.cryptodotcom import CryptodotcomSpotPriceSource from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator usdt_usd_median_feed = DataFeed( @@ -15,6 +17,8 @@ CoinGeckoSpotPriceSource(asset="usdt", currency="usd"), GeminiSpotPriceSource(asset="usdt", currency="usd"), agniFinancePriceSource(asset="usdt", currency="usd"), + OKXSpotPriceSource(asset="usdt", currency="usdc"), + CryptodotcomSpotPriceSource(asset="usdt", currency="usd"), ], ), ) diff --git a/tests/feeds/test_usdt_usd_feed.py b/tests/feeds/test_usdt_usd_feed.py index 36402208..257917f7 100644 --- a/tests/feeds/test_usdt_usd_feed.py +++ b/tests/feeds/test_usdt_usd_feed.py @@ -12,7 +12,7 @@ async def test_usdt_usd_median_feed(caplog): assert v is not None assert v > 0 - assert "sources used in aggregate: 4" in caplog.text.lower() + assert "sources used in aggregate: 5" in caplog.text.lower() print(f"usdt/usd Price: {v}") source_prices = usdt_usd_median_feed.source.latest[0] # Get list of data sources from sources dict From e9fd5ee1a5499bfa7d327bb3e5d8b987ddbb0b46 Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Thu, 26 Sep 2024 10:33:40 -0400 Subject: [PATCH 8/8] fix typos --- src/telliot_feeds/feeds/btc_usd_feed.py | 2 +- src/telliot_feeds/feeds/comp_usd_feed.py | 2 +- src/telliot_feeds/feeds/crv_usd_feed.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/telliot_feeds/feeds/btc_usd_feed.py b/src/telliot_feeds/feeds/btc_usd_feed.py index 1ab2cde1..486427ce 100644 --- a/src/telliot_feeds/feeds/btc_usd_feed.py +++ b/src/telliot_feeds/feeds/btc_usd_feed.py @@ -15,7 +15,7 @@ currency="usd", algorithm="median", sources=[ - # BinanceSpotPriceSource(asset="bch", currency="usdt"), + # BinanceSpotPriceSource(asset="btc", currency="usdt"), CoinGeckoSpotPriceSource(asset="btc", currency="usd"), GeminiSpotPriceSource(asset="btc", currency="usd"), KrakenSpotPriceSource(asset="xbt", currency="usd"), diff --git a/src/telliot_feeds/feeds/comp_usd_feed.py b/src/telliot_feeds/feeds/comp_usd_feed.py index c3fb7c43..636c458e 100644 --- a/src/telliot_feeds/feeds/comp_usd_feed.py +++ b/src/telliot_feeds/feeds/comp_usd_feed.py @@ -14,7 +14,7 @@ currency="usd", algorithm="median", sources=[ - # BinanceSpotPriceSource(asset="bch", currency="usd"), + # BinanceSpotPriceSource(asset="comp", currency="usd"), CoinGeckoSpotPriceSource(asset="comp", currency="usd"), GeminiSpotPriceSource(asset="comp", currency="usd"), OKXSpotPriceSource(asset="comp", currency="usdt"), diff --git a/src/telliot_feeds/feeds/crv_usd_feed.py b/src/telliot_feeds/feeds/crv_usd_feed.py index 0c8dc7e0..7fa96709 100644 --- a/src/telliot_feeds/feeds/crv_usd_feed.py +++ b/src/telliot_feeds/feeds/crv_usd_feed.py @@ -14,7 +14,7 @@ currency="usd", algorithm="median", sources=[ - # BinanceSpotPriceSource(asset="bch", currency="usd"), + # BinanceSpotPriceSource(asset="crv", currency="usd"), CoinGeckoSpotPriceSource(asset="crv", currency="usd"), KrakenSpotPriceSource(asset="crv", currency="usd"), OKXSpotPriceSource(asset="crv", currency="usdt"),