Skip to content

Commit

Permalink
Merge pull request #707 from tellor-io/diva-usd-feed
Browse files Browse the repository at this point in the history
added diva/usd feed (coingecko)
  • Loading branch information
0xSpuddy authored Sep 18, 2023
2 parents a42553f + e9a8fb2 commit fc7b855
Show file tree
Hide file tree
Showing 6 changed files with 51 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 @@ -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
Expand Down Expand Up @@ -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]] = {
Expand Down
19 changes: 19 additions & 0 deletions src/telliot_feeds/feeds/diva_usd_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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"),
],
),
)
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 @@ -67,6 +67,7 @@
"OUSD/USD",
"OETH/ETH",
"WLD/USD",
"DIVA/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 @@ -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"),
)
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 @@ -58,6 +58,7 @@
"ousd": "origin-dollar",
"sweth": "sweth",
"wld": "worldcoin",
"diva": "diva-protocol",
}


Expand Down
22 changes: 22 additions & 0 deletions tests/feeds/test_diva_usd_feed.py
Original file line number Diff line number Diff line change
@@ -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_usd_median_feed]
print(source_prices)

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

0 comments on commit fc7b855

Please sign in to comment.