diff --git a/.gitignore b/.gitignore index 8bbf9b5..34ea5c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env +.log __pycache__ .pytest_cache src/tempCodeRunnerFile.py diff --git a/slippage_project.log b/slippage_project.log deleted file mode 100644 index e69de29..0000000 diff --git a/src/price_providers/endpoint_auction_pricing.py b/src/price_providers/endpoint_auction_pricing.py index 5fbc116..8cc31ff 100644 --- a/src/price_providers/endpoint_auction_pricing.py +++ b/src/price_providers/endpoint_auction_pricing.py @@ -8,8 +8,9 @@ class AuctionPriceProvider(AbstractPriceProvider): """Fetch auction prices.""" def __init__(self) -> None: - self.endpoint_url = { - "prod": f"https://api.cow.fi/mainnet/api/v1/solver_competition/by_tx_hash/" + self.endpoint_urls = { + "prod": f"https://api.cow.fi/mainnet/api/v1/solver_competition/by_tx_hash/", + "barn": f"https://barn.api.cow.fi/mainnet/api/v1/solver_competition/by_tx_hash/", } @property @@ -19,32 +20,36 @@ 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) - url = self.endpoint_url["prod"] + tx_hash - try: - response = requests.get(url) - response.raise_for_status() - data = response.json() - - # Search for the token address in the auction prices - auction_prices = data.get("auction", {}).get("prices", {}) - price = auction_prices.get(token_address.lower()) - - if price is None: - logger.warning( - f"Price for token {token_address} not found in auction data." + for environment, url in self.endpoint_urls.items(): + try: + # append tx_hash to endpoint + response = requests.get(url + tx_hash) + response.raise_for_status() + data = response.json() + + # Search for the token address in the auction prices + auction_prices = data.get("auction", {}).get("prices", {}) + price = auction_prices.get(token_address.lower()) + + if price is None: + logger.warning( + f"Price for token {token_address} not found in auction data." + ) + return None + # calculation for converting auction price from endpoint to ETH equivalent per token unit + price_in_eth = (float(price) / 10**18) * ( + 10 ** get_token_decimals(token_address) / 10**18 ) - return None - # calculation for converting auction price from endpoint to ETH equivalent per token unit - price_in_eth = (float(price) / 10**18) * ( - 10 ** get_token_decimals(token_address) / 10**18 - ) - return price_in_eth - - except requests.exceptions.RequestException as req_err: - logger.error(f"Error occurred during request: {req_err}") - except KeyError as key_err: - logger.error(f"Key error: {key_err}") - except Exception as e: - logger.error(f"An unexpected error occurred: {e}") + return price_in_eth + + except requests.exceptions.HTTPError as err: + if err.response.status_code == 404: + pass + except requests.exceptions.RequestException as req_err: + logger.error(f"Error occurred during request: {req_err}") + except KeyError as key_err: + logger.error(f"Key error: {key_err}") + except Exception as e: + logger.error(f"An unexpected error occurred: {e}") return None