fix bug: when same symbal and same code and same name create html report will can not open the on collection, add symbal code name and group name to unique id (当同一股票在不通分组,生成出来的html报告只能展开一个报告)

This commit is contained in:
guopengfa
2026-01-18 18:55:41 +08:00
parent b07ed7a9ee
commit cf4ce60ba5
@@ -91,7 +91,7 @@ def _get_positions_for_monitor(position_ids: List[int] = None, user_id: int = No
placeholders = ','.join(['?' for _ in position_ids]) placeholders = ','.join(['?' for _ in position_ids])
cur.execute( cur.execute(
f""" f"""
SELECT id, market, symbol, name, side, quantity, entry_price SELECT id, market, symbol, name, side, quantity, entry_price, group_name
FROM qd_manual_positions FROM qd_manual_positions
WHERE user_id = ? AND id IN ({placeholders}) WHERE user_id = ? AND id IN ({placeholders})
""", """,
@@ -100,7 +100,7 @@ def _get_positions_for_monitor(position_ids: List[int] = None, user_id: int = No
else: else:
cur.execute( cur.execute(
""" """
SELECT id, market, symbol, name, side, quantity, entry_price SELECT id, market, symbol, name, side, quantity, entry_price, group_name
FROM qd_manual_positions FROM qd_manual_positions
WHERE user_id = ? WHERE user_id = ?
""", """,
@@ -115,7 +115,8 @@ def _get_positions_for_monitor(position_ids: List[int] = None, user_id: int = No
symbol = row.get('symbol') symbol = row.get('symbol')
entry_price = float(row.get('entry_price') or 0) entry_price = float(row.get('entry_price') or 0)
quantity = float(row.get('quantity') or 0) quantity = float(row.get('quantity') or 0)
side = row.get('side') or 'long' side = row.get('side') or 'long',
group_name = row.get('group_name')
# Get current price (use realtime price API) # Get current price (use realtime price API)
current_price = 0 current_price = 0
@@ -143,7 +144,8 @@ def _get_positions_for_monitor(position_ids: List[int] = None, user_id: int = No
'entry_price': entry_price, 'entry_price': entry_price,
'current_price': current_price, 'current_price': current_price,
'pnl': round(pnl, 2), 'pnl': round(pnl, 2),
'pnl_percent': pnl_percent 'pnl_percent': pnl_percent,
'group_name': group_name
}) })
return positions return positions
@@ -168,6 +170,7 @@ def _run_ai_analysis(positions: List[Dict[str, Any]], config: Dict[str, Any]) ->
market = pos.get('market') market = pos.get('market')
symbol = pos.get('symbol') symbol = pos.get('symbol')
name = pos.get('name') or symbol name = pos.get('name') or symbol
group_name = pos.get('group_name')
if not market or not symbol: if not market or not symbol:
continue continue
@@ -193,6 +196,7 @@ def _run_ai_analysis(positions: List[Dict[str, Any]], config: Dict[str, Any]) ->
'market': market, 'market': market,
'symbol': symbol, 'symbol': symbol,
'name': name, 'name': name,
'group_name': group_name,
'entry_price': pos.get('entry_price'), 'entry_price': pos.get('entry_price'),
'current_price': pos.get('current_price'), 'current_price': pos.get('current_price'),
'pnl': pos.get('pnl'), 'pnl': pos.get('pnl'),
@@ -454,6 +458,7 @@ def _build_html_report(
symbol = pa.get('symbol', '') symbol = pa.get('symbol', '')
name = pa.get('name', symbol) name = pa.get('name', symbol)
market = pa.get('market', '') market = pa.get('market', '')
group_name = pa.get('group_name', '')
if pa.get('error'): if pa.get('error'):
html += f''' html += f'''
@@ -538,7 +543,7 @@ def _build_html_report(
''' '''
# Generate unique ID for collapsible sections (use symbol hash to avoid special chars) # Generate unique ID for collapsible sections (use symbol hash to avoid special chars)
section_id_base = hashlib.md5(f"{symbol}_{market}".encode()).hexdigest()[:8] section_id_base = hashlib.md5(f"{symbol}_{market}_{group_name}".encode()).hexdigest()[:8]
# Collapsible: Trader Analysis # Collapsible: Trader Analysis
if trader_reasoning: if trader_reasoning: