feat: 导航开关与 CTP 柜台手续费

系统设置可开关五类导航;手续费默认从 CTP 查询同步,本地/AKShare 作离线兜底;补充 FEES.md。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 12:19:56 +08:00
parent ca894dfd4d
commit 528d9811e3
13 changed files with 523 additions and 48 deletions
+5 -5
View File
@@ -484,14 +484,14 @@
<button type="button" class="nav-backdrop" id="nav-backdrop" aria-label="关闭菜单" hidden></button>
<nav class="site-nav" id="site-nav">
<a href="{{ url_for('positions') }}" class="{% if request.endpoint in ('positions', 'trade_page', 'recommend_page') %}active{% endif %}">持仓监控</a>
<a href="{{ url_for('strategy_page') }}" class="{% if request.endpoint in ('strategy_page', 'strategy_records_page') %}active{% endif %}">策略交易</a>
<a href="{{ url_for('plans') }}" class="{% if request.endpoint == 'plans' %}active{% endif %}">开单计划</a>
{% if nav_items.strategy %}<a href="{{ url_for('strategy_page') }}" class="{% if request.endpoint in ('strategy_page', 'strategy_records_page') %}active{% endif %}">策略交易</a>{% endif %}
{% if nav_items.plans %}<a href="{{ url_for('plans') }}" class="{% if request.endpoint == 'plans' %}active{% endif %}">开单计划</a>{% endif %}
<a href="{{ url_for('keys') }}" class="{% if request.endpoint == 'keys' %}active{% endif %}">关键位监控</a>
<a href="{{ url_for('market_page') }}" class="{% if request.endpoint == 'market_page' %}active{% endif %}">行情K线</a>
{% if nav_items.market %}<a href="{{ url_for('market_page') }}" class="{% if request.endpoint == 'market_page' %}active{% endif %}">行情K线</a>{% endif %}
<a href="{{ url_for('records') }}" class="{% if request.endpoint in ('records', 'trades') %}active{% endif %}">交易记录与复盘</a>
<a href="{{ url_for('stats') }}" class="{% if request.endpoint == 'stats' %}active{% endif %}">统计分析</a>
<a href="{{ url_for('fees') }}" class="{% if request.endpoint == 'fees' %}active{% endif %}">手续费配置</a>
<a href="{{ url_for('contract_profile_page') }}" class="{% if request.endpoint == 'contract_profile_page' %}active{% endif %}">品种简介</a>
{% if nav_items.fees %}<a href="{{ url_for('fees') }}" class="{% if request.endpoint == 'fees' %}active{% endif %}">手续费配置</a>{% endif %}
{% if nav_items.contract %}<a href="{{ url_for('contract_profile_page') }}" class="{% if request.endpoint == 'contract_profile_page' %}active{% endif %}">品种简介</a>{% endif %}
<a href="{{ url_for('settings') }}" class="{% if request.endpoint == 'settings' %}active{% endif %}">系统设置</a>
</nav>
</header>
+40 -8
View File
@@ -2,7 +2,37 @@
{% block title %}手续费配置 - 国内期货监控系统{% endblock %}
{% block content %}
<div class="card">
<h2>手续费倍率</h2>
<h2>手续费数据源</h2>
<div class="card-body">
<form action="{{ url_for('fees') }}" method="post" class="form-row" style="flex-wrap:wrap;gap:.75rem;align-items:center">
<input type="hidden" name="action" value="fee_source">
<label class="text-muted" style="font-size:.85rem">计费依据</label>
<select name="fee_source_mode" style="min-width:220px">
<option value="ctp" {% if fee_source_mode == 'ctp' %}selected{% endif %}>CTP 柜台(SimNow/实盘,推荐)</option>
<option value="local" {% if fee_source_mode == 'local' %}selected{% endif %}>本地 / AKShare 参考表</option>
</select>
<button type="submit" class="btn-primary">保存</button>
</form>
<p class="hint" style="margin-top:.75rem">
默认使用 <strong>CTP 柜台</strong> 查询到的开仓/平仓费率(连接 CTP 后自动同步,与 SimNow/期货公司一致)。
离线或未连接时可改用本地表估算。
</p>
<div class="form-row" style="margin-top:.75rem;flex-wrap:wrap;gap:.5rem">
<form action="{{ url_for('fees') }}" method="post" style="display:inline">
<input type="hidden" name="action" value="sync_ctp">
<button type="submit" class="btn-primary" {% if not ctp_connected %}disabled title="请先连接 CTP"{% endif %}>从 CTP 同步费率</button>
</form>
{% if ctp_connected %}
<span class="badge profit">CTP 已连接</span>
{% else %}
<span class="badge planned">CTP 未连接 — 请先连接后再同步</span>
{% endif %}
</div>
</div>
</div>
<div class="card">
<h2>本地参考倍率(仅「本地数据源」时使用)</h2>
<div class="card-body">
<form action="{{ url_for('fees') }}" method="post" class="form-row">
<input type="hidden" name="action" value="multiplier">
@@ -10,27 +40,26 @@
<input name="fee_multiplier" type="number" step="0.1" min="0" value="{{ multiplier }}" style="width:100px">
<button type="submit" class="btn-primary">保存倍率</button>
</form>
<p class="hint">默认 2 倍:从第三方拉取交易所参考标准后自动乘以该倍率写入本地表。模拟盘估算用,非实盘账单。</p>
<div class="form-row" style="margin-top:.75rem">
<form action="{{ url_for('fees') }}" method="post" style="display:inline">
<input type="hidden" name="action" value="sync">
<button type="submit" class="btn-primary">第三方同步(AKShare</button>
<button type="submit" class="btn-secondary"> AKShare 同步(本地</button>
</form>
<form action="{{ url_for('fees') }}" method="post" style="display:inline">
<input type="hidden" name="action" value="reload_json">
<button type="submit" class="btn-link" style="padding:.5rem 1rem;border:1px solid var(--card-border);border-radius:8px">重载本地 JSON 默认表</button>
<button type="submit" class="btn-link" style="padding:.5rem 1rem;border:1px solid var(--card-border);border-radius:8px">重载 JSON 默认表</button>
</form>
</div>
</div>
</div>
<div class="card">
<h2>品种费率表(已含倍率)</h2>
<h2>品种费率表</h2>
<div class="card-body card-scroll">
<table class="trade-table">
<thead>
<tr>
<th>品种</th><th>交易所</th><th>乘数</th>
<th>品种</th><th>来源</th><th>交易所</th><th>乘数</th>
<th>开仓(元/手)</th><th>开仓(比例)</th>
<th>平昨(元/手)</th><th>平昨(比例)</th>
<th>平今(元/手)</th><th>平今(比例)</th>
@@ -44,6 +73,7 @@
<input type="hidden" name="action" value="save_row">
<input type="hidden" name="product" value="{{ r.product }}">
<td><strong>{{ r.product }}</strong></td>
<td><span class="badge {% if r.source == 'ctp' %}profit{% else %}planned{% endif %}">{{ r.source or 'local' }}</span></td>
<td><input name="exchange" value="{{ r.exchange or '' }}" style="width:72px;padding:.3rem"></td>
<td><input name="mult" type="number" value="{{ r.mult }}" style="width:56px;padding:.3rem"></td>
<td><input name="open_fixed" type="number" step="0.0001" value="{{ r.open_fixed }}" style="width:72px;padding:.3rem"></td>
@@ -57,11 +87,13 @@
</form>
</tr>
{% else %}
<tr><td colspan="11" class="text-muted">暂无费率,请同步或重载 JSON</td></tr>
<tr><td colspan="12" class="text-muted">暂无费率,请连接 CTP 后同步</td></tr>
{% endfor %}
</tbody>
</table>
</div>
<p class="hint" style="margin-top:.75rem">比例按「成交价×乘数×手数×比例」计费;元/手为固定每手。开+平合计为一笔往返手续费。</p>
<p class="hint" style="margin-top:.75rem">
公式:单边手续费 = 固定(元/手)×手数 + 比例×价格×乘数×手数。往返 = 开仓 + 平仓(平今/平昨自动判断)。
</p>
</div>
{% endblock %}
+17
View File
@@ -2,6 +2,23 @@
{% block title %}系统设置 - 国内期货监控系统{% endblock %}
{% block content %}
<div class="card">
<h2>导航显示</h2>
<form action="{{ url_for('settings') }}" method="post">
<input type="hidden" name="action" value="nav">
<p class="hint" style="margin-bottom:.75rem">关闭后顶栏隐藏对应入口,直接访问 URL 也会跳转回持仓监控。</p>
<div class="form-grid" style="max-width:640px;grid-template-columns:1fr 1fr">
{% for key, label in nav_toggles.items() %}
<label class="field" style="display:flex;align-items:center;gap:.5rem;cursor:pointer">
<input type="checkbox" name="nav_{{ key }}" {% if nav_items[key] %}checked{% endif %}>
<span>{{ label }}</span>
</label>
{% endfor %}
</div>
<button type="submit" class="btn-primary" style="margin-top:.75rem">保存导航</button>
</form>
</div>
<div class="card">
<h2>交易模式</h2>
<form action="{{ url_for('settings') }}" method="post">