fix: 自选Tab显示策略数据(买入区间/信号/策略)+live_prices涨跌

This commit is contained in:
知微
2026-07-09 19:49:07 +08:00
parent bd744c252c
commit ffef8cdd29
2 changed files with 23 additions and 17 deletions
+6 -5
View File
@@ -109,11 +109,12 @@ def api_watchlist():
conn = sqlite3.connect("/home/hmo/MoFin/data/mofin.db")
conn.row_factory = sqlite3.Row
rows = conn.execute("""
SELECT code, name, entry_low, entry_high, stop_loss, take_profit,
timing_signal, action, price, rr_ratio, updated_at
FROM holding_strategies
WHERE status='active' AND decision_type='自选策略'
ORDER BY code
SELECT hs.code, hs.name, hs.entry_low, hs.entry_high, hs.stop_loss, hs.take_profit,
hs.timing_signal, hs.action, lp.price, lp.change_pct, hs.rr_ratio, hs.updated_at
FROM holding_strategies hs
LEFT JOIN live_prices lp ON hs.code = lp.code
WHERE hs.status='active' AND hs.decision_type='自选策略'
ORDER BY hs.code
""").fetchall()
conn.close()
stocks = [dict(r) for r in rows]
+17 -12
View File
@@ -301,20 +301,25 @@ function renderWatchlist() {
<thead><tr class="text-slate-500 border-b border-slate-800/50">
<th class="text-left p-3">股票</th><th class="text-right p-3">现价</th>
<th class="text-right p-3">涨跌%</th><th class="text-right p-3">买入区间</th>
<th class="text-right p-3">建议仓位</th><th class="text-left p-3">推荐理由</th>
<th class="text-right p-3">信号</th><th class="text-left p-3">策略</th>
</tr></thead>
<tbody>${stocks.map(s => `
<tbody>${stocks.map(s => {
const buyZone = (s.entry_low||0) + '~' + (s.entry_high||0);
const rr = s.rr_ratio || 0;
const sl = s.stop_loss || 0;
const tp = s.take_profit || 0;
const signal = s.timing_signal || '';
const action = (s.action||'').slice(0,60);
return `
<tr class="stock-row border-b border-slate-800/30" onclick="openStock('${s.code}')">
<td class="p-3"><div class="font-medium text-white">${s.name}</div><div class="text-slate-500">${s.code}</div></td>
<td class="p-3 text-right font-mono">${(s.price||'—')}</td>
<td class="p-3 text-right font-mono ${(s.change_pct||0)>=0?'badge-up':'badge-down'}">
${(s.change_pct||0)>=0?'+':''}${(s.change_pct||0).toFixed(2)}
</td>
<td class="p-3 text-right font-mono">${s.analysis?.buy_low||'—'}~${s.analysis?.buy_high||'—'}</td>
<td class="p-3 text-right font-mono">${s.analysis?.position_recommend||'—'}</td>
<td class="p-3 text-slate-400">${s.analysis?.reason||''}</td>
</tr>
`).join('')}</tbody>
<td class="p-3 text-right font-mono">${(s.change_pct||0)>=0?'+':''}${(s.change_pct||0).toFixed(2)}</td>
<td class="p-3 text-right font-mono" title="损${sl}${tp} RR${rr}">${buyZone}</td>
<td class="p-3 text-right font-mono"><span class="${signal.includes('买入')?'text-green-400':signal.includes('关注')?'text-yellow-400':'text-slate-400'}">${signal||'—'}</span></td>
<td class="p-3 text-slate-400 text-xs max-w-[200px] truncate" title="${action}">${action||'—'}</td>
</tr>`;
}).join('')}</tbody>
</table>
</div>
</div>
@@ -396,8 +401,8 @@ function refreshMarketData() {
`).join('') : '<div class="text-xs text-slate-500">暂无</div>'}
</div>
<div class="card p-4">
<h3 class="text-sm font-semibold mb-2">🔍 小果扫描 (${xiaoguo.length})</h3>
${xiaoguo.length ? xiaoguo.slice(0,6).map(s => `
<h3 class="text-sm font-semibold mb-2">📊 信号汇总 (${sigs.length})</h3>
${sigs.length ? sigs.slice(0,6).map(s => `
<div class="p-1.5 bg-slate-800/30 rounded mb-0.5 text-xs">
<span class="font-semibold ${s.overall_sentiment==='利好'?'text-green-400':s.overall_sentiment==='利空'?'text-red-400':'text-slate-400'}">${s.overall_sentiment||'中性'}</span>
${s.sector} ${(s.summary||'').slice(0,60)}