feat: single-row funds strip on header and system settings page

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 10:09:51 +08:00
parent e82fd15bb7
commit 75aa4b1391
10 changed files with 185 additions and 73 deletions
@@ -85,11 +85,24 @@ def profit_loss_ratio_from_trades(trades: list[dict[str, Any]] | None) -> float
return profit_loss_ratio_from_averages(avg_win, avg_loss)
def options_funding_label(
funding_usdc: float | None,
funding_usdt: float | None = None,
) -> str:
parts: list[str] = []
if funding_usdc is not None:
parts.append(f"{float(funding_usdc):.2f} USDC")
if funding_usdt is not None:
parts.append(f"{float(funding_usdt):.2f} USDT")
return " · ".join(parts) if parts else ""
def total_funds_usdt(
funding_usdt: float | None,
trading_usdt: float | None,
options_trading_usdc: float | None = None,
options_funding_usdc: float | None = None,
options_funding_usdt: float | None = None,
) -> float | None:
if funding_usdt is None:
return None
@@ -97,6 +110,8 @@ def total_funds_usdt(
total = float(funding_usdt) + float(trading_usdt or 0)
if options_funding_usdc is not None:
total += float(options_funding_usdc)
if options_funding_usdt is not None:
total += float(options_funding_usdt)
if options_trading_usdc is not None:
total += float(options_trading_usdc)
return round(total, 2)
+11 -3
View File
@@ -1047,6 +1047,13 @@ function sumOrdersFloatPnl(orders){
return found ? total : null;
}
function formatOptionsFundingLabel(usdc, usdt) {
const parts = [];
if (usdc !== null && usdc !== undefined) parts.push(`${Number(usdc).toFixed(2)} USDC`);
if (usdt !== null && usdt !== undefined) parts.push(`${Number(usdt).toFixed(2)} USDT`);
return parts.length ? parts.join(" · ") : "—";
}
function refreshAccountSnapshot(){
fetch("/api/account_snapshot").then(r=>r.json()).then(data=>{
if (typeof data.funding_usdt !== "undefined") {
@@ -1061,10 +1068,9 @@ function refreshAccountSnapshot(){
const el = document.getElementById("current-capital");
if(el) el.innerText = `${Number(data.current_capital).toFixed(2)}U`;
}
if (typeof data.options_funding_usdc !== "undefined") {
if (typeof data.options_funding_usdc !== "undefined" || typeof data.options_funding_usdt !== "undefined") {
const el = document.getElementById("options-funding-usdc");
if (el) el.innerText = (data.options_funding_usdc === null || data.options_funding_usdc === undefined)
? "—" : `${Number(data.options_funding_usdc).toFixed(2)} USDC`;
if (el) el.innerText = formatOptionsFundingLabel(data.options_funding_usdc, data.options_funding_usdt);
}
if (typeof data.options_trading_usdc !== "undefined") {
const el = document.getElementById("options-trading-usdc");
@@ -1179,6 +1185,8 @@ if(window.ManualOrderRrPreview){
});
refreshAccountSnapshot();
const settingsRefreshFunds = document.getElementById("settings-refresh-funds");
if (settingsRefreshFunds) settingsRefreshFunds.addEventListener("click", refreshAccountSnapshot);
if (window.AccountRiskBadge) AccountRiskBadge.startTicker();
const _journalFormEl = document.getElementById("journal-form");
if(_journalFormEl){
+1 -1
View File
@@ -7,7 +7,7 @@
<link rel="stylesheet" href="/static/instance_theme_early.css?v=4">
<link rel="stylesheet" href="/static/account_risk_badge.css?v=4">
<link rel="stylesheet" href="/static/instance_page.css?v=3">
<link rel="stylesheet" href="/static/instance_theme.css?v=60">
<link rel="stylesheet" href="/static/instance_theme.css?v=62">
<script src="/static/account_risk_badge.js?v=4"></script>
<meta name="theme-color" content="#0b0d14">
<title>{{ exchange_display }} · 加密货币 | 交易监控复盘系统</title>
+12 -4
View File
@@ -17,7 +17,7 @@
<link rel="manifest" href="/static/icons/manifest.webmanifest">
<title>{{ exchange_display }} · 加密货币 | 交易监控复盘系统</title>
<link rel="stylesheet" href="/static/instance_page.css?v=1">
<link rel="stylesheet" href="/static/instance_theme.css?v=61">
<link rel="stylesheet" href="/static/instance_theme.css?v=62">
</head>
<body
@@ -1598,6 +1598,13 @@ function sumOrdersFloatPnl(orders){
return found ? total : null;
}
function formatOptionsFundingLabel(usdc, usdt) {
const parts = [];
if (usdc !== null && usdc !== undefined) parts.push(`${Number(usdc).toFixed(2)} USDC`);
if (usdt !== null && usdt !== undefined) parts.push(`${Number(usdt).toFixed(2)} USDT`);
return parts.length ? parts.join(" · ") : "—";
}
function refreshAccountSnapshot(){
fetch("/api/account_snapshot").then(r=>r.json()).then(data=>{
if (typeof data.funding_usdt !== "undefined") {
@@ -1612,10 +1619,9 @@ function refreshAccountSnapshot(){
const el = document.getElementById("current-capital");
if(el) el.innerText = `${Number(data.current_capital).toFixed(2)}U`;
}
if (typeof data.options_funding_usdc !== "undefined") {
if (typeof data.options_funding_usdc !== "undefined" || typeof data.options_funding_usdt !== "undefined") {
const el = document.getElementById("options-funding-usdc");
if (el) el.innerText = (data.options_funding_usdc === null || data.options_funding_usdc === undefined)
? "—" : `${Number(data.options_funding_usdc).toFixed(2)} USDC`;
if (el) el.innerText = formatOptionsFundingLabel(data.options_funding_usdc, data.options_funding_usdt);
}
if (typeof data.options_trading_usdc !== "undefined") {
const el = document.getElementById("options-trading-usdc");
@@ -1754,6 +1760,8 @@ if(window.ManualOrderRrPreview){
});
refreshAccountSnapshot();
const settingsRefreshFunds = document.getElementById("settings-refresh-funds");
if (settingsRefreshFunds) settingsRefreshFunds.addEventListener("click", refreshAccountSnapshot);
if (window.AccountRiskBadge) AccountRiskBadge.startTicker();
const _journalFormEl = document.getElementById("journal-form");
if(_journalFormEl){
@@ -41,52 +41,7 @@
</div>
</div>
</div>
<div class="instance-header-stats instance-desktop-only">
<div class="stat-strip-item stat-strip-item--primary">
<div class="label">交易所</div>
<div class="value">{{ exchange_display }}</div>
</div>
<div class="stat-strip-item">
<div class="label">交易日</div>
<div class="value">{{ trading_day }}</div>
</div>
<div class="stat-strip-item stat-strip-item--primary">
<div class="label">总交易</div>
<div class="value" id="stat-total">{{ total }}</div>
</div>
<div class="stat-strip-item">
<div class="label">胜率</div>
<div class="value" id="stat-rate">{{ rate }}%</div>
</div>
<div class="stat-strip-item" title="平均盈利 ÷ 平均亏损(当前列表窗口)">
<div class="label">盈亏比</div>
<div class="value" id="stat-pl-ratio">{% if profit_loss_ratio is not none %}{{ profit_loss_ratio }}{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">总资金</div>
<div class="value" id="total-funds">{% if total_funds is not none %}{{ funds_fmt(total_funds) }}U{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">资金账户</div>
<div class="value" id="total-capital">{% if funding_usdt is not none %}{{ funds_fmt(funding_usdt) }}U{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">交易账户</div>
<div class="value" id="current-capital">{{ funds_fmt(current_capital) }}U</div>
</div>
{% if options_enabled %}
<div class="stat-strip-item">
<div class="label">期权资金账户</div>
<div class="value" id="options-funding-usdc">{% if options_funding_usdc is not none %}{{ funds_fmt(options_funding_usdc) }} USDC{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">期权交易账户</div>
<div class="value" id="options-trading-usdc">{% if options_trading_usdc is not none %}{{ funds_fmt(options_trading_usdc) }} USDC{% else %}—{% endif %}</div>
</div>
{% endif %}
<div class="stat-strip-item stat-strip-item--pnl">
<div class="label">实时盈亏</div>
<div class="value" id="realtime-pnl"></div>
</div>
<div class="instance-header-stats-wrap instance-desktop-only">
{% include 'instance_header_stats.html' %}
</div>
</div>
@@ -0,0 +1,49 @@
{# 资金与统计条(顶栏 / 系统设置共用,单行展示) #}
<div class="instance-header-stats{% if options_enabled %} instance-header-stats--options{% endif %}">
<div class="stat-strip-item stat-strip-item--primary">
<div class="label">交易所</div>
<div class="value">{{ exchange_display }}</div>
</div>
<div class="stat-strip-item">
<div class="label">交易日</div>
<div class="value">{{ trading_day }}</div>
</div>
<div class="stat-strip-item stat-strip-item--primary">
<div class="label">总交易</div>
<div class="value" id="stat-total">{{ total }}</div>
</div>
<div class="stat-strip-item">
<div class="label">胜率</div>
<div class="value" id="stat-rate">{{ rate }}%</div>
</div>
<div class="stat-strip-item" title="平均盈利 ÷ 平均亏损(当前列表窗口)">
<div class="label">盈亏比</div>
<div class="value" id="stat-pl-ratio">{% if profit_loss_ratio is not none %}{{ profit_loss_ratio }}{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">总资金</div>
<div class="value" id="total-funds">{% if total_funds is not none %}{{ funds_fmt(total_funds) }}U{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">资金账户</div>
<div class="value" id="total-capital">{% if funding_usdt is not none %}{{ funds_fmt(funding_usdt) }}U{% else %}—{% endif %}</div>
</div>
<div class="stat-strip-item">
<div class="label">交易账户</div>
<div class="value" id="current-capital">{{ funds_fmt(current_capital) }}U</div>
</div>
{% if options_enabled %}
<div class="stat-strip-item">
<div class="label">期权资金账户</div>
<div class="value" id="options-funding-usdc">{{ options_funding_label(options_funding_usdc, options_funding_usdt) }}</div>
</div>
<div class="stat-strip-item">
<div class="label">期权交易账户</div>
<div class="value" id="options-trading-usdc">{% if options_trading_usdc is not none %}{{ funds_fmt(options_trading_usdc) }} USDC{% else %}—{% endif %}</div>
</div>
{% endif %}
<div class="stat-strip-item stat-strip-item--pnl">
<div class="label">实时盈亏</div>
<div class="value" id="realtime-pnl"></div>
</div>
</div>
@@ -1,5 +1,15 @@
{# 系统设置:左风控说明 · 右资金划转 + 数据导出 #}
<div class="settings-page">
<div class="card settings-account-summary">
<div class="settings-account-summary-head">
<div class="instance-toolbar-status">
<div class="exchange-tag">{{ exchange_display }}</div>
<span class="risk-status-badge risk-status-{{ risk_status.status|default('normal') }}" role="status">{{ risk_status.status_label|default('正常') }}</span>
</div>
<button type="button" class="btn-secondary btn-sm" id="settings-refresh-funds">刷新资金</button>
</div>
{% include 'instance_header_stats.html' %}
</div>
<div class="settings-cards-grid">
<div class="card settings-card settings-card--risk">
<h2>风控说明</h2>