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:
Add data feed in src/telliot_feeds/feeds/. For example, for adding BTCTEST/USD, create file src/telliot_feeds/feeds/btctest_usd_feed.py:
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.coinbase import CoinbaseSpotPriceSource
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource
from telliot_feeds.sources.price.spot.gemini import GeminiSpotPriceSource
from telliot_feeds.sources.price.spot.kraken import KrakenSpotPriceSource
from telliot_feeds.sources.price_aggregator import PriceAggregator
btctest_usd_median_feed = DataFeed(
query=SpotPrice(asset="BTCTEST", currency="USD"),
source=PriceAggregator(
asset="btctest",
currency="usd",
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="btc", currency="usd"),
BinanceSpotPriceSource(asset="btc", currency="usdt"),
CoinbaseSpotPriceSource(asset="btc", currency="usd"),
GeminiSpotPriceSource(asset="btc", currency="usd"),
KrakenSpotPriceSource(asset="btc", currency="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:
Test your new feed in tests/feeds/. For example, once you've created a data feed for an BTCTEST/USD spot price using an aggregate of a few price sources, create file tests/feeds/test_btctest_usd_feed.py:
import statistics
import pytest
from telliot_feeds.feeds.btctest_usd_feed import btctest_usd_median_feed
@pytest.mark.asyncio
async def test_btctest_usd_median_feed(caplog):
"""Retrieve median BTC/USD price."""
v, _ = await btctest_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() 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 tolerance
assert (v - statistics.median(source_prices)) < 10**-6
Create a pull request to merge your changes into the main branch here.
Using pulseX as source
There's a V1 and V2 versions for pulseX source in /source/spot/price.
Make sure to use the one where your token address, for the feed you're creating, is available.
to import from pulsex_subgraph or pulsex_subgraph_v2 sources, just use:
If you want to create a Testnet token feed (using the testnet RPC) set the token key to start with t* when fetching the source. This will tell the program to use Testnet RPC to fetch the price.
If the token is for Mainnet, just set it under #mainnet tokens . The program will use the Mainnet RPC for the token keys not starting with t* .
Now, if we report with btctest-usd-spot it should use the sources we created, including pulseX v1 for this example.
To use pulseX v2, follow the same process but pay attention to the name of the sources.