Compare commits

...

4 Commits

Author SHA1 Message Date
9qeklajc
f160384e14 price 2025-12-21 21:06:38 +01:00
9qeklajc
4ee6801413 price 2025-12-21 21:03:03 +01:00
9qeklajc
e4153920a9 price 2025-12-21 20:58:52 +01:00
9qeklajc
1b4e092242 add print 2025-12-21 12:33:14 +01:00
2 changed files with 18 additions and 4 deletions

View File

@@ -528,4 +528,5 @@ async def models(session: AsyncSession = Depends(get_session)) -> dict:
from ..proxy import get_unique_models
items = get_unique_models()
print(items)
return {"data": items}

View File

@@ -85,6 +85,7 @@ async def _fetch_btc_usd_price() -> float:
_binance_btc_usdt(client),
)
valid_prices = [price for price in prices if price is not None]
print(valid_prices)
if not valid_prices:
logger.error("No valid BTC prices obtained from any exchange")
raise ValueError("Unable to fetch BTC price from any exchange")
@@ -102,14 +103,26 @@ async def _update_prices() -> None:
global BTC_USD_PRICE, SATS_USD_PRICE
try:
btc_price = await _fetch_btc_usd_price()
BTC_USD_PRICE = btc_price
SATS_USD_PRICE = btc_price / 100_000_000
logger.info(
"Updated BTC/SATS prices successfully",
extra={"btc_usd": btc_price, "sats_usd": SATS_USD_PRICE},
)
except Exception as e:
logger.warning(
"Skipping price update; unable to fetch BTC price",
"Failed to fetch live prices, using fallback if available",
extra={"error": str(e), "error_type": type(e).__name__},
)
return
BTC_USD_PRICE = btc_price
SATS_USD_PRICE = btc_price / 100_000_000
# Use fallback price if no price is set
if BTC_USD_PRICE is None or SATS_USD_PRICE is None:
fallback_btc_price = getattr(settings, "fallback_btc_usd_price", 50000.0)
BTC_USD_PRICE = fallback_btc_price
SATS_USD_PRICE = fallback_btc_price / 100_000_000
logger.info(
"Using fallback BTC price",
extra={"fallback_btc_usd": fallback_btc_price, "sats_usd": SATS_USD_PRICE},
)
def btc_usd_price() -> float: