diff --git a/backend/api/routes/account.py b/backend/api/routes/account.py index b600e6d..6890e24 100644 --- a/backend/api/routes/account.py +++ b/backend/api/routes/account.py @@ -269,7 +269,14 @@ async def ensure_all_positions_sltp(limit: int = Query(50, ge=1, le=200, descrip for sym in symbols: try: res = await _ensure_exchange_sltp_for_symbol(sym) - results.append({"symbol": sym, "ok": True, "orders": res.get("orders")}) + results.append( + { + "symbol": sym, + "ok": True, + "orders": res.get("orders"), + "open_protection_orders": res.get("open_protection_orders"), + } + ) except Exception as e: errors.append({"symbol": sym, "ok": False, "error": str(e)}) diff --git a/frontend/src/components/StatsDashboard.jsx b/frontend/src/components/StatsDashboard.jsx index ca1b53f..68f5624 100644 --- a/frontend/src/components/StatsDashboard.jsx +++ b/frontend/src/components/StatsDashboard.jsx @@ -9,6 +9,7 @@ const StatsDashboard = () => { const [closingSymbol, setClosingSymbol] = useState(null) const [sltpSymbol, setSltpSymbol] = useState(null) const [sltpAllBusy, setSltpAllBusy] = useState(false) + const [sltpDebugText, setSltpDebugText] = useState('') const [message, setMessage] = useState('') const [tradingConfig, setTradingConfig] = useState(null) @@ -113,12 +114,14 @@ const StatsDashboard = () => { } setSltpSymbol(symbol) setMessage('') + setSltpDebugText('') try { const res = await api.ensurePositionSLTP(symbol) const slId = res?.orders?.stop_market?.orderId const tpId = res?.orders?.take_profit_market?.orderId const cnt = Array.isArray(res?.open_protection_orders) ? res.open_protection_orders.length : 0 - setMessage(`${symbol} 已补挂保护单:SL=${slId || '-'} / TP=${tpId || '-'}(币安条件单可见,当前检测到保护单 ${cnt} 条)`) + setMessage(`${symbol} 已尝试补挂:SL=${slId || '-'} / TP=${tpId || '-'}(当前检测到保护单 ${cnt} 条)`) + setSltpDebugText(JSON.stringify(res || {}, null, 2)) await loadDashboard() } catch (error) { setMessage(`补挂失败 ${symbol}: ${error.message || '未知错误'}`) @@ -134,11 +137,20 @@ const StatsDashboard = () => { } setSltpAllBusy(true) setMessage('') + setSltpDebugText('') try { const res = await api.ensureAllPositionsSLTP(50) const ok = res?.ok ?? 0 const failed = res?.failed ?? 0 - setMessage(`一键补挂完成:成功 ${ok} / 失败 ${failed}(请在币安【条件单/止盈止损】里查看)`) + let openCnt = 0 + try { + const arr = Array.isArray(res?.results) ? res.results : [] + openCnt = arr.reduce((acc, it) => acc + (Array.isArray(it?.open_protection_orders) ? it.open_protection_orders.length : 0), 0) + } catch (e) { + openCnt = 0 + } + setMessage(`一键补挂完成:成功 ${ok} / 失败 ${failed}(检测到保护单 ${openCnt} 条)`) + setSltpDebugText(JSON.stringify(res || {}, null, 2)) await loadDashboard() } catch (error) { setMessage(`一键补挂失败: ${error.message || '未知错误'}`) @@ -227,6 +239,14 @@ const StatsDashboard = () => { {message && (
{message} + {sltpDebugText ? ( +
+ 查看补挂返回详情(用于排查) +
+{sltpDebugText}
+              
+
+ ) : null}
)}