diff --git a/backend/main.py b/backend/main.py index 2d29371..4c42912 100644 --- a/backend/main.py +++ b/backend/main.py @@ -568,8 +568,20 @@ async def paper_positions(user: dict = Depends(get_current_user)): "tp1_price, tp2_price, sl_price, tp1_hit, status, atr_at_entry " "FROM paper_trades WHERE status IN ('active','tp1_hit') ORDER BY entry_ts DESC" ) - # 获取实时价格 + # 从币安API获取实时价格 prices = {} + symbols_needed = list(set(r["symbol"] for r in rows)) + if symbols_needed: + try: + async with httpx.AsyncClient(timeout=5) as client: + resp = await client.get("https://fapi.binance.com/fapi/v1/ticker/price") + if resp.status_code == 200: + for item in resp.json(): + if item["symbol"] in symbols_needed: + prices[item["symbol"]] = float(item["price"]) + except Exception: + pass + # fallback: 如果币安API失败,用signal_indicators for r in rows: sym = r["symbol"] if sym not in prices: