nectar.haf module
- class nectar.haf.HAF(api: str | None = None, blockchain_instance=None, timeout: float | None = None)
Bases:
objectHive Account Feed (HAF) API client for accessing Hive blockchain endpoints.
This class provides access to various Hive API endpoints that are not part of the standard RPC blockchain calls. It supports multiple API providers and handles reputation queries and other HAF-related data.
- Parameters:
api (str) – Base API URL to use for requests. Supported endpoints include: - ‘https://api.hive.blog’ (default) - ‘https://api.syncad.com’
blockchain_instance – Blockchain instance for compatibility with the nectar ecosystem
>>> from nectar.haf import HAF >>> haf = HAF() >>> reputation = haf.reputation("thecrazygm") >>> print(reputation)
- DEFAULT_APIS = ['https://api.hive.blog', 'https://api.syncad.com']
- get_account_balances(account: str) Dict[str, Any] | None
Get account balances from the balance API.
This method retrieves comprehensive balance information including HBD, HIVE, vesting shares, rewards, and other balance-related data for an account.
- Parameters:
account (str): Hive account name
- Returns:
dict or None: Account balance data or None if request fails
- Example:
>>> haf = HAF() >>> balances = haf.get_account_balances("thecrazygm") >>> print(balances['hive_balance'])
- get_account_delegations(account: str) Dict[str, Any] | None
Get account delegations from the balance API.
This method retrieves both incoming and outgoing delegations for an account.
- Parameters:
account (str): Hive account name
- Returns:
dict or None: Delegation data containing incoming and outgoing delegations
- Example:
>>> haf = HAF() >>> delegations = haf.get_account_delegations("thecrazygm") >>> print(delegations['incoming_delegations'])
- get_account_recurrent_transfers(account: str) Dict[str, Any] | None
Get account recurrent transfers from the balance API.
This method retrieves both incoming and outgoing recurrent transfers for an account.
- Parameters:
account (str): Hive account name
- Returns:
dict or None: Recurrent transfer data containing incoming and outgoing transfers
- Example:
>>> haf = HAF() >>> transfers = haf.get_account_recurrent_transfers("thecrazygm") >>> print(transfers['outgoing_recurrent_transfers'])
- get_available_apis() list[str]
Get the list of available API endpoints.
- Returns:
list: List of supported API URLs
- get_balance_last_synced_block() int | None
Get the last block number synced by the balance tracker.
- Returns:
int or None: Last synced block number or None if request fails
- Example:
>>> haf = HAF() >>> block = haf.get_balance_last_synced_block() >>> print(block)
- get_balance_version() str | None
Get the balance tracker’s version from the balance API.
- Returns:
str or None: Version string or None if request fails
- Example:
>>> haf = HAF() >>> version = haf.get_balance_version() >>> print(version)
- get_current_api() str
Get the currently active API endpoint.
- Returns:
str: Current API URL
- get_reputation_last_synced_block() int | None
Get the last block number synced by the reputation tracker.
- Returns:
int or None: Last synced block number or None if request fails
- Example:
>>> haf = HAF() >>> block = haf.get_reputation_last_synced_block() >>> print(block)
- get_reputation_version() str | None
Get the reputation tracker’s version from the reputation API.
- Returns:
str or None: Version string or None if request fails
- Example:
>>> haf = HAF() >>> version = haf.get_reputation_version() >>> print(version)
- reputation(account: str) Dict[str, Any] | None
Get reputation information for a Hive account.
This method queries the reputation API endpoint to retrieve the account’s reputation score and related metadata.
- Parameters:
account (str): Hive account name
- Returns:
- dict or None: Reputation data containing account information and reputation score,
or None if the request fails or account is not found
- Example:
>>> haf = HAF() >>> rep = haf.reputation("thecrazygm") >>> print(rep) {'account': 'thecrazygm', 'reputation': '71', ...}
- set_api(api: str) None
Change the API endpoint.
- Parameters:
api (str): New API URL to use
- Raises:
ValueError: If the API URL is invalid