data.portfolios

Data for analyzing a portfolio of different tokens.

Examples

from datetime import datetime
from web3cat.data import PortfolioData

addresses = [
    "0x78605Df79524164911C144801f41e9811B7DB73D",
    "0xBF72Da2Bd84c5170618Fbe5914B0ECA9638d5eb5",
    "0x8EB8a3b98659Cce290402893d0123abb75E3ab28"
]
tokens = ["USDC", "WETH", "ETH", "WBTC"]
base_tokens = ["USDC", "WETH"]
portfolio_data = PortfolioData(
    tokens=tokens,
    base_tokens=base_tokens,
    addresses = addresses,
    start = datetime(2022, 6, 1),
    end = datetime(2022, 9, 1),
    numpoints = 4
)

# Portfolio value in USDC by address for USDC, WETH, ETH and WBTC holdings
portfolio_data.breakdown_by_address("USDC")

# Portfolio value in WETH by address for USDC, WETH, ETH and WBTC holdings
portfolio_data.breakdown_by_address("WETH")

# Portfolio value in USDC by token for USDC, WETH, ETH and WBTC holdings
portfolio_data.breakdown_by_token("USDC")

# Portfolio value in WETH by token for USDC, WETH, ETH and WBTC holdings
portfolio_data.breakdown_by_token("WETH")

# Balance and price data
portfolio_data.balances_and_prices

# Balances of a one specific token
portfolio_data.balances("USDC")
class web3cat.data.portfolios.PortfolioData(tokens: List[str], base_tokens: List[str], addresses: List[str], start: int | datetime.datetime, end: int | datetime.datetime, numpoints: int, **kwargs)

Bases: DataCore

Portfolio data (a group of tokens for a group of addresses)

Parameters:
  • tokens – A list of tokens to track

  • base_tokens – A list of tokens for aggregation by price

  • addresses – A list of addresses to track

  • start – start of the data

  • end – endof the data

  • numpoints – number of points between start and end

property tokens: List[ERC20Meta]

Tracked tokens metas.

property base_tokens: List[ERC20Meta]

Base tokens metas.

balances(base_token: str) DataFrame

Breakdown of a specific token holdings by the owner address.

Note

Unlike breakdown_by_address() it doesn’t convert other tokens. For example, with basetoken='USDC' ETH holdings will be just ignored.

Parameters:

base_token – token for holdings

Return type:

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

<address N>

numpy.float64

Balance of the address of base_token

total

numpy.float64

Total portfolio balance of base_token

breakdown_by_address(base_token: str) DataFrame

Breakdown of token holdings by the owner address.

Parameters:

base_token – token for denomination of holdings

Return type:

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

<address N>

numpy.float64

Balance of the address in base_token

total

numpy.float64

Total portfolio balance in base_token

breakdown_by_token(base_token: str) DataFrame

Breakdown of token holdings by the owner address.

Parameters:

base_token – token for denomination of holdings

Return type:

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

<token> (<base_token>)

numpy.float64

Value of token in base_token

total

numpy.float64

Total portfolio balance in base_token

property balances_and_prices: DataFrame

Balances and prices data.

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

address

str

Address of tokens owner

<token>

numpy.float64

Value of token in base_token

<token> / <base_token>

numpy.float64

Price of token in terms of base token

total

numpy.float64

Total portfolio balance in base_token