Web3Cat
latest

User guide

  • Intro
  • Getting started
  • Cookbook
  • Technical details

Api

  • view
  • data
    • data.chainlink
      • ChainlinkData
        • ChainlinkData.add_token()
        • ChainlinkData.get_data()
        • ChainlinkData.prices()
      • ChainlinkUSDData
        • ChainlinkUSDData.meta
        • ChainlinkUSDData.oracle_proxy_contract
        • ChainlinkUSDData.oracle_aggregator_contract
        • ChainlinkUSDData.oracle_decimals
        • ChainlinkUSDData.initial_price
        • ChainlinkUSDData.index
        • ChainlinkUSDData.prices()
        • ChainlinkUSDData.updates
    • data.ethers
    • data.erc20s
    • data.portfolios
    • data.gearbox
    • data.core
  • fetcher
Web3Cat
  • data
  • data.chainlink
  • Edit on GitHub

data.chainlink

Chainlink prices datasets.

The module has two classes:

  • ChainlinkData is a price data for a pair of tokens

  • ChainlinkUSDData is 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: DataCore

Chainlink 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

timestamp

numpy.int64

Timestamp for the snapshot of the balance

date

datetime.datetime

Date for the timestamp

block_number

int

Number of the block

price

numpy.float64

Relative price

class web3cat.data.chainlink.ChainlinkUSDData(token: str, start: int | datetime.datetime, end: int | datetime.datetime, **kwargs)

Bases: DataCore

Chainlink data for a specific token.

property meta: ERC20Meta

Metadata for tokens (like name, symbol and decimals)

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 oracle_decimals: int

Chainlink oracle decimals

property initial_price: float64

Oracle price at from_block

property index: Dict[str, Any]

Oracles index

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

Previous Next

© Copyright 2022, Mono6. Revision 2fc1d667.

Built with Sphinx using a theme provided by Read the Docs.