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:
DataCorePortfolio 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
startandend
- 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, withbasetoken='USDC'ETH holdings will be just ignored.- Parameters:
base_token – token for holdings
- Return type:
A Dataframe with fields
Field
Type
Description
timestampTimestamp for the snapshot of the balance
dateDate for the timestamp
block_numberNumber of the block
<address N>Balance of the address of
base_tokentotalTotal 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
timestampTimestamp for the snapshot of the balance
dateDate for the timestamp
block_numberNumber of the block
<address N>Balance of the address in
base_tokentotalTotal 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
timestampTimestamp for the snapshot of the balance
dateDate for the timestamp
block_numberNumber of the block
<token> (<base_token>)Value of token in
base_tokentotalTotal portfolio balance in
base_token
- property balances_and_prices: DataFrame
Balances and prices data.
Field
Type
Description
timestampTimestamp for the snapshot of the balance
dateDate for the timestamp
block_numberNumber of the block
addressAddress of tokens owner
<token>Value of token in
base_token<token> / <base_token>Price of token in terms of base token
totalTotal portfolio balance in
base_token