fix: fetch_market.py change_pct 输出纯数值,方向符号由前端渲染
- change_pct 从 "▲ 2.26%" 改为 "2.26%",is_up 控制方向 - 与 brief.html 前端渲染逻辑对齐,避免重复方向符号 - 修复 A 股超时后 cn_indices 为空导致行情行缺失的问题
This commit is contained in:
@ -23,13 +23,12 @@ def fetch_crypto():
|
|||||||
continue
|
continue
|
||||||
price = data[coin_id]["usd"]
|
price = data[coin_id]["usd"]
|
||||||
change = data[coin_id].get("usd_24h_change", 0) or 0
|
change = data[coin_id].get("usd_24h_change", 0) or 0
|
||||||
direction = "▲" if change >= 0 else "▼"
|
|
||||||
items.append({
|
items.append({
|
||||||
"type": "crypto",
|
"type": "crypto",
|
||||||
"symbol": names[coin_id],
|
"symbol": names[coin_id],
|
||||||
"icon": icon,
|
"icon": icon,
|
||||||
"price": f"${price:,.2f}",
|
"price": f"${price:,.2f}",
|
||||||
"change_pct": f"{direction} {abs(change):.2f}%",
|
"change_pct": f"{abs(change):.2f}%",
|
||||||
"is_up": change >= 0,
|
"is_up": change >= 0,
|
||||||
})
|
})
|
||||||
return items
|
return items
|
||||||
@ -49,13 +48,11 @@ def fetch_cn_indices():
|
|||||||
price = diff.get("f2", 0)
|
price = diff.get("f2", 0)
|
||||||
change = diff.get("f4", 0)
|
change = diff.get("f4", 0)
|
||||||
pct = diff.get("f3", 0)
|
pct = diff.get("f3", 0)
|
||||||
direction = "▲" if change >= 0 else "▼"
|
|
||||||
items.append({
|
items.append({
|
||||||
"type": "cn_index",
|
"type": "cn_index",
|
||||||
"symbol": name,
|
"symbol": name,
|
||||||
"price": f"{price:.2f}",
|
"price": f"{price:.2f}",
|
||||||
"change": f"{direction} {abs(change):.2f}",
|
"change_pct": f"{abs(pct):.2f}%",
|
||||||
"change_pct": f"{direction} {abs(pct):.2f}%",
|
|
||||||
"is_up": change >= 0,
|
"is_up": change >= 0,
|
||||||
})
|
})
|
||||||
return items
|
return items
|
||||||
|
|||||||
Reference in New Issue
Block a user