diff --git a/server.py b/server.py index 73f49b0d..514b28fb 100644 --- a/server.py +++ b/server.py @@ -280,10 +280,22 @@ def get_watch(): d.pop('_pos', None) d.pop('_rr', None) + # 数据最新更新时间(price_monitor/live_prices) + _data_time = "" + try: + _dtc = sqlite3.connect("/home/hmo/MoFin/data/mofin.db") + _r = _dtc.execute("SELECT MAX(updated_at) FROM live_prices").fetchone() + if _r and _r[0]: + _data_time = str(_r[0]) + _dtc.close() + except Exception: + pass + return json.dumps({"stocks": results, "count": len(results), "cash": _cash, "total_assets": _total, "budget_pct": round(_budget_pct, 2), - "rec_used_pct": round(_cum, 2)}, ensure_ascii=False) + "rec_used_pct": round(_cum, 2), + "data_time": _data_time}, ensure_ascii=False) @app.route("/api/strategy_history/") diff --git a/static/index.html b/static/index.html index c8e13046..bdf9424f 100644 --- a/static/index.html +++ b/static/index.html @@ -265,16 +265,23 @@ async function fetchJSON(url) { async function refreshAll() { document.getElementById('tab-overview').classList.add('loading'); - const [overview, portfolio, watchlist, reports] = await Promise.all([ + const [overview, portfolio, watchlist, reports, watchData] = await Promise.all([ fetchJSON('/api/overview'), fetchJSON('/api/portfolio'), fetchJSON('/api/watchlist'), fetchJSON('/api/reports'), + fetchJSON('/api/watch'), ]); portfolioData = portfolio; watchlistData = watchlist; reportsData = Array.isArray(reports) ? reports : []; - document.getElementById('updateTime').textContent = '更新 ' + new Date().toLocaleTimeString('zh-CN', {hour:'2-digit',minute:'2-digit'}); + // 右上角时间显示:来源时间说明 + let timeParts = ['⏱页面 ' + new Date().toLocaleTimeString('zh-CN', {hour:'2-digit',minute:'2-digit'})]; + if (watchData && watchData.data_time) { + const dt = watchData.data_time.slice(5,16); + timeParts.unshift('📡价格 ' + dt); + } + document.getElementById('updateTime').textContent = timeParts.join(' | '); document.getElementById('tab-overview').classList.remove('loading'); renderTab(document.querySelector('.tab-btn.active')?.dataset?.tab || 'overview'); }