Really-amin commited on
Commit
3185dca
·
verified ·
1 Parent(s): 826bf9f

fix: indicators use trading service OHLCV with geo bypass

Browse files
Files changed (1) hide show
  1. backend/routers/indicators_api.py +17 -25
backend/routers/indicators_api.py CHANGED
@@ -1427,35 +1427,27 @@ async def get_comprehensive_analysis(
1427
  prices_data = ohlcv.get("prices") if isinstance(ohlcv, dict) else None
1428
  if not prices_data:
1429
  candles = None
 
1430
  try:
1431
- from backend.services.binance_client import binance_client
1432
- candles = await binance_client.get_ohlcv(base_symbol, timeframe=timeframe, limit=200)
1433
- except Exception as client_err:
1434
- logger.warning(f"Binance client import/fetch failed for {base_symbol}: {client_err}")
 
 
 
 
 
 
 
 
1435
 
1436
  if not candles:
1437
  try:
1438
- pair = base_symbol if base_symbol.endswith("USDT") else f"{base_symbol}USDT"
1439
- interval = {"1m": "1m", "5m": "5m", "15m": "15m", "1h": "1h", "4h": "4h", "1d": "1d"}.get(timeframe, "1h")
1440
- async with httpx.AsyncClient(timeout=12.0) as client:
1441
- response = await client.get(
1442
- "https://api.binance.com/api/v3/klines",
1443
- params={"symbol": pair, "interval": interval, "limit": 200},
1444
- )
1445
- response.raise_for_status()
1446
- candles = [
1447
- {
1448
- "open": float(k[1]),
1449
- "high": float(k[2]),
1450
- "low": float(k[3]),
1451
- "close": float(k[4]),
1452
- "volume": float(k[5]),
1453
- }
1454
- for k in response.json()
1455
- if float(k[4]) > 0
1456
- ]
1457
- except Exception as direct_err:
1458
- logger.warning(f"Direct Binance klines failed for {base_symbol}: {direct_err}")
1459
 
1460
  if candles:
1461
  prices = [float(c["close"]) for c in candles]
 
1427
  prices_data = ohlcv.get("prices") if isinstance(ohlcv, dict) else None
1428
  if not prices_data:
1429
  candles = None
1430
+ pair = base_symbol if base_symbol.endswith("USDT") else f"{base_symbol}USDT"
1431
  try:
1432
+ from backend.services.trading_backtesting_service import get_trading_service
1433
+ trading = get_trading_service(enable_proxy=False)
1434
+ ohlcv_result = await trading.get_trading_ohlcv(
1435
+ symbol=pair,
1436
+ timeframe=timeframe,
1437
+ limit=200,
1438
+ exchange="binance",
1439
+ )
1440
+ if ohlcv_result.get("success"):
1441
+ candles = ohlcv_result.get("candles") or []
1442
+ except Exception as trading_err:
1443
+ logger.warning(f"Trading service OHLCV failed for {pair}: {trading_err}")
1444
 
1445
  if not candles:
1446
  try:
1447
+ from backend.services.binance_client import binance_client
1448
+ candles = await binance_client.get_ohlcv(pair, timeframe=timeframe, limit=200)
1449
+ except Exception as client_err:
1450
+ logger.warning(f"Binance client fallback failed for {pair}: {client_err}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1451
 
1452
  if candles:
1453
  prices = [float(c["close"]) for c in candles]