From 8f04782bd65de3cd672d18f6466637ac61ae815b Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Tue, 15 Oct 2024 14:34:53 -0400 Subject: [PATCH 1/2] add lsk/usd feed --- src/telliot_feeds/feeds/__init__.py | 2 ++ src/telliot_feeds/feeds/lsk_usd_feed.py | 20 ++++++++++++++++ src/telliot_feeds/queries/price/spot_price.py | 1 + src/telliot_feeds/queries/query_catalog.py | 6 +++++ .../sources/price/spot/kraken.py | 1 + .../sources/price/spot/uniswapV3.py | 1 + tests/feeds/test_lsk_usd_feed.py | 23 +++++++++++++++++++ 7 files changed, 54 insertions(+) create mode 100644 src/telliot_feeds/feeds/lsk_usd_feed.py create mode 100644 tests/feeds/test_lsk_usd_feed.py diff --git a/src/telliot_feeds/feeds/__init__.py b/src/telliot_feeds/feeds/__init__.py index 32675727..3fa6751a 100644 --- a/src/telliot_feeds/feeds/__init__.py +++ b/src/telliot_feeds/feeds/__init__.py @@ -57,6 +57,7 @@ from telliot_feeds.feeds.landx_feed import wheat from telliot_feeds.feeds.leth_usd_feed import leth_usd_feed from telliot_feeds.feeds.link_usd_feed import link_usd_median_feed +from telliot_feeds.feeds.lsk_usd_feed import lsk_usd_median_feed from telliot_feeds.feeds.ltc_usd_feed import ltc_usd_median_feed from telliot_feeds.feeds.matic_usd_feed import matic_usd_median_feed from telliot_feeds.feeds.meth_usd_feed import meth_usd_median_feed @@ -232,6 +233,7 @@ "pufeth-usd-spot": pufeth_usd_median_feed, "stone-usd-spot": stone_usd_median_feed, "superoethb-eth-spot": superoethb_eth_median_feed, + "lsk-usd-spot": lsk_usd_median_feed, } DATAFEED_BUILDER_MAPPING: Dict[str, DataFeed[Any]] = { diff --git a/src/telliot_feeds/feeds/lsk_usd_feed.py b/src/telliot_feeds/feeds/lsk_usd_feed.py new file mode 100644 index 00000000..89414a8c --- /dev/null +++ b/src/telliot_feeds/feeds/lsk_usd_feed.py @@ -0,0 +1,20 @@ +from telliot_feeds.datafeed import DataFeed +from telliot_feeds.queries.price.spot_price import SpotPrice +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource +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 + +lsk_usd_median_feed = DataFeed( + query=SpotPrice(asset="LSK", currency="USD"), + source=PriceAggregator( + asset="lsk", + currency="usd", + algorithm="median", + sources=[ + OKXSpotPriceSource(asset="lsk", currency="usdt"), + KrakenSpotPriceSource(asset="lsk", currency="usd"), + UniswapV3PriceSource(asset="lsk", currency="usd") + ], + ), +) diff --git a/src/telliot_feeds/queries/price/spot_price.py b/src/telliot_feeds/queries/price/spot_price.py index 4a19065a..b33be4c0 100644 --- a/src/telliot_feeds/queries/price/spot_price.py +++ b/src/telliot_feeds/queries/price/spot_price.py @@ -100,6 +100,7 @@ "PUFETH/USD", "STONE/USD", "SUPEROETHB/ETH", + "LSK/USD", ] diff --git a/src/telliot_feeds/queries/query_catalog.py b/src/telliot_feeds/queries/query_catalog.py index 9928b200..a9d4bbe8 100644 --- a/src/telliot_feeds/queries/query_catalog.py +++ b/src/telliot_feeds/queries/query_catalog.py @@ -662,3 +662,9 @@ title="superOETHb/ETH spot price", q=SpotPrice(asset="superoethb", currency="eth"), ) + +query_catalog.add_entry( + tag="lsk-usd-spot", + title="LSK/USD spot price", + q=SpotPrice(asset="lsk", currency="usd"), +) diff --git a/src/telliot_feeds/sources/price/spot/kraken.py b/src/telliot_feeds/sources/price/spot/kraken.py index 1bc7d8da..3574a90d 100644 --- a/src/telliot_feeds/sources/price/spot/kraken.py +++ b/src/telliot_feeds/sources/price/spot/kraken.py @@ -32,6 +32,7 @@ "FIL", "LINK", "PYTH", + "LSK", } KRAKEN_CURRENCIES = {"USD"} diff --git a/src/telliot_feeds/sources/price/spot/uniswapV3.py b/src/telliot_feeds/sources/price/spot/uniswapV3.py index 476dfa85..9ee16a27 100644 --- a/src/telliot_feeds/sources/price/spot/uniswapV3.py +++ b/src/telliot_feeds/sources/price/spot/uniswapV3.py @@ -36,6 +36,7 @@ "pufeth": "0xd9a442856c234a39a81a089c06451ebaa4306a72", "eul": "0xd9fcd98c322942075a5c3860693e9f4f03aae07b", "rai": "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919", + "lsk": "0x6033f7f88332b8db6ad452b7c6d5bb643990ae3f", } API_KEY = TelliotConfig().api_keys.find(name="thegraph")[0].key diff --git a/tests/feeds/test_lsk_usd_feed.py b/tests/feeds/test_lsk_usd_feed.py new file mode 100644 index 00000000..9e333e58 --- /dev/null +++ b/tests/feeds/test_lsk_usd_feed.py @@ -0,0 +1,23 @@ +import statistics + +import pytest + +from telliot_feeds.feeds.lsk_usd_feed import lsk_usd_median_feed + + +@pytest.mark.asyncio +async def test_lsk_usd_median_feed(caplog): + """Retrieve median lsk/usd price.""" + v, _ = await lsk_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"lsk/usd Price: {v}") + + # Get list of data sources from sources dict + source_prices = [source.latest[0] for source in lsk_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 22efba76d00daf85b42d85c35824829dd441160b Mon Sep 17 00:00:00 2001 From: 0xSpuddy Date: Tue, 15 Oct 2024 14:42:36 -0400 Subject: [PATCH 2/2] tox --- src/telliot_feeds/feeds/lsk_usd_feed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/telliot_feeds/feeds/lsk_usd_feed.py b/src/telliot_feeds/feeds/lsk_usd_feed.py index 89414a8c..4964b9d9 100644 --- a/src/telliot_feeds/feeds/lsk_usd_feed.py +++ b/src/telliot_feeds/feeds/lsk_usd_feed.py @@ -1,7 +1,7 @@ from telliot_feeds.datafeed import DataFeed from telliot_feeds.queries.price.spot_price import SpotPrice -from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource +from telliot_feeds.sources.price.spot.okx import OKXSpotPriceSource from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource from telliot_feeds.sources.price_aggregator import PriceAggregator @@ -14,7 +14,7 @@ sources=[ OKXSpotPriceSource(asset="lsk", currency="usdt"), KrakenSpotPriceSource(asset="lsk", currency="usd"), - UniswapV3PriceSource(asset="lsk", currency="usd") + UniswapV3PriceSource(asset="lsk", currency="usd"), ], ), )