Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch and log HTTPError exceptions accessing CoinGecko API. #33

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyth_observer/coingecko.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import os

from loguru import logger
from pycoingecko import CoinGeckoAPI
from requests.exceptions import HTTPError

from throttler import throttle

Expand Down Expand Up @@ -30,7 +32,12 @@ def get_coingecko_symbol_to_id_mapping():
@throttle(rate_limit=1, period=60)
async def get_coingecko_prices(symbols):
ids = [symbol_to_id_mapping[x]["api"] for x in symbol_to_id_mapping if x in symbols]
prices = cg.get_price(ids=ids, vs_currencies="usd", include_last_updated_at=True)
try:
prices = cg.get_price(ids=ids, vs_currencies="usd", include_last_updated_at=True)
except HTTPError as exc:
logger.exception(exc)
logger.error("CoinGecko API call failed - CoinGecko price comparisons not available.")
prices = {}
# remap to symbol -> prices
prices_mapping = {api_to_symbol_mapping[x]: prices[x] for x in prices}
return prices_mapping
Expand Down