mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-07-22 12:22:20 +00:00
Compare commits
4 Commits
litellm
...
cost-calcu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f160384e14 | ||
|
|
4ee6801413 | ||
|
|
e4153920a9 | ||
|
|
1b4e092242 |
@@ -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}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user