Skip to content

Commit

Permalink
add lsk/usd feed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSpuddy committed Oct 15, 2024
1 parent 65f694e commit 8f04782
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/telliot_feeds/feeds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]] = {
Expand Down
20 changes: 20 additions & 0 deletions src/telliot_feeds/feeds/lsk_usd_feed.py
Original file line number Diff line number Diff line change
@@ -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")
],
),
)
1 change: 1 addition & 0 deletions src/telliot_feeds/queries/price/spot_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"PUFETH/USD",
"STONE/USD",
"SUPEROETHB/ETH",
"LSK/USD",
]


Expand Down
6 changes: 6 additions & 0 deletions src/telliot_feeds/queries/query_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
1 change: 1 addition & 0 deletions src/telliot_feeds/sources/price/spot/kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"FIL",
"LINK",
"PYTH",
"LSK",
}
KRAKEN_CURRENCIES = {"USD"}

Expand Down
1 change: 1 addition & 0 deletions src/telliot_feeds/sources/price/spot/uniswapV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"pufeth": "0xd9a442856c234a39a81a089c06451ebaa4306a72",
"eul": "0xd9fcd98c322942075a5c3860693e9f4f03aae07b",
"rai": "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919",
"lsk": "0x6033f7f88332b8db6ad452b7c6d5bb643990ae3f",
}

API_KEY = TelliotConfig().api_keys.find(name="thegraph")[0].key
Expand Down
23 changes: 23 additions & 0 deletions tests/feeds/test_lsk_usd_feed.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f04782

Please sign in to comment.