Skip to content

Commit

Permalink
superoethb basic feed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSpuddy committed Sep 23, 2024
1 parent cba6aa3 commit 4fc9123
Show file tree
Hide file tree
Showing 6 changed files with 49 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 @@ -97,6 +97,7 @@
from telliot_feeds.feeds.steth_usd_feed import steth_usd_median_feed
from telliot_feeds.feeds.stone_usd_feed import stone_usd_median_feed
from telliot_feeds.feeds.string_query_feed import string_query_feed
from telliot_feeds.feeds.superoethb_eth_feed import superoethb_eth_median_feed
from telliot_feeds.feeds.sushi_usd_feed import sushi_usd_median_feed
from telliot_feeds.feeds.sweth_usd_feed import sweth_usd_median_feed
from telliot_feeds.feeds.tara_usd_feed import tara_usd_median_feed
Expand Down Expand Up @@ -230,6 +231,7 @@
"tara-usd-spot": tara_usd_median_feed,
"pufeth-usd-spot": pufeth_usd_median_feed,
"stone-usd-spot": stone_usd_median_feed,
"superoethb-eth-spot": superoethb_eth_median_feed,
}

DATAFEED_BUILDER_MAPPING: Dict[str, DataFeed[Any]] = {
Expand Down
17 changes: 17 additions & 0 deletions src/telliot_feeds/feeds/superoethb_eth_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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


superoethb_eth_median_feed = DataFeed(
query=SpotPrice(asset="SUPEROETHB", currency="ETH"),
source=PriceAggregator(
asset="superoethb",
currency="eth",
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="superoethb", currency="eth"),
],
),
)
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 @@ -99,6 +99,7 @@
"TARA/USD",
"PUFETH/USD",
"STONE/USD",
"SUPEROETHB/ETH",
]


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 @@ -656,3 +656,9 @@
title="STONE/USD spot price",
q=SpotPrice(asset="stone", currency="usd"),
)

query_catalog.add_entry(
tag="superoethb-eth-spot",
title="superOETHb/ETH spot price",
q=SpotPrice(asset="superoethb", currency="eth"),
)
1 change: 1 addition & 0 deletions src/telliot_feeds/sources/price/spot/coingecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"tara": "taraxa",
"pufeth": "pufeth",
"stone": "stakestone-ether",
"superoethb": "super-oeth",
}

API_KEY = TelliotConfig().api_keys.find(name="coingecko")[0].key
Expand Down
22 changes: 22 additions & 0 deletions tests/feeds/test_superoethb_eth_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import statistics

import pytest

from telliot_feeds.feeds.superoethb_eth_feed import superoethb_eth_median_feed


@pytest.mark.asyncio
async def test_superoethb_eth_median_feed(caplog):
"""Retrieve median superOETHb/ETH price."""
v, _ = await superoethb_eth_median_feed.source.fetch_new_datapoint()

assert v is not None
assert v > 0
assert "sources used in aggregate: 1" in caplog.text.lower()
print(f"superOETHb/eth Price: {v}")

# Get list of data sources from sources dict
source_prices = [source.latest[0] for source in superoethb_eth_median_feed.source.sources if source.latest[0]]

# Make sure error is less than decimal tolerance
assert (v - statistics.median(source_prices)) < 10**-6

0 comments on commit 4fc9123

Please sign in to comment.