Skip to content

Commit

Permalink
Merge pull request #741 from tellor-io/cleanup-feeds-v0.1.16
Browse files Browse the repository at this point in the history
Cleanup Feeds for Release v0.1.16
  • Loading branch information
akremstudy authored Jan 31, 2024
2 parents d3afa92 + 5d32881 commit 2d99868
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 164 deletions.
2 changes: 0 additions & 2 deletions docs/new-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Snapshot(AbiQuery):
from telliot_feeds.datafeed import DataFeed
from telliot_feeds.queries.price.spot_price import SpotPrice
from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceSource
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource
Expand All @@ -64,7 +63,6 @@ matic_usd_median_feed = DataFeed(
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="matic", currency="usd"),
BittrexSpotPriceSource(asset="matic", currency="usd"),
BinanceSpotPriceSource(asset="matic", currency="usdt"),
CoinbaseSpotPriceSource(asset="matic", currency="usd"),
GeminiSpotPriceSource(asset="matic", currency="usd"),
Expand Down
2 changes: 1 addition & 1 deletion src/telliot_feeds/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.15"
__version__ = "0.1.16"
2 changes: 0 additions & 2 deletions src/telliot_feeds/feeds/dai_usd_feed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from telliot_feeds.datafeed import DataFeed
from telliot_feeds.queries.price.spot_price import SpotPrice
from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceSource
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource
Expand All @@ -18,7 +17,6 @@
CoinbaseSpotPriceSource(asset="dai", currency="usd"),
BinanceSpotPriceSource(asset="dai", currency="usdt"),
GeminiSpotPriceSource(asset="dai", currency="usd"),
BittrexSpotPriceSource(asset="dai", currency="usd"),
],
),
)
2 changes: 0 additions & 2 deletions src/telliot_feeds/feeds/matic_usd_feed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from telliot_feeds.datafeed import DataFeed
from telliot_feeds.queries.price.spot_price import SpotPrice
from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceSource
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource
Expand All @@ -16,7 +15,6 @@
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="matic", currency="usd"),
BittrexSpotPriceSource(asset="matic", currency="usd"),
BinanceSpotPriceSource(asset="matic", currency="usdt"),
CoinbaseSpotPriceSource(asset="matic", currency="usd"),
GeminiSpotPriceSource(asset="matic", currency="usd"),
Expand Down
2 changes: 0 additions & 2 deletions src/telliot_feeds/feeds/mkr_usd_feed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from telliot_feeds.datafeed import DataFeed
from telliot_feeds.queries.price.spot_price import SpotPrice
from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceSource
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource
Expand All @@ -16,7 +15,6 @@
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="mkr", currency="usd"),
BittrexSpotPriceSource(asset="mkr", currency="usdt"),
BinanceSpotPriceSource(asset="mkr", currency="usdt"),
CoinbaseSpotPriceSource(asset="mkr", currency="usd"),
GeminiSpotPriceSource(asset="mkr", currency="usd"),
Expand Down
4 changes: 2 additions & 2 deletions src/telliot_feeds/feeds/ogv_eth_feed.py
Original file line number Diff line number Diff line change
@@ -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.coinpaprika import CoinpaprikaSpotPriceSource
from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource
from telliot_feeds.sources.price.spot.uniswapV3Pool import UniswapV3PoolPriceSource
from telliot_feeds.sources.price_aggregator import PriceAggregator


Expand All @@ -13,7 +13,7 @@
algorithm="median",
sources=[
CoinpaprikaSpotPriceSource(asset="ogv-origin-dollar-governance", currency="eth"),
UniswapV3PriceSource(asset="ogv", currency="eth"),
UniswapV3PoolPriceSource(asset="ogv", currency="eth"),
],
),
)
2 changes: 0 additions & 2 deletions src/telliot_feeds/feeds/sushi_usd_feed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from telliot_feeds.datafeed import DataFeed
from telliot_feeds.queries.price.spot_price import SpotPrice
from telliot_feeds.sources.price.spot.binance import BinanceSpotPriceSource
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceSource
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource
Expand All @@ -16,7 +15,6 @@
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="sushi", currency="usd"),
BittrexSpotPriceSource(asset="sushi", currency="usd"),
BinanceSpotPriceSource(asset="sushi", currency="usdt"),
CoinbaseSpotPriceSource(asset="sushi", currency="usd"),
GeminiSpotPriceSource(asset="sushi", currency="usd"),
Expand Down
2 changes: 0 additions & 2 deletions src/telliot_feeds/feeds/xdai_usd_feed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from telliot_feeds.datafeed import DataFeed
from telliot_feeds.queries.price.spot_price import SpotPrice
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceSource
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price_aggregator import PriceAggregator
Expand All @@ -14,7 +13,6 @@
sources=[
CoinGeckoSpotPriceSource(asset="xdai", currency="usd"),
CoinbaseSpotPriceSource(asset="dai", currency="usd"),
BittrexSpotPriceSource(asset="dai", currency="usd"),
],
),
)
82 changes: 0 additions & 82 deletions src/telliot_feeds/sources/price/spot/bittrex.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/telliot_feeds/sources/price/spot/coingecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"uni": "uniswap",
"usdt": "tether",
"yfi": "yearn-finance",
"steth": "lido-staked-ether",
"steth": "staked-ether",
"reth": "rocket-pool-eth",
"op": "optimism",
"grt": "the-graph",
Expand Down
2 changes: 1 addition & 1 deletion src/telliot_feeds/sources/price/spot/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, **kwargs: Any):
async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]:
"""Implement PriceServiceInterface
This implementation gets the price from the Bittrex API
This implementation gets the price from the Gemini API
Note that the timestamp returned form the coinbase API could be used
instead of the locally generated timestamp.
Expand Down
1 change: 0 additions & 1 deletion src/telliot_feeds/sources/price/spot/uniswapV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"sweth": "0xf951e335afb289353dc249e82926178eac7ded78",
"cbeth": "0xbe9895146f7af43049ca1c1ae358b0541ea49704",
"oeth": "0x856c4efb76c1d1ae02e20ceb03a2a6a08b0b8dc3",
"ogv": "0x9c354503c38481a7a7a51629142963f98ecc12d0",
"wbtc": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"mnt": "0x3c3a81e81dc49a522a592e7622a7e711c06bf354",
}
Expand Down
26 changes: 18 additions & 8 deletions src/telliot_feeds/sources/price/spot/uniswapV3Pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@


logger = get_logger(__name__)
uniswapV3Pool_map = {

uniswapV3token0__pool_map = {
"oeth": "0x52299416c469843f4e0d54688099966a6c7d720f",
}


uniswapV3token1__pool_map = {
"ogv": "0xa0b30e46f6aeb8f5a849241d703254bb4a719d92",
}


class UniswapV3PoolPriceService(WebPriceService):
"""UniswapV3 Price Service for Pool Ratios"""

Expand All @@ -28,23 +34,27 @@ def __init__(self, **kwargs: Any) -> None:

async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]:
"""Implement PriceServiceInterface
This implementation gets the price from the UniswapV3 subgraph using the pool query
https://docs.uniswap.org/sdk/subgraph/subgraph-examples
"""

asset = asset.lower()
pool0 = uniswapV3token0__pool_map.get(asset, None)
pool1 = uniswapV3token1__pool_map.get(asset, None)

pool = uniswapV3Pool_map.get(asset, None)
if not pool:
if not pool0 and not pool1:
raise Exception("Asset not supported: {}".format(asset))

headers = {
"Content-Type": "application/json",
}
if pool0:
query = "{pool" + f'(id: "{pool0}")' + "{ token0Price } }"
key = "token0Price"

query = "{pool" + f'(id: "{pool}")' + "{ token0Price } }"
if pool1:
query = "{pool" + f'(id: "{pool1}")' + "{ token1Price } }"
key = "token1Price"

json_data = {"query": query}

Expand Down Expand Up @@ -72,10 +82,10 @@ async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]
response = data["response"]

try:
token_price = float(response["data"]["pool"]["token0Price"])
token_price = float(response["data"]["pool"][key])
return token_price, datetime_now_utc()
except KeyError as e:
msg = "Error parsing MaverickV2 response: KeyError: {}".format(e)
msg = "Error parsing UniswapV3 pool response: KeyError: {}".format(e)
logger.critical(msg)
return None, None

Expand Down
2 changes: 1 addition & 1 deletion tests/feeds/test_reth_btc_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def test_reth_btc_median_feed(caplog):

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

# Get list of data sources from sources dict
Expand Down
17 changes: 0 additions & 17 deletions tests/feeds/test_wsteth_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
import pytest

from telliot_feeds.feeds.wsteth_feed import wsteth_eth_median_feed
from telliot_feeds.feeds.wsteth_feed import wsteth_usd_median_feed


@pytest.mark.asyncio
async def test_wsteth_usd_median_feed(caplog):
"""Retrieve median WSTETH/USD price."""
v, _ = await wsteth_usd_median_feed.source.fetch_new_datapoint()

assert v is not None
assert v > 0
assert "sources used in aggregate: 4" in caplog.text.lower()
print(f"WSTETH/USD Price: {v}")
# Get list of data sources from sources dict
source_prices = wsteth_usd_median_feed.source.latest[0]

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


@pytest.mark.asyncio
Expand Down
38 changes: 0 additions & 38 deletions tests/sources/test_spot_price_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from telliot_core.apps.telliot_config import TelliotConfig

from telliot_feeds.sources.price.spot.bitfinex import BitfinexSpotPriceService
from telliot_feeds.sources.price.spot.bittrex import BittrexSpotPriceService
from telliot_feeds.sources.price.spot.coinbase import CoinbaseSpotPriceService
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceService
from telliot_feeds.sources.price.spot.coinmarketcap import CoinMarketCapSpotPriceService
Expand All @@ -31,7 +30,6 @@
service = {
"coinbase": CoinbaseSpotPriceService(),
"coingecko": CoinGeckoSpotPriceService(),
"bittrex": BittrexSpotPriceService(),
"gemini": GeminiSpotPriceService(),
"nomics": NomicsSpotPriceService(),
"pancakeswap": PancakeswapPriceService(),
Expand Down Expand Up @@ -148,42 +146,6 @@ def bad_status(*args, **kwargs):
print("No CoinMarketCap API key ")


@pytest.mark.asyncio
async def test_bittrex(caplog):
"""Test retrieving from Bittrex price source."""
v, t = await get_price("btc", "usd", service["bittrex"])

if "Unable to decode Bittrex JSON" in caplog.text:
assert v is None
assert t is None
else:
validate_price(v, t)

# test rate limiting
def mock_get_url(*args, **kwargs):
return {"error": "blah", "exception": Exception("restrictions that prevent you from accessing the site")}

with mock.patch(
"telliot_feeds.sources.price.spot.bittrex.BittrexSpotPriceService.get_url", side_effect=mock_get_url
):
v, t = await get_price("btc", "usd", service["bittrex"])
assert v is None
assert t is None
assert "Bittrex API rate limit exceeded" in caplog.text

# test unknown error
def mock_get_url2(*args, **kwargs):
return {"error": "bingo", "exception": Exception("bango")}

with mock.patch(
"telliot_feeds.sources.price.spot.bittrex.BittrexSpotPriceService.get_url", side_effect=mock_get_url2
):
v, t = await get_price("btc", "usd", service["bittrex"])
assert v is None
assert t is None
assert "Exception('bango')" in caplog.text


@pytest.mark.asyncio
async def test_gemini(caplog, monkeypatch):
"""Test retrieving from Gemini price source."""
Expand Down

0 comments on commit 2d99868

Please sign in to comment.