From 1c9761e559e49655b1c5301f26344a3675cd5fce Mon Sep 17 00:00:00 2001 From: counterweight Date: Mon, 22 Dec 2025 16:07:33 +0100 Subject: [PATCH] feat: add explicit 30 second timeout for Bitfinex API requests Previously used httpx's implicit default (5 seconds). Explicit timeout makes behavior clear and gives more time for slow responses. --- backend/price_fetcher.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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()