feat(hub): render AI summary account breakdown as icon table
Replace pipe-separated account lines with a structured table from stats_snapshot, including exchange icons and position remarks. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -271,6 +271,28 @@ def format_context_text(payload: dict) -> str:
|
||||
return "\n".join(lines).strip()
|
||||
|
||||
|
||||
def format_account_remark(ac: dict) -> str:
|
||||
"""分户表格备注:持仓摘要或关注点。"""
|
||||
positions = ac.get("positions") or []
|
||||
if not positions:
|
||||
issues = ac.get("issues") or []
|
||||
if issues:
|
||||
return ";".join(str(x) for x in issues[:2])
|
||||
return "无"
|
||||
parts: list[str] = []
|
||||
for p in positions[:3]:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
sym = p.get("symbol") or "?"
|
||||
side = p.get("side") or "?"
|
||||
contracts = p.get("contracts") if p.get("contracts") is not None else p.get("size")
|
||||
upnl = _position_float_pnl(p)
|
||||
parts.append(f"持仓: {sym} {side} 张数{contracts} 浮盈亏{upnl:.4f}U")
|
||||
if len(positions) > 3:
|
||||
parts.append(f"另有{len(positions) - 3}仓")
|
||||
return ";".join(parts) if parts else "无"
|
||||
|
||||
|
||||
def format_chat_context_brief(payload: dict, max_chars: int = 2500) -> str:
|
||||
text = format_context_text(payload)
|
||||
if len(text) <= max_chars:
|
||||
|
||||
Reference in New Issue
Block a user