data.chainlink
Chainlink prices datasets.
The module has two classes:
ChainlinkDatais a price data for a pair of tokensChainlinkUSDDatais a price data of a token for usd
ChainlinkUSDData is a strictly less powerful data source.
However, it’s also more lightweight than ChainlinkData.
The latter has two ChainlinkUSDData under the hood and
relative price tokens are determined using cross exchange rates
to USD.
Note
Expect the error of up to 2% in this price data (this is how chainlink oracles work)
Note
Current oracles data are generally available from mid-2021.
Examples
from datetime import datetime
from web3cat.data import ChainlinkData
dates = [datetime(2021, 6, 1), datetime(2021, 7, 1), datetime(2021, 8, 1), datetime(2021, 9, 1)]
tokens = ["USDC", "WETH", "WBTC"]
chainlink_data = ChainlinkData(tokens, min(dates), max(dates))
# Historical prices WETH/USDC
chainlink_data.prices("WETH", "USDC", dates)
# Historical prices WBTC/WETH
chainlink_data.prices("WBTC", "WETH", dates)
# Underlying USDC/USD prices
chainlink_data.get_data("USDC").prices(dates)
- class web3cat.data.chainlink.ChainlinkData(tokens: List[str], start: int | datetime.datetime, end: int | datetime.datetime, **kwargs)
Bases:
DataCoreChainlink price feed for tokens.
- Parameters:
tokens – a list of ERC20 tokens
start – start of a dataset
end – end of a dataset
kwargs – arguments for fetchers, see
fetcher.core.Core
- add_token(token: str, start: Optional[Union[int, datetime]] = None, end: Optional[Union[int, datetime]] = None, proxy: Optional[str] = None)
Add token to prices dataset.
- Parameters:
token – token to add
start – start of the data
end – end of the data
- get_data(token: str) ChainlinkUSDData
Get chainlink USD data for token.
- Agruments:
token: ERC20 token
- Returns:
Chainlink USD data for token
- prices(token0: str, token1: str, timepoints: List[int | datetime.datetime]) DataFrame
Chainlink prices for pair of tokens. The token0 = “WETH”, token1 = “USDC” would mean the regular WETH/USDC (that is how much dollars we give for 1 ETH)
Dataframe with balances for addresses over time.
- Parameters:
token0 – The first token
token1 – The second token
timepoints – A list of timepoints (see
ERC20Data)
- Returns:
A Dataframe with fields
Field
Type
Description
timestampTimestamp for the snapshot of the balance
dateDate for the timestamp
block_numberNumber of the block
priceRelative price
- class web3cat.data.chainlink.ChainlinkUSDData(token: str, start: int | datetime.datetime, end: int | datetime.datetime, **kwargs)
Bases:
DataCoreChainlink data for a specific token.
- property oracle_proxy_contract: Contract
A reference to Chainlink oracle proxy contract
- property oracle_aggregator_contract: Contract
A reference to Chainlink oracle aggregator contract
- property initial_price: float64
Oracle price at from_block
- prices(timepoints: List[int | datetime.datetime]) DataFrame
Chainlink price feed.
- Parameters:
timepoints – A list of timepoints for prices
- property updates: DataFrame
A list of oracle updates