diff --git a/src/constants.py b/src/constants.py index 215f8ca..4a8276a 100644 --- a/src/constants.py +++ b/src/constants.py @@ -22,6 +22,7 @@ NULL_ADDRESS_STRING = "0x0000000000000000000000000000000000000000" REQUEST_TIMEOUT = 5 +API_NUM_OF_RETRIES = 5 # Time limit, currently set to 1 full day, after which Coingecko Token List is re-fetched (in seconds) COINGECKO_TOKEN_LIST_RELOAD_TIME = 86400 diff --git a/src/fees/compute_fees.py b/src/fees/compute_fees.py index c1b7391..e69455e 100644 --- a/src/fees/compute_fees.py +++ b/src/fees/compute_fees.py @@ -13,7 +13,7 @@ from hexbytes import HexBytes from web3 import Web3 -from src.constants import REQUEST_TIMEOUT, NULL_ADDRESS +from src.constants import REQUEST_TIMEOUT, NULL_ADDRESS, API_NUM_OF_RETRIES # types for trades @@ -405,21 +405,24 @@ def get_all_data(self, tx_hash: HexBytes) -> SettlementData: return settlement_data def get_auction_data(self, tx_hash: HexBytes): - for environment, url in self.orderbook_urls.items(): - try: - response = requests.get( - url + f"solver_competition/by_tx_hash/{tx_hash.to_0x_hex()}", - timeout=REQUEST_TIMEOUT, - ) - response.raise_for_status() - auction_data = response.json() - sleep(0.5) # introducing some delays so that we don't overload the api - return auction_data, environment - except requests.exceptions.HTTPError as err: - if err.response.status_code == 404: - pass + for i in range(API_NUM_OF_RETRIES): + for environment, url in self.orderbook_urls.items(): + try: + response = requests.get( + url + f"solver_competition/by_tx_hash/{tx_hash.to_0x_hex()}", + timeout=REQUEST_TIMEOUT, + ) + sleep( + 0.5 + ) # introducing some delays so that we don't overload the api + response.raise_for_status() + auction_data = response.json() + return auction_data, environment + except requests.exceptions.HTTPError as err: + if err.response.status_code == 404: + pass raise ConnectionError( - f"Error fetching off-chain data for tx {tx_hash.to_0x_hex()}" + f"Error fetching api auction data for tx {tx_hash.to_0x_hex()}" ) def get_order_data(self, uid: HexBytes, environment: str):