diff --git a/koios_python/__pycache__/account.cpython-310.pyc b/koios_python/__pycache__/account.cpython-310.pyc index 4c93d12..3afaf47 100644 Binary files a/koios_python/__pycache__/account.cpython-310.pyc and b/koios_python/__pycache__/account.cpython-310.pyc differ diff --git a/koios_python/__pycache__/environment.cpython-310.pyc b/koios_python/__pycache__/environment.cpython-310.pyc index 507b170..e4d427e 100644 Binary files a/koios_python/__pycache__/environment.cpython-310.pyc and b/koios_python/__pycache__/environment.cpython-310.pyc differ diff --git a/koios_python/__pycache__/network.cpython-310.pyc b/koios_python/__pycache__/network.cpython-310.pyc index 5563a03..16b1ddc 100644 Binary files a/koios_python/__pycache__/network.cpython-310.pyc and b/koios_python/__pycache__/network.cpython-310.pyc differ diff --git a/koios_python/__pycache__/urls.cpython-310.pyc b/koios_python/__pycache__/urls.cpython-310.pyc index 5bf40af..17ea15a 100644 Binary files a/koios_python/__pycache__/urls.cpython-310.pyc and b/koios_python/__pycache__/urls.cpython-310.pyc differ diff --git a/koios_python/account.py b/koios_python/account.py index fce1bac..6b79da3 100644 --- a/koios_python/account.py +++ b/koios_python/account.py @@ -186,6 +186,44 @@ def get_account_addresses(self, *args): def get_account_assets(self, *args): + """ + Get the native asset balance of given accounts. + :param str args: staking address/es in bech32 format (stake1...) + :return: list with all account assets. + :rtype: list. + """ + timeout = BASE_TIMEOUT + retriyng_time = RETRYING_TIME + + while True: + try: + get_format = {"_stake_addresses": [args]} + assets = requests.post(self.ACCOUNT_ASSETS_URL, json= get_format, timeout=timeout) + assets = json.loads(assets.content) + break + + except requests.exceptions.ReadTimeout as timeout_error: + print(f"Exception: {timeout_error}") + if timeout < LIMIT_TIMEOUT: + timeout= timeout + 10 + else: + print(f"Reach Limit Timeout= {LIMIT_TIMEOUT} seconds") + break + print(f"Retriyng with longer timeout: Total Timeout= {timeout}s") + + except json.decoder.JSONDecodeError as decode_error: + print(f"Exception Decode: Payload too heavy. {decode_error}") + sleep(SLEEP_TIME) + retriyng_time += 1 + print(f"Retriyng one more time...({retriyng_time} times)") + if retriyng_time >= LIMIT_RETRYING_TIMES: + print("Reached limit of attempts") + break + + return assets + +## Alternative to Paginate all list automately +def get_account_assets_2(self, *args): """ Get the native asset balance of given accounts. :param str args: staking address/es in bech32 format (stake1...) @@ -217,8 +255,8 @@ def get_account_assets(self, *args): except json.decoder.JSONDecodeError as decode_error: print(f"Exception Decode: Payload too heavy. {decode_error}") sleep(SLEEP_TIME) - print(f"Retriyng one more time...({retriyng_time} time/s)") retriyng_time += 1 + print(f"Retriyng one more time...({retriyng_time} times)") if retriyng_time >= LIMIT_RETRYING_TIMES: print("Reached limit of attempts") break diff --git a/koios_python/environment.py b/koios_python/environment.py index d1db3c8..e43b79b 100644 --- a/koios_python/environment.py +++ b/koios_python/environment.py @@ -9,7 +9,7 @@ SLEEP_TIME= 10 OFFSET= 0 RETRYING_TIME= 1 -LIMIT_RETRYING_TIMES= 7 +LIMIT_RETRYING_TIMES= 10 # Exceptions Functions def handle_timeout_exceptions(timeout, timeout_error): diff --git a/koios_python/network.py b/koios_python/network.py index 19359fe..e5cbbd5 100644 --- a/koios_python/network.py +++ b/koios_python/network.py @@ -74,7 +74,7 @@ def get_totals(self, epoch_no=None): while True: try: if epoch_no is None: - totals = requests.get(self.TOTALS_URL, timeout=10) + totals = requests.get(self.TOTALS_URL, timeout=timeout) totals = json.loads(totals.content) else: totals = requests.get(f"{self.TOTALS_URL}?_epoch_no={epoch_no}", timeout=timeout) diff --git a/koios_python/urls.py b/koios_python/urls.py index caee6eb..a3b28af 100644 --- a/koios_python/urls.py +++ b/koios_python/urls.py @@ -9,7 +9,7 @@ class URLs: from .network import get_tip, get_genesis, get_totals from .block import get_blocks, get_block_info, get_block_txs from .address import get_address_info, get_address_txs, get_address_assets, get_credential_txs - from .account import get_account_info, get_account_info_cached, get_account_list, get_account_rewards, get_account_updates, get_account_addresses, get_account_assets, get_account_history + from .account import get_account_info, get_account_info_cached, get_account_list, get_account_rewards, get_account_updates, get_account_addresses, get_account_assets, get_account_history, get_account_assets_2 from .asset import get_asset_list, get_asset_address_list, get_asset_info, get_asset_history, get_asset_policy_info, get_asset_summary, get_asset_txs from .pool import get_pool_list, get_pool_info, get_pool_stake_snapshot, get_pool_delegators, get_pool_delegators_history, get_pool_blocks, get_pool_history, get_pool_updates, get_pool_relays, get_pool_metadata from .scripts import get_native_script_list, get_plutus_script_list, get_script_redeemers, get_datum_info @@ -62,7 +62,8 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.ACCOUNT_REWARDS_URL = self.url + "account_rewards" self.ACCOUNT_UPDATES_URL = self.url + "account_updates" self.ACCOUNT_ADDRESSES_URL = self.url + "account_addresses" - self.ACCOUNT_ASSETS_URL = self.url + "account_assets?offset=" + #self.ACCOUNT_ASSETS_URL = self.url + "account_assets?offset=" + self.ACCOUNT_ASSETS_URL = self.url + "account_assets" self.ACCOUNT_HISTORY_URL = self.url + "account_history" # Asset URLs self.ASSET_LIST_URL = self.url + "asset_list"