From 15fd23fdf06dccb49ffb5463babacde0deb87f27 Mon Sep 17 00:00:00 2001 From: Shubh Agarwal Date: Fri, 23 Aug 2024 02:05:42 -0400 Subject: [PATCH 1/2] price exception handling --- src/price_providers/coingecko_pricing.py | 4 ++-- src/price_providers/dune_pricing.py | 1 + src/price_providers/endpoint_auction_pricing.py | 7 +++++-- src/price_providers/moralis_pricing.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/price_providers/coingecko_pricing.py b/src/price_providers/coingecko_pricing.py index e6dac7b..f296180 100644 --- a/src/price_providers/coingecko_pricing.py +++ b/src/price_providers/coingecko_pricing.py @@ -153,10 +153,10 @@ def get_price(self, price_params: dict) -> float | None: token_id, block_start_timestamp, block_end_timestamp ) if api_price is None: - logger.warning(f"API returned None for token ID: {token_id}") + logger.warning(f"Coingecko API returned None for token ID: {token_id}") return None except requests.RequestException as e: - logger.error(f"Error fetching price from API: {e}") + logger.error(f"Error fetching price from Coingecko API: {e}") return None return api_price diff --git a/src/price_providers/dune_pricing.py b/src/price_providers/dune_pricing.py index 3e27b3a..5954ec0 100644 --- a/src/price_providers/dune_pricing.py +++ b/src/price_providers/dune_pricing.py @@ -70,6 +70,7 @@ def get_price(self, price_params: dict) -> float | None: if price is not None: return price # No valid price found + self.logger.warning("Price not found on Dune.") return None except KeyError as e: self.logger.error(f"Key error occurred: {e}") diff --git a/src/price_providers/endpoint_auction_pricing.py b/src/price_providers/endpoint_auction_pricing.py index 8cc31ff..2d1fb53 100644 --- a/src/price_providers/endpoint_auction_pricing.py +++ b/src/price_providers/endpoint_auction_pricing.py @@ -43,8 +43,11 @@ def get_price(self, price_params: dict) -> float | None: return price_in_eth except requests.exceptions.HTTPError as err: - if err.response.status_code == 404: - pass + # Continue to check if tx present on barn. + if err.response.status_code == 404 and environment == "prod": + continue + # Error logged if tx not found on barn either. + logger.error(f"Error: {err}") except requests.exceptions.RequestException as req_err: logger.error(f"Error occurred during request: {req_err}") except KeyError as key_err: diff --git a/src/price_providers/moralis_pricing.py b/src/price_providers/moralis_pricing.py index ba2fb9c..9cdd968 100644 --- a/src/price_providers/moralis_pricing.py +++ b/src/price_providers/moralis_pricing.py @@ -53,6 +53,6 @@ def get_price(self, price_params: dict) -> float | None: self.logger.warning(f"Error: {e}") except Exception as e: self.logger.warning( - f"Error: {e}, Likely the token: {token_address} was not found or API limit reached." + f"Price retrieval for token: {token_address} returned: {e}" ) return None From 1731c504c5ae6f19e0be777a3ec5503b58ff3cb6 Mon Sep 17 00:00:00 2001 From: Shubh Agarwal Date: Fri, 23 Aug 2024 19:59:29 -0400 Subject: [PATCH 2/2] addressed comment --- src/price_providers/endpoint_auction_pricing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/price_providers/endpoint_auction_pricing.py b/src/price_providers/endpoint_auction_pricing.py index 2d1fb53..f525bee 100644 --- a/src/price_providers/endpoint_auction_pricing.py +++ b/src/price_providers/endpoint_auction_pricing.py @@ -20,6 +20,7 @@ def name(self) -> str: def get_price(self, price_params: dict) -> float | None: """Function returns Auction price from endpoint for a token address.""" token_address, tx_hash = extract_params(price_params, is_block=False) + unchecked_endpoints_count = len(self.endpoint_urls) for environment, url in self.endpoint_urls.items(): try: # append tx_hash to endpoint @@ -43,10 +44,11 @@ def get_price(self, price_params: dict) -> float | None: return price_in_eth except requests.exceptions.HTTPError as err: + unchecked_endpoints_count -= 1 # Continue to check if tx present on barn. - if err.response.status_code == 404 and environment == "prod": + if err.response.status_code == 404 and unchecked_endpoints_count != 0: continue - # Error logged if tx not found on barn either. + # Error logged for the last endpoint in the list (expected: barn) logger.error(f"Error: {err}") except requests.exceptions.RequestException as req_err: logger.error(f"Error occurred during request: {req_err}")