Skip to content

Commit

Permalink
Merge pull request #41 from cowprotocol/price-handling
Browse files Browse the repository at this point in the history
Slightly clearer exception handling for prices
  • Loading branch information
harisang authored Aug 28, 2024
2 parents 4dec721 + 1731c50 commit a6eef14
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/price_providers/coingecko_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/price_providers/dune_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
9 changes: 7 additions & 2 deletions src/price_providers/endpoint_auction_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,8 +44,12 @@ 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
unchecked_endpoints_count -= 1
# Continue to check if tx present on barn.
if err.response.status_code == 404 and unchecked_endpoints_count != 0:
continue
# 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}")
except KeyError as key_err:
Expand Down
2 changes: 1 addition & 1 deletion src/price_providers/moralis_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a6eef14

Please sign in to comment.