fix: TradingView K线图表并修复品种推荐为空。

- 行情页改用 Lightweight Charts 标准蜡烛图(红跌绿涨)
- 修复 fee_rates 缺 source 列导致推荐刷新失败
- 空缓存自动重试,持仓页实时兜底计算推荐列表

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-25 12:33:49 +08:00
parent 074551490f
commit 32f1fa2c66
8 changed files with 458 additions and 527 deletions
+28 -9
View File
@@ -220,20 +220,39 @@ def _timeshare_session(bars: list) -> list:
def bars_to_api(bars: list) -> list[dict]:
"""转为前端图表 JSON。"""
result = []
"""转为前端图表 JSON(去重、排序、数值规范化)"""
result: list[dict] = []
seen: dict[int, dict] = {}
for bar in bars:
dt = _bar_datetime(bar)
ts = int(dt.timestamp() * 1000) if dt else None
result.append({
try:
o = float(bar.get("o") or 0)
h = float(bar.get("h") or o)
l = float(bar.get("l") or o)
c = float(bar.get("c") or o)
v = float(bar.get("v") or 0)
except (TypeError, ValueError):
continue
if h < l:
h, l = l, h
h = max(h, o, c)
l = min(l, o, c)
row = {
"time": bar["d"],
"timestamp": ts,
"open": bar["o"],
"high": bar["h"],
"low": bar["l"],
"close": bar["c"],
"volume": bar.get("v", 0),
})
"open": o,
"high": h,
"low": l,
"close": c,
"volume": v,
}
if ts is not None:
seen[ts] = row
else:
result.append(row)
if seen:
result = [seen[k] for k in sorted(seen.keys())]
return result