fix: gainers/losers binance fallback chain
Browse files117 unmodified lines11811912012112212350 unmodified lines174175176177178179117 unmodified linesreturn rowsasync def _fetch_markets_from_coinpaprika(limit: int) -> List[dict]:tickers = await fetch_from_coinpaprika("tickers")if not tickers:50 unmodified lineslogger.warning("CoinCap movers failed, trying CoinPaprika...")rows = await _fetch_markets_from_coinpaprika(limit)source = "coinpaprika"if not rows:raise HTTPException(status_code=503, detail="All market mover providers unavailable")117 unmodified lines11811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316450 unmodified lines215216217218219220221222223224117 unmodified linesreturn rowsasync def _fetch_markets_from_binance(limit: int) -> List[dict]:"""Binance 24h ticker — reliable fallback when aggregators rate-limit."""try:async with httpx.AsyncClient(timeout=12.0) as client:response = await client.get("https://api.binance.com/api/v3/ticker/24hr")response.raise_for_status()tickers = response.json()except Exception as e:logger.error(f"Binance movers error: {e}")return []rows: List[dict] = []for item in tickers:symbol = str(item.get("symbol", ""))if not symbol.endswith("USDT"):continuetry:change = float(item.get("priceChangePercent", 0))price = float(item.get("lastPrice", 0))volume = float(item.get("quoteVolume", 0))except (TypeError, ValueError):continueif price <= 0:continuebase = symbol[:-4]rows.append(_normalize_market_row({"id": base.lower(),"symbol": base,"name": base,"priceUsd": price,"changePercent24Hr": change,"volumeUsd24Hr": volume,},"binance",))return rows[: max(limit * 3, 100)]async def _fetch_markets_from_coinpaprika(limit: int) -> List[dict]:tickers = await fetch_from_coinpaprika("tickers")if not tickers:50 unmodified lineslogger.warning("CoinCap movers failed, trying CoinPaprika...")rows = await _fetch_markets_from_coinpaprika(limit)source = "coinpaprika"if not rows:logger.warning("CoinPaprika movers failed, trying Binance...")rows = await _fetch_markets_from_binance(limit)source = "binance"if not rows:raise HTTPException(status_code=503, detail="All market mover providers unavailable")
backend/routers/expanded_market_api.py+45