本地监控止盈止损、盘前自动连CTP,并完善保证金与推荐手数。

- 止盈止损改为程序本地监控,触发后市价平仓(含跳空)
- 交易前30分钟后台自动连接 CTP
- 保证金占用上限默认30%,可在系统设置修改
- K线标准蜡烛图红跌绿涨,费率表全宽固定表头
- 品种推荐按保证金比例×总资金计算推荐手数

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-25 12:18:18 +08:00
parent fe1b651900
commit 9875ee6d44
15 changed files with 467 additions and 256 deletions
+30 -3
View File
@@ -4,14 +4,41 @@
<style>
.fees-status-card .card-body{display:flex;flex-wrap:wrap;gap:.75rem 1.25rem;align-items:center}
.fees-status-card .fees-meta{font-size:.85rem;color:var(--text-muted)}
.fees-table-card .card-body{padding:.75rem 1rem 1rem}
.fees-table-card .trade-table-wrap{
max-height:min(70vh,560px);
width:100%;
border:none;
overflow:auto;
-webkit-overflow-scrolling:touch;
border:1px solid var(--table-border);
border-radius:10px;
background:var(--card-inner);
}
.fees-table-card .trade-table{
width:100%;
min-width:0;
table-layout:fixed;
font-size:.8rem;
}
.fees-table-card .trade-table thead th{
position:sticky;
top:0;
z-index:2;
background:var(--card-inner);
box-shadow:0 1px 0 var(--table-border);
}
.fees-table-card .trade-table th,
.fees-table-card .trade-table td{
padding:.5rem .4rem;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
}
.fees-table-card .trade-table th:last-child,
.fees-table-card .trade-table td:last-child{
position:static;
box-shadow:none;
}
.fees-table-card .trade-table{min-width:960px}
.fees-table-card .card-body{padding:.75rem 1rem 1rem}
</style>
{% endblock %}
{% block content %}
+5 -1
View File
@@ -63,10 +63,14 @@
<label>单笔风险比例(以损定仓,%</label>
<input name="risk_percent" type="number" step="0.1" min="0.1" max="100" value="{{ risk_percent }}">
</div>
<div class="field">
<label>保证金占用上限(%</label>
<input name="max_margin_pct" type="number" step="1" min="1" max="100" value="{{ max_margin_pct }}">
</div>
</div>
<button type="submit" class="btn-primary" style="margin-top:.75rem">保存交易设置</button>
<p class="hint" style="margin-top:.75rem;margin-bottom:0">
<code>.env</code> 配置 <code>SIMNOW_USER</code>,于「持仓监控」连接 CTP;权益与行情优先来自柜台。
保证金上限用于开仓校验与品种推荐手数(默认 30%)。<code>.env</code> 配置 <code>SIMNOW_USER</code>,于「持仓监控」连接 CTP;权益与行情优先来自柜台。
</p>
</form>
</div>
+4 -4
View File
@@ -19,7 +19,7 @@
</div>
<div class="trade-top-bar-actions">
<button type="button" class="btn-primary btn-ctp-sm" id="btn-ctp-connect">{% if ctp_status.connected %}重连 CTP{% else %}连接 CTP{% endif %}</button>
<span class="text-muted trade-top-hint">断线自动重连</span>
<span class="text-muted trade-top-hint">断线自动重连 · 开盘前 30 分钟自动连接</span>
</div>
</div>
@@ -107,7 +107,7 @@
<div class="card trade-card trade-card-full" id="recommend">
<h2>品种推荐</h2>
<div class="card-body">
<p class="hint">按权益 <strong class="text-accent" id="rec-capital">{{ '%.2f'|format(capital) }}</strong>筛选,仅显示可开 1 手的品种;参考止损/止盈按 20 跳、盈亏比 2:1 估算。
<p class="hint">按权益 <strong class="text-accent" id="rec-capital">{{ '%.2f'|format(capital) }}</strong> × 保证金上限 <strong>{{ max_margin_pct }}%</strong> 推荐手数;参考止损/止盈按 20 跳、盈亏比 2:1 估算。
{% if recommend_updated_at %}<span class="text-muted">每日后台更新 · 最近 {{ recommend_updated_at }}</span>{% else %}<span class="text-muted" id="rec-updated">等待今日后台刷新…</span>{% endif %}
</p>
<div class="trade-table-wrap">
@@ -116,7 +116,7 @@
<tr>
<th>品种</th><th>交易所</th><th>参考价</th>
<th>参考止损</th><th>参考止盈</th>
<th>1手保证金</th><th>1手手续费</th><th>建议最低资金</th><th>状态</th>
<th>1手保证金</th><th>1手手续费</th><th>推荐手数</th><th>状态</th>
</tr>
</thead>
<tbody id="recommend-list">
@@ -130,7 +130,7 @@
<td>{% if r.ref_take_profit %}{{ r.ref_take_profit }}{% else %}—{% endif %}</td>
<td>{% if r.margin_one_lot %}{{ r.margin_one_lot }}{% else %}—{% endif %}</td>
<td>{% if r.open_fee_one_lot is defined and r.open_fee_one_lot is not none %}{{ r.open_fee_one_lot }}{% else %}—{% endif %}</td>
<td>{% if r.min_capital_one_lot %}{{ r.min_capital_one_lot }}{% else %}—{% endif %}</td>
<td>{% if r.recommended_lots %}{{ r.recommended_lots }}{% else %}—{% endif %}</td>
<td><span class="badge {% if r.status=='ok' %}profit{% else %}planned{% endif %}">{{ r.status_label }}</span></td>
</tr>
{% endfor %}