eth_portfolio package
Subpackages
- eth_portfolio.protocols package
- Subpackages
- Submodules
- eth_portfolio.protocols.convex module
- eth_portfolio.protocols.dsr module
- eth_portfolio.protocols.liquity module
LiquityStabilityPool
LiquityStabilityPool._balances()
LiquityStabilityPool.should_check()
LiquityStabilityPool.__call__
LiquityStabilityPool.balance_method_name
LiquityStabilityPool.balances
LiquityStabilityPool.contract
LiquityStabilityPool.contract_address
LiquityStabilityPool.contract_call
LiquityStabilityPool.deploy_block
LiquityStabilityPool.networks
LiquityStabilityPool.price
LiquityStabilityPool.scale
LiquityStabilityPool.token
LqtyStakingPool
LqtyStakingPool._balances()
LqtyStakingPool.should_check()
LqtyStakingPool.__call__
LqtyStakingPool.balance_method_name
LqtyStakingPool.balances
LqtyStakingPool.contract
LqtyStakingPool.contract_address
LqtyStakingPool.contract_call
LqtyStakingPool.deploy_block
LqtyStakingPool.networks
LqtyStakingPool.price
LqtyStakingPool.scale
LqtyStakingPool.token
- Module contents
- eth_portfolio.structs package
- Submodules
- eth_portfolio.structs.modified module
CallTrace
CallTrace.__getitem__()
CallTrace.__iter__()
CallTrace.get()
CallTrace.items()
CallTrace.keys()
CallTrace.values()
CallTrace._action
CallTrace.action
CallTrace.block
CallTrace.blockHash
CallTrace.blockNumber
CallTrace.error
CallTrace.result
CallTrace.subtraces
CallTrace.traceAddress
CallTrace.transactionHash
CallTrace.transactionPosition
CallTrace.type
CreateTrace
CreateTrace.__getitem__()
CreateTrace.__iter__()
CreateTrace.get()
CreateTrace.items()
CreateTrace.keys()
CreateTrace.values()
CreateTrace._action
CreateTrace.action
CreateTrace.block
CreateTrace.blockHash
CreateTrace.blockNumber
CreateTrace.error
CreateTrace.result
CreateTrace.subtraces
CreateTrace.traceAddress
CreateTrace.transactionHash
CreateTrace.transactionPosition
CreateTrace.type
RewardTrace
RewardTrace.__getitem__()
RewardTrace.__iter__()
RewardTrace.get()
RewardTrace.items()
RewardTrace.keys()
RewardTrace.values()
RewardTrace._action
RewardTrace.action
RewardTrace.block
RewardTrace.blockHash
RewardTrace.blockNumber
RewardTrace.error
RewardTrace.subtraces
RewardTrace.traceAddress
RewardTrace.transactionHash
RewardTrace.transactionPosition
RewardTrace.type
SuicideTrace
SuicideTrace.__getitem__()
SuicideTrace.__iter__()
SuicideTrace.get()
SuicideTrace.items()
SuicideTrace.keys()
SuicideTrace.values()
SuicideTrace.action
SuicideTrace.block
SuicideTrace.blockHash
SuicideTrace.blockNumber
SuicideTrace.error
SuicideTrace.result
SuicideTrace.subtraces
SuicideTrace.traceAddress
SuicideTrace.transactionHash
SuicideTrace.transactionPosition
SuicideTrace.type
- eth_portfolio.structs.structs module
InternalTransfer
InternalTransfer.__getitem__()
InternalTransfer.__iter__()
InternalTransfer.from_trace()
InternalTransfer.get()
InternalTransfer.items()
InternalTransfer.keys()
InternalTransfer.values()
InternalTransfer._evm_object
InternalTransfer.block_hash
InternalTransfer.block_number
InternalTransfer.call_type
InternalTransfer.chainid
InternalTransfer.entry_type
InternalTransfer.from_address
InternalTransfer.gas
InternalTransfer.gas_used
InternalTransfer.hash
InternalTransfer.input
InternalTransfer.output
InternalTransfer.price
InternalTransfer.reward_type
InternalTransfer.subtraces
InternalTransfer.to_address
InternalTransfer.trace
InternalTransfer.trace_address
InternalTransfer.transaction_index
InternalTransfer.type
InternalTransfer.value
InternalTransfer.value_usd
TokenTransfer
TokenTransfer.__getitem__()
TokenTransfer.__iter__()
TokenTransfer.get()
TokenTransfer.items()
TokenTransfer.keys()
TokenTransfer.values()
TokenTransfer._evm_object
TokenTransfer.block_number
TokenTransfer.chainid
TokenTransfer.entry_type
TokenTransfer.from_address
TokenTransfer.hash
TokenTransfer.log
TokenTransfer.log_index
TokenTransfer.price
TokenTransfer.to_address
TokenTransfer.token
TokenTransfer.token_address
TokenTransfer.transaction_index
TokenTransfer.value
TokenTransfer.value_usd
Transaction
Transaction.__getitem__()
Transaction.__iter__()
Transaction.from_rpc_response()
Transaction.get()
Transaction.items()
Transaction.keys()
Transaction.values()
Transaction._evm_object
Transaction.access_list
Transaction.block_hash
Transaction.block_number
Transaction.chainid
Transaction.entry_type
Transaction.from_address
Transaction.gas
Transaction.gas_price
Transaction.hash
Transaction.input
Transaction.max_fee_per_gas
Transaction.max_priority_fee_per_gas
Transaction.nonce
Transaction.price
Transaction.r
Transaction.s
Transaction.to_address
Transaction.transaction
Transaction.transaction_index
Transaction.type
Transaction.v
Transaction.value
Transaction.value_usd
Transaction.y_parity
TransactionRLP
TransactionRLP.__getitem__()
TransactionRLP.__iter__()
TransactionRLP.from_rpc_response()
TransactionRLP.get()
TransactionRLP.items()
TransactionRLP.keys()
TransactionRLP.values()
TransactionRLP._evm_object
TransactionRLP.access_list
TransactionRLP.block_hash
TransactionRLP.block_number
TransactionRLP.chainid
TransactionRLP.entry_type
TransactionRLP.from_address
TransactionRLP.gas
TransactionRLP.gas_price
TransactionRLP.hash
TransactionRLP.input
TransactionRLP.max_fee_per_gas
TransactionRLP.max_priority_fee_per_gas
TransactionRLP.nonce
TransactionRLP.price
TransactionRLP.r
TransactionRLP.s
TransactionRLP.to_address
TransactionRLP.transaction
TransactionRLP.transaction_index
TransactionRLP.type
TransactionRLP.v
TransactionRLP.value
TransactionRLP.value_usd
TransactionRLP.y_parity
_LE
_LedgerEntryBase
_TransactionBase
_TransactionBase.__getitem__()
_TransactionBase.__iter__()
_TransactionBase.from_rpc_response()
_TransactionBase.get()
_TransactionBase.items()
_TransactionBase.keys()
_TransactionBase.values()
_TransactionBase._evm_object
_TransactionBase.access_list
_TransactionBase.block_hash
_TransactionBase.block_number
_TransactionBase.chainid
_TransactionBase.entry_type
_TransactionBase.from_address
_TransactionBase.gas
_TransactionBase.gas_price
_TransactionBase.hash
_TransactionBase.input
_TransactionBase.max_fee_per_gas
_TransactionBase.max_priority_fee_per_gas
_TransactionBase.nonce
_TransactionBase.price
_TransactionBase.r
_TransactionBase.s
_TransactionBase.to_address
_TransactionBase.transaction_index
_TransactionBase.type
_TransactionBase.v
_TransactionBase.value
_TransactionBase.value_usd
_TransactionBase.y_parity
_get_init_kwargs()
LedgerEntry
- Module contents
InternalTransfer
InternalTransfer.__getitem__()
InternalTransfer.__iter__()
InternalTransfer.from_trace()
InternalTransfer.get()
InternalTransfer.items()
InternalTransfer.keys()
InternalTransfer.values()
InternalTransfer._evm_object
InternalTransfer.block_hash
InternalTransfer.block_number
InternalTransfer.call_type
InternalTransfer.chainid
InternalTransfer.entry_type
InternalTransfer.from_address
InternalTransfer.gas
InternalTransfer.gas_used
InternalTransfer.hash
InternalTransfer.input
InternalTransfer.output
InternalTransfer.price
InternalTransfer.reward_type
InternalTransfer.subtraces
InternalTransfer.to_address
InternalTransfer.trace
InternalTransfer.trace_address
InternalTransfer.transaction_index
InternalTransfer.type
InternalTransfer.value
InternalTransfer.value_usd
TokenTransfer
TokenTransfer.__getitem__()
TokenTransfer.__iter__()
TokenTransfer.get()
TokenTransfer.items()
TokenTransfer.keys()
TokenTransfer.values()
TokenTransfer._evm_object
TokenTransfer.block_number
TokenTransfer.chainid
TokenTransfer.entry_type
TokenTransfer.from_address
TokenTransfer.hash
TokenTransfer.log
TokenTransfer.log_index
TokenTransfer.price
TokenTransfer.to_address
TokenTransfer.token
TokenTransfer.token_address
TokenTransfer.transaction_index
TokenTransfer.value
TokenTransfer.value_usd
Transaction
Transaction.__getitem__()
Transaction.__iter__()
Transaction.from_rpc_response()
Transaction.get()
Transaction.items()
Transaction.keys()
Transaction.values()
Transaction._evm_object
Transaction.access_list
Transaction.block_hash
Transaction.block_number
Transaction.chainid
Transaction.entry_type
Transaction.from_address
Transaction.gas
Transaction.gas_price
Transaction.hash
Transaction.input
Transaction.max_fee_per_gas
Transaction.max_priority_fee_per_gas
Transaction.nonce
Transaction.price
Transaction.r
Transaction.s
Transaction.to_address
Transaction.transaction
Transaction.transaction_index
Transaction.type
Transaction.v
Transaction.value
Transaction.value_usd
Transaction.y_parity
TransactionRLP
TransactionRLP.__getitem__()
TransactionRLP.__iter__()
TransactionRLP.from_rpc_response()
TransactionRLP.get()
TransactionRLP.items()
TransactionRLP.keys()
TransactionRLP.values()
TransactionRLP._evm_object
TransactionRLP.access_list
TransactionRLP.block_hash
TransactionRLP.block_number
TransactionRLP.chainid
TransactionRLP.entry_type
TransactionRLP.from_address
TransactionRLP.gas
TransactionRLP.gas_price
TransactionRLP.hash
TransactionRLP.input
TransactionRLP.max_fee_per_gas
TransactionRLP.max_priority_fee_per_gas
TransactionRLP.nonce
TransactionRLP.price
TransactionRLP.r
TransactionRLP.s
TransactionRLP.to_address
TransactionRLP.transaction
TransactionRLP.transaction_index
TransactionRLP.type
TransactionRLP.v
TransactionRLP.value
TransactionRLP.value_usd
TransactionRLP.y_parity
- eth_portfolio.typing package
- Module contents
PortfolioBalances
PortfolioBalances.__getitem__()
PortfolioBalances.__init__()
PortfolioBalances.__iter__()
PortfolioBalances.get()
PortfolioBalances.items()
PortfolioBalances.keys()
PortfolioBalances.pop()
PortfolioBalances.popitem()
PortfolioBalances.sum_usd()
PortfolioBalances.values()
PortfolioBalances.block
PortfolioBalances.dataframe
PortfolioBalances.inverted
PortfolioBalancesByCategory
PortfolioBalancesByCategory.__getitem__()
PortfolioBalancesByCategory.__init__()
PortfolioBalancesByCategory.__iter__()
PortfolioBalancesByCategory.get()
PortfolioBalancesByCategory.invert()
PortfolioBalancesByCategory.items()
PortfolioBalancesByCategory.keys()
PortfolioBalancesByCategory.pop()
PortfolioBalancesByCategory.popitem()
PortfolioBalancesByCategory.values()
PortfolioBalancesByCategory.assets
PortfolioBalancesByCategory.debt
RemoteTokenBalances
RemoteTokenBalances.__getitem__()
RemoteTokenBalances.__init__()
RemoteTokenBalances.__iter__()
RemoteTokenBalances.get()
RemoteTokenBalances.items()
RemoteTokenBalances.keys()
RemoteTokenBalances.pop()
RemoteTokenBalances.popitem()
RemoteTokenBalances.sum_usd()
RemoteTokenBalances.values()
RemoteTokenBalances.block
RemoteTokenBalances.dataframe
TokenBalances
WalletBalances
WalletBalances.__getitem__()
WalletBalances.__init__()
WalletBalances.__iter__()
WalletBalances.get()
WalletBalances.items()
WalletBalances.keys()
WalletBalances.pop()
WalletBalances.popitem()
WalletBalances.sum_usd()
WalletBalances.values()
WalletBalances.assets
WalletBalances.dataframe
WalletBalances.debt
WalletBalances.external
WalletBalancesRaw
_SummableNonNumericMixin
_WalletBalancesTD
_WalletBalancesTD.__getitem__()
_WalletBalancesTD.__init__()
_WalletBalancesTD.__iter__()
_WalletBalancesTD.get()
_WalletBalancesTD.items()
_WalletBalancesTD.keys()
_WalletBalancesTD.pop()
_WalletBalancesTD.popitem()
_WalletBalancesTD.values()
_WalletBalancesTD.assets
_WalletBalancesTD.debt
_WalletBalancesTD.external
- Module contents
Submodules
eth_portfolio.address module
This module defines the PortfolioAddress
class, which represents an address managed by the eth-portfolio system.
The PortfolioAddress
class is designed to manage different aspects of an Ethereum address within the portfolio,
such as transactions, transfers, balances, and interactions with both external and lending protocols.
Key components and functionalities provided by the PortfolioAddress
class include:
- Handling Ethereum and token balances
- Managing debt and collateral from lending protocols
- Tracking transactions and transfers (both internal and token transfers)
- Providing comprehensive balance descriptions at specific block heights
The class leverages asynchronous operations using the a_sync library to efficiently gather and process data. It also integrates with various submodules from eth-portfolio to load balances, manage ledgers, and interact with external protocols.
- class eth_portfolio.address.PortfolioAddress[source]
Bases:
_LedgeredBase
Represents a portfolio address within the eth-portfolio system.
This class is designed to manage different aspects of an Ethereum address within the portfolio, such as transactions, transfers, balances, and interactions with both external and lending protocols.
Key components and functionalities provided by the
PortfolioAddress
class include: - Handling Ethereum and token balances - Managing debt and collateral from lending protocols - Tracking transactions and transfers (both internal and token transfers) - Providing comprehensive balance descriptions at specific block heightsThe class leverages asynchronous operations using the a_sync library to efficiently gather and process data. It also integrates with various submodules from eth-portfolio to load balances, manage ledgers, and interact with external protocols.
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = PortfolioAddress(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], _LT) True
- __aiter__()
Return an async iterator that yields {obj} from the {cls}.
- Return type:
AsyncIterator[_T]
- __getitem__(slice)
- Parameters:
slice (slice)
- Return type:
ASyncIterator[_T][_T]
- __init__(address, start_block, load_prices, num_workers_transactions=1000, asynchronous=False)[source]
Initializes the
PortfolioAddress
instance.- Parameters:
address (str | HexBytes | AnyAddress | EthAddress) – The Ethereum address to manage.
start_block (int | BlockNumber) – The block number from which to start tracking.
load_prices (bool) – Flag indicating if price loading is enabled.
num_workers_transactions (optional) – Number of workers for transaction processing. Defaults to 1000.
asynchronous (optional) – Flag for asynchronous operation. Defaults to False.
- Raises:
TypeError – If asynchronous is not a boolean.
- Return type:
None
Examples
>>> address = PortfolioAddress('0x1234...', 0, True) >>> print(address)
>>> address = PortfolioAddress('0x1234...', 0, False, num_workers_transactions=500, asynchronous=True) >>> print(address)
See also
AddressTransactionsLedger
AddressInternalTransfersLedger
AddressTokenTransfersLedger
- __iter__()
Return an iterator that yields {obj} from the {cls}.
Note
Synchronous iteration leverages
ASyncIterator
, which usesasyncio.BaseEventLoop.run_until_complete()
to fetch items.ASyncIterator.__next__()
raises aSyncModeInAsyncContextError
if the event loop is already running.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.
- filter(self, function: ViewFn[T])
Filters the
T
objects yielded by the ASyncIterator[T] based on a function.- Parameters:
function (ViewFn[T]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filteredT
objects from the ASyncIterator[T].
- sort(self, key: SortKey[T] = None, reverse: bool = False)
Sort the
T
objects yielded by the ASyncIterator[T].- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield theT
objects yielded from this ASyncIterator[T], but sorted.
- yield_forever()
- Return type:
ASyncIterator[_T][_T]
- property _ledgers: Tuple[_LT, _LT, _LT]
An iterator with the 3 ledgers (transactions, internal transfers, token transfers)
- address
The address being managed.
- all[source]
Retrieves all ledger entries between two blocks.
- Parameters:
- Returns:
The ledger entries.
- Return type:
Dict[str,
PandableLedgerEntryList
]
Examples
>>> all_entries = await address.all(12000000, 12345678)
- assets[source]
Retrieves the balances for every asset in the wallet at a given block.
- Parameters:
block (optional) – The block number to query. Defaults to None, which uses the latest block.
- Returns:
The asset balances at block.
- Return type:
Examples
>>> assets = await address.assets(12345678)
- asynchronous
Flag indicating if the operations are asynchronous.
- balances[source]
Retrieves balances for all assets in the wallet at a given block.
- Parameters:
block (int | BlockNumber | None) – The block number.
- Returns:
The balances.
- Return type:
Examples
>>> balances = await address.balances(12345678)
- collateral[source]
Retrieves all balances held by lending protocols on behalf of the wallet at a given block.
- Parameters:
block (optional) – The block number. Defaults to None, which uses the latest block.
- Returns:
The collateral balances.
- Return type:
Examples
>>> collateral = await address.collateral(12345678)
- debt[source]
Retrieves all debt balances for the wallet at a given block.
- Parameters:
block (optional) – The block number. Defaults to None, which uses the latest block.
- Returns:
The debt balances at block.
- Return type:
Examples
>>> debt = await address.debt(12345678)
- describe[source]
Describes all of the wallet’s balances at a given block.
- Parameters:
block (int) – The block number.
- Returns:
The wallet balances.
- Return type:
- Raises:
TypeError – If block is not an integer.
Examples
>>> wallet_balances = await address.describe(12345678)
- eth_balance[source]
Retrieves the ETH balance for the wallet at a given block.
- Parameters:
block (int | BlockNumber | None) – The block number.
- Returns:
The ETH balance at block.
- Return type:
Balance
Examples
>>> eth_balance = await address.eth_balance(12345678)
- external_balances[source]
Retrieves the balances owned by the wallet, but not held in the wallet, at a given block.
- Parameters:
block (optional) – The block number. Defaults to None, which uses the latest block.
- Returns:
The external balances.
- Return type:
Examples
>>> external_balances = await address.external_balances(12345678)
- internal_transfers: _LT
Ledger for tracking internal transfers.
- load_prices
Indicates if price loading is enabled.
- materialized
List[T]
Synchronously iterate through the {cls} and return all {obj}.
- Returns:
A list of the {obj} yielded by the {cls}.
- Type:
_AwaitableAsyncIterableMixin.materialized
- staking[source]
Retrieves all balances staked in protocols supported by eth_portfolio on behalf of the wallet at a given block.
- Parameters:
block (optional) – The block number. Defaults to None, which uses the latest block.
- Returns:
The staked balances.
- Return type:
Examples
>>> staking_balances = await address.staking(12345678)
- token_balances[source]
Retrieves the balances for all tokens in the wallet at a given block.
- Parameters:
block – The block number.
- Returns:
The token balances at block.
- Return type:
Examples
>>> token_balances = await address.token_balances(12345678)
- token_transfers: _LT
Ledger for tracking token transfers.
- transactions: _LT
Ledger for tracking transactions.
eth_portfolio.buckets module
- async eth_portfolio.buckets.get_token_bucket(token)[source]
Categorize a token into a specific bucket based on its type.
This function attempts to categorize a given token into predefined buckets such as “Cash & cash equivalents”, “ETH”, “BTC”, “Other long term assets”, or “Other short term assets”. The categorization is based on the token’s characteristics and its presence in specific sets like
ETH_LIKE
,BTC_LIKE
, andOTHER_LONG_TERM_ASSETS
.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address of the token to categorize.
- Returns:
A string representing the bucket category of the token.
- Raises:
ValueError – If the token’s source has not been verified and the error message
does not match the expected pattern. –
- Return type:
Example
Categorize a stablecoin:
>>> await get_token_bucket("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") 'Cash & cash equivalents'
Categorize an ETH-like token:
>>> await get_token_bucket("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") 'ETH'
See also
_unwrap_token()
_is_stable()
eth_portfolio.constants module
eth_portfolio.portfolio module
This module defines the Portfolio
and PortfolioWallets
classes, which are used to manage and interact with a collection of PortfolioAddress
objects.
It also includes the PortfolioLedger
class for handling transactions, internal transfers, and token transfers associated with the portfolio.
The Portfolio
class leverages the a_sync library to support both synchronous and asynchronous operations. This allows it to efficiently gather data, perform portfolio-related tasks, and handle network calls without blocking, thus improving the overall responsiveness and performance of portfolio operations.
This file is part of a larger system that includes modules for handling portfolio addresses, ledger entries, and other related tasks.
- class eth_portfolio.portfolio.Portfolio[source]
Bases:
ASyncGenericBase
Used to export information about a group of
PortfolioAddress
objects.Has all attributes of a
PortfolioAddress
.All calls to function(*args, **kwargs) will return {address: PortfolioAddress(Address).function(*args, **kwargs)}
- __getitem__(key)[source]
Get a
PortfolioAddress
by its key.- Parameters:
key (str | HexBytes | AnyAddress | EthAddress) – The address key.
- Returns:
The
PortfolioAddress
object.- Return type:
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> address = portfolio["0xAddress1"] >>> print(address)
- __init__(addresses, start_block=0, label='your portfolio', load_prices=True, num_workers_transactions=1000, asynchronous=False)[source]
Initialize a Portfolio instance.
- Parameters:
addresses (str | HexBytes | AnyAddress | EthAddress | Iterable[str | HexBytes | AnyAddress | EthAddress]) – The addresses to include in the portfolio.
start_block (int)
label (str)
load_prices (bool)
num_workers_transactions (int)
asynchronous (bool)
- Return type:
None
Examples
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> print(portfolio)
- __iter__()[source]
Iterate over the
PortfolioAddress
objects.- Returns:
An iterator over
PortfolioAddress
objects.- Return type:
Iterator[PortfolioAddress]
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> for address in portfolio: ... print(address)
- received(start_block=None, end_block=None)[source]
- Parameters:
- Return type:
AsyncIterator[Transaction | InternalTransfer | TokenTransfer]
- sent(start_block=None, end_block=None)[source]
- Parameters:
- Return type:
AsyncIterator[Transaction | InternalTransfer | TokenTransfer]
- _start_block = 0
The starting block number. Defaults to 0.
- addresses
A container for the
Portfolio
’sPortfolioAddress
objects.- Type:
PortfolioWallets
Works like a
Dict[Address, PortfolioAddress]
except you get the values when you iterate instead of the keys.
- describe[source]
Returns a full snapshot of your portfolio at a given block.
- Parameters:
block (int) – The block number.
- Returns:
A snapshot of the portfolio balances.
- Return type:
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> balances = await portfolio.describe(block=1200000) >>> print(balances)
- property internal_transfers: PortfolioInternalTransfersLedger[_T]
A container for all internal transfers to or from any of your
PortfolioAddress
.- Returns:
The
PortfolioInternalTransfersLedger
object.- Return type:
PortfolioInternalTransfersLedger
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> internal_transfers = portfolio.internal_transfers >>> print(internal_transfers)
- ledger
A container for all of your fun taxable events.
- Type:
PortfolioLedger
- property token_transfers: PortfolioTokenTransfersLedger[_T]
A container for all token transfers to or from any of your
PortfolioAddress
.- Returns:
The
PortfolioTokenTransfersLedger
object.- Return type:
PortfolioTokenTransfersLedger
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> token_transfers = portfolio.token_transfers >>> print(token_transfers)
- property transactions: PortfolioTransactionsLedger[_T]
A container for all transactions to or from any of your
PortfolioAddress
.- Returns:
The
PortfolioTransactionsLedger
object.- Return type:
PortfolioTransactionsLedger
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> transactions = portfolio.transactions >>> print(transactions)
- class eth_portfolio.portfolio.PortfolioLedger[source]
Bases:
_LedgeredBase
A container for all transactions, internal transfers, and token transfers to or from any of the wallets in your
Portfolio
.When awaited, a list of all
T
objects will be returned.Example
>>> my_object = PortfolioLedger(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], _LT) True
- __aiter__()
Return an async iterator that yields {obj} from the {cls}.
- Return type:
AsyncIterator[_T]
- __getitem__(slice)
- Parameters:
slice (slice)
- Return type:
ASyncIterator[_T][_T]
- __iter__()
Return an iterator that yields {obj} from the {cls}.
Note
Synchronous iteration leverages
ASyncIterator
, which usesasyncio.BaseEventLoop.run_until_complete()
to fetch items.ASyncIterator.__next__()
raises aSyncModeInAsyncContextError
if the event loop is already running.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.
- filter(self, function: ViewFn[T])
Filters the
T
objects yielded by the ASyncIterator[T] based on a function.- Parameters:
function (ViewFn[T]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filteredT
objects from the ASyncIterator[T].
- received(start_block=None, end_block=None)[source]
- Parameters:
- Return type:
AsyncIterator[Transaction | InternalTransfer | TokenTransfer]
- sent(start_block=None, end_block=None)[source]
- Parameters:
- Return type:
AsyncIterator[Transaction | InternalTransfer | TokenTransfer]
- sort(self, key: SortKey[T] = None, reverse: bool = False)
Sort the
T
objects yielded by the ASyncIterator[T].- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield theT
objects yielded from this ASyncIterator[T], but sorted.
- yield_forever()
- Return type:
ASyncIterator[_T][_T]
- property _ledgers: Tuple[_LT, _LT, _LT]
An iterator with the 3 ledgers (transactions, internal transfers, token transfers)
- all_entries[source]
Returns a mapping containing all transactions, internal transfers, and token transfers to or from each wallet in your portfolio.
- Parameters:
- Returns:
A dictionary mapping
PortfolioAddress
to their ledger entries.- Return type:
Dict[PortfolioAddress, Dict[str, PandableLedgerEntryList]]
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> entries = await portfolio.ledger.all_entries(start_block=1000000, end_block=1100000) >>> print(entries)
- asynchronous
True if default mode is async, False if sync.
- df[source]
Returns a DataFrame containing all transactions, internal transfers, and token transfers to or from any wallet in your portfolio.
- Parameters:
- Returns:
A DataFrame with the ledger entries.
- Return type:
DataFrame
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> df = await portfolio.ledger.df(start_block=1000000, end_block=1100000) >>> print(df)
- internal_transfers: _LT
A container for all internal transfers to or from any of your
PortfolioAddress
.
- materialized
List[T]
Synchronously iterate through the {cls} and return all {obj}.
- Returns:
A list of the {obj} yielded by the {cls}.
- Type:
_AwaitableAsyncIterableMixin.materialized
- token_transfers: _LT
A container for all token transfers to or from any of your
PortfolioAddress
.
- transactions: _LT
A container for all transactions to or from any of your
PortfolioAddress
.
- class eth_portfolio.portfolio.PortfolioWallets[source]
Bases:
Iterable
[PortfolioAddress
],Dict
[str
|HexBytes
|AnyAddress
|EthAddress
,PortfolioAddress
]A container that holds all
PortfolioAddress
objects for a specificPortfolio
.Works like a
Dict[Address, PortfolioAddress]
except when you iterate you get the values instead of the keys. You should not initialize these. They are created automatically duringPortfolio
initialization.- _wallets
A checksummed dictionary of
PortfolioAddress
objects.- Type:
checksum_dict.base.ChecksumAddressDict[eth_portfolio.address.PortfolioAddress[eth_portfolio.typing._T]]
- __getitem__(address)[source]
Get the
PortfolioAddress
object for a given address.- Parameters:
address (str | HexBytes | AnyAddress | EthAddress) – The address to look up.
- Returns:
The
PortfolioAddress
object.- Return type:
- __init__(addresses, start_block, load_prices, num_workers_transactions)[source]
Initialize a PortfolioWallets instance.
- __iter__()[source]
Iterate over the
PortfolioAddress
objects in the wallets.- Returns:
An iterator over
PortfolioAddress
objects.- Return type:
Iterator[PortfolioAddress]
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()[source]
Get the items (address,
PortfolioAddress
pairs) of the wallets.- Returns:
An iterable of (address,
PortfolioAddress
) tuples.- Return type:
Iterable[Tuple[Address, PortfolioAddress]]
- keys()[source]
Get the keys (addresses) of the wallets.
- Returns:
An iterable of addresses.
- Return type:
Iterable[Address]
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- values()[source]
Get the values (
PortfolioAddress
objects) of the wallets.- Returns:
An iterable of
PortfolioAddress
objects.- Return type:
Iterable[PortfolioAddress]
- _wallets: ChecksumAddressDict[PortfolioAddress[_T]]
A checksummed dictionary of
PortfolioAddress
objects.- Type:
ChecksumAddressDict[PortfolioAddress]
Module contents
- class eth_portfolio.Portfolio[source]
Bases:
ASyncGenericBase
Used to export information about a group of
PortfolioAddress
objects.Has all attributes of a
PortfolioAddress
.All calls to function(*args, **kwargs) will return {address: PortfolioAddress(Address).function(*args, **kwargs)}
- __getitem__(key)[source]
Get a
PortfolioAddress
by its key.- Parameters:
key (str | HexBytes | AnyAddress | EthAddress) – The address key.
- Returns:
The
PortfolioAddress
object.- Return type:
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> address = portfolio["0xAddress1"] >>> print(address)
- __init__(addresses, start_block=0, label='your portfolio', load_prices=True, num_workers_transactions=1000, asynchronous=False)[source]
Initialize a Portfolio instance.
- Parameters:
addresses (str | HexBytes | AnyAddress | EthAddress | Iterable[str | HexBytes | AnyAddress | EthAddress]) – The addresses to include in the portfolio.
start_block (int)
label (str)
load_prices (bool)
num_workers_transactions (int)
asynchronous (bool)
- Return type:
None
Examples
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> print(portfolio)
- __iter__()[source]
Iterate over the
PortfolioAddress
objects.- Returns:
An iterator over
PortfolioAddress
objects.- Return type:
Iterator[PortfolioAddress]
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> for address in portfolio: ... print(address)
- received(start_block=None, end_block=None)[source]
- Parameters:
- Return type:
AsyncIterator[Transaction | InternalTransfer | TokenTransfer]
- sent(start_block=None, end_block=None)[source]
- Parameters:
- Return type:
AsyncIterator[Transaction | InternalTransfer | TokenTransfer]
- _start_block = 0
The starting block number. Defaults to 0.
- addresses
A container for the
Portfolio
’sPortfolioAddress
objects.- Type:
PortfolioWallets
Works like a
Dict[Address, PortfolioAddress]
except you get the values when you iterate instead of the keys.
- describe[source]
Returns a full snapshot of your portfolio at a given block.
- Parameters:
block (int) – The block number.
- Returns:
A snapshot of the portfolio balances.
- Return type:
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> balances = await portfolio.describe(block=1200000) >>> print(balances)
- property internal_transfers: PortfolioInternalTransfersLedger[_T]
A container for all internal transfers to or from any of your
PortfolioAddress
.- Returns:
The
PortfolioInternalTransfersLedger
object.- Return type:
PortfolioInternalTransfersLedger
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> internal_transfers = portfolio.internal_transfers >>> print(internal_transfers)
- ledger
A container for all of your fun taxable events.
- Type:
PortfolioLedger
- property token_transfers: PortfolioTokenTransfersLedger[_T]
A container for all token transfers to or from any of your
PortfolioAddress
.- Returns:
The
PortfolioTokenTransfersLedger
object.- Return type:
PortfolioTokenTransfersLedger
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> token_transfers = portfolio.token_transfers >>> print(token_transfers)
- property transactions: PortfolioTransactionsLedger[_T]
A container for all transactions to or from any of your
PortfolioAddress
.- Returns:
The
PortfolioTransactionsLedger
object.- Return type:
PortfolioTransactionsLedger
Example
>>> portfolio = Portfolio(addresses=["0xAddress1", "0xAddress2"]) >>> transactions = portfolio.transactions >>> print(transactions)