This page outlines the steps to add support for reporting a new spot price to your Telliot reporter and optionally share that with the community via the Fetch open source Github repo.
Add spot price to catalog. See src/telliot_feeds/queries/query_catalog.py. For example let's add a query called btctest-usd-spot for testing, adding BTCTEST/USD:
In the above example, we use the PriceAggregator to aggregate the price from multiple sources (automatic API fetches, not sources that require manual entry). The algorithm can be median or mean. The sources can be any combination of those found in src/telliot_feeds/sources/price/spot/ directory or you can add your own, of course.
You're limited by what asset and currency pairs are supported by the underlying APIs (data providers). For example, if you want to add BTC/JPY, you might use the CoinGeckoSpotPriceSource and BinanceSpotPriceSource (which support BTC/JPY), but not the CoinbaseSpotPriceSource (which does not support BTC/JPY).
You will need to check the documentation of the underlying APIs for which pairs they support or how to parse their values correctly.
3. Add feed to CATALOG_FEEDS constant in src/telliot_feeds/feeds/__init__.py:
from telliot_feeds.feeds.btctest_usd_feed import btctest_usd_median_feedCATALOG_FEEDS ={ ..."btctest-usd-spot": btctest_usd_median_feed,}
Add currency/asset to supported lists in src/telliot_feeds/queries/price/spot_price.py. For example, for adding BTCTEST/USD:
Test your new feed in tests/feeds/. For example, once you've created a datafeed for an BTCTEST/USD spot price using an aggregate of a few price sourcees, create file tests/feeds/test_btctest_usd_feed.py:
import statisticsimport pytestfrom telliot_feeds.feeds.btctest_usd_feed import btctest_usd_median_feed@pytest.mark.asyncioasyncdeftest_btctest_usd_median_feed(caplog):"""Retrieve median BTC/USD price.""" v, _ =await btctest_usd_median_feed.source.fetch_new_datapoint()assert v isnotNoneassert v >0assert ("sources used in aggregate: 4"in caplog.text.lower()or"sources used in aggregate: 5"in caplog.text.lower() )print(f"BTC/USD Price: {v}")# Get list of data sources from sources dict source_prices = [source.latest[0]for source in btctest_usd_median_feed.source.sources if source.latest[0]]# Make sure error is less than decimal toleranceassert (v - statistics.median(source_prices)) <10**-6
Create a pull request to merge your changes into the main branch here.