From 7bf648b8140a95214cdd160892ff09337bcd5d1c Mon Sep 17 00:00:00 2001 From: spuddyminer Date: Fri, 25 Aug 2023 13:56:50 -0400 Subject: [PATCH] added diva/usd feed --- src/telliot_feeds/feeds/__init__.py | 2 ++ src/telliot_feeds/feeds/diva_usd_feed.py | 18 +++++++++++++++ src/telliot_feeds/queries/price/spot_price.py | 1 + src/telliot_feeds/queries/query_catalog.py | 6 +++++ .../sources/price/spot/coingecko.py | 1 + tests/feeds/test_diva_usd_feed.py | 22 +++++++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 src/telliot_feeds/feeds/diva_usd_feed.py create mode 100644 tests/feeds/test_diva_usd_feed.py diff --git a/src/telliot_feeds/feeds/__init__.py b/src/telliot_feeds/feeds/__init__.py index f9011ce8..a17fc335 100644 --- a/src/telliot_feeds/feeds/__init__.py +++ b/src/telliot_feeds/feeds/__init__.py @@ -19,6 +19,7 @@ from telliot_feeds.feeds.daily_volatility_manual_feed import daily_volatility_manual_feed from telliot_feeds.feeds.diva_feed import diva_example_feed from telliot_feeds.feeds.diva_feed import diva_manual_feed +from telliot_feeds.feeds.diva_usd_feed import diva_usd_median_feed from telliot_feeds.feeds.doge_usd_feed import doge_usd_median_feed from telliot_feeds.feeds.dot_usd_feed import dot_usd_median_feed from telliot_feeds.feeds.eth_btc_feed import eth_btc_median_feed @@ -158,6 +159,7 @@ "oeth-eth-spot": oeth_eth_median_feed, "wld-usd-spot": wld_usd_median_feed, "sweth-usd-spot": sweth_usd_median_feed, + "diva-usd-spot": diva_usd_median_feed, } DATAFEED_BUILDER_MAPPING: Dict[str, DataFeed[Any]] = { diff --git a/src/telliot_feeds/feeds/diva_usd_feed.py b/src/telliot_feeds/feeds/diva_usd_feed.py new file mode 100644 index 00000000..e6e9e104 --- /dev/null +++ b/src/telliot_feeds/feeds/diva_usd_feed.py @@ -0,0 +1,18 @@ +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_aggregator import PriceAggregator +# from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource + +diva_usd_median_feed = DataFeed( + query=SpotPrice(asset="DIVA", currency="USD"), + source=PriceAggregator( + asset="diva", + currency="usd", + algorithm="median", + sources=[ + CoinGeckoSpotPriceSource(asset="diva", currency="usd"), + # UniswapV3PriceSource(asset="diva", currency="usd"), + ], + ), +) diff --git a/src/telliot_feeds/queries/price/spot_price.py b/src/telliot_feeds/queries/price/spot_price.py index 182938bd..430d75d0 100644 --- a/src/telliot_feeds/queries/price/spot_price.py +++ b/src/telliot_feeds/queries/price/spot_price.py @@ -67,6 +67,7 @@ "OUSD/USD", "OETH/ETH", "WLD/USD", + "DIVA/USD", ] diff --git a/src/telliot_feeds/queries/query_catalog.py b/src/telliot_feeds/queries/query_catalog.py index 59d05764..a274c679 100644 --- a/src/telliot_feeds/queries/query_catalog.py +++ b/src/telliot_feeds/queries/query_catalog.py @@ -441,3 +441,9 @@ title="SWETH/USD spot price", q=SpotPrice(asset="sweth", currency="usd"), ) + +query_catalog.add_entry( + tag="diva-usd-spot", + title="diva/USD spot price", + q=SpotPrice(asset="diva", currency="usd"), +) diff --git a/src/telliot_feeds/sources/price/spot/coingecko.py b/src/telliot_feeds/sources/price/spot/coingecko.py index 6c79d2fd..c6a33c8a 100644 --- a/src/telliot_feeds/sources/price/spot/coingecko.py +++ b/src/telliot_feeds/sources/price/spot/coingecko.py @@ -58,6 +58,7 @@ "ousd": "origin-dollar", "sweth": "sweth", "wld": "worldcoin", + "diva": "diva-protocol", } diff --git a/tests/feeds/test_diva_usd_feed.py b/tests/feeds/test_diva_usd_feed.py new file mode 100644 index 00000000..7e75b414 --- /dev/null +++ b/tests/feeds/test_diva_usd_feed.py @@ -0,0 +1,22 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.diva_usd_feed import diva_usd_median_feed + + +@pytest.mark.asyncio +async def test_diva_usd_median_feed(): + """Retrieve median DIVA/USD price.""" + v, _ = await diva_usd_median_feed.source.fetch_new_datapoint() + + assert v is not None + assert v > 0 + print(f"DIVA/USD Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in diva.source.sources] + print(source_prices) + + # Make sure error is less than decimal tolerance + assert (v - statistics.median(source_prices)) < 10**-6