diff --git a/backend/price_fetcher.py b/backend/price_fetcher.py index 52f0a05..00ae462 100644 --- a/backend/price_fetcher.py +++ b/backend/price_fetcher.py @@ -6,6 +6,7 @@ import httpx BITFINEX_TICKER_URL = "https://api-pub.bitfinex.com/v2/ticker/tBTCEUR" LAST_PRICE_INDEX = 6 +REQUEST_TIMEOUT_SECONDS = 30.0 # Constants for price history records SOURCE_BITFINEX = "bitfinex" @@ -21,10 +22,10 @@ async def fetch_btc_eur_price() -> tuple[float, datetime]: Raises: httpx.HTTPStatusError: If the API returns a non-2xx status code. - httpx.RequestError: If a network error occurs. + httpx.RequestError: If a network error occurs (including timeout). ValueError: If the response format is unexpected. """ - async with httpx.AsyncClient() as client: + async with httpx.AsyncClient(timeout=REQUEST_TIMEOUT_SECONDS) as client: response = await client.get(BITFINEX_TICKER_URL) response.raise_for_status()