diff --git a/static/js/strategy.js b/static/js/strategy.js index fc9aeb4..14f84ed 100644 --- a/static/js/strategy.js +++ b/static/js/strategy.js @@ -16,6 +16,42 @@ return o; } + function showPreview(el, text, ok) { + if (!el) return; + if (!text) { + el.hidden = true; + el.textContent = ''; + return; + } + el.hidden = false; + el.textContent = text; + el.style.color = ok === false ? 'var(--loss)' : ''; + } + + function formatPlan(plan) { + if (!plan) return ''; + var lines = []; + if (plan.symbol) lines.push('品种:' + plan.symbol); + if (plan.target_lots != null) lines.push('目标手数:' + plan.target_lots); + if (plan.first_lots != null) lines.push('首仓:' + plan.first_lots + ' 手'); + if (plan.grid && plan.grid.length) { + lines.push('补仓档位:' + plan.grid.map(function (g) { return g.price; }).join(' → ')); + } + if (plan.message) lines.push(plan.message); + return lines.length ? lines.join('\n') : JSON.stringify(plan, null, 2); + } + + function formatRoll(preview) { + if (!preview) return ''; + var lines = []; + if (preview.add_lots != null) lines.push('加仓手数:' + preview.add_lots); + if (preview.new_stop_loss != null) lines.push('新止损:' + preview.new_stop_loss); + if (preview.total_lots != null) lines.push('合计手数:' + preview.total_lots); + if (preview.worst_loss != null) lines.push('最坏亏损:' + preview.worst_loss + ' 元'); + if (preview.message) lines.push(preview.message); + return lines.length ? lines.join('\n') : JSON.stringify(preview, null, 2); + } + var trendForm = document.getElementById('trend-form'); var btnPreview = document.getElementById('btn-trend-preview'); var btnExec = document.getElementById('btn-trend-exec'); @@ -23,20 +59,32 @@ if (btnPreview && trendForm) { btnPreview.addEventListener('click', function () { + btnPreview.disabled = true; jsonPost('/api/strategy/trend/preview', formData(trendForm)).then(function (d) { - if (!d.ok) { previewEl.textContent = d.error || '预览失败'; btnExec.hidden = true; return; } + if (!d.ok) { + showPreview(previewEl, d.error || '预览失败', false); + btnExec.hidden = true; + return; + } trendPayload = formData(trendForm); - previewEl.textContent = JSON.stringify(d.plan, null, 2); + showPreview(previewEl, formatPlan(d.plan), true); btnExec.hidden = false; + }).finally(function () { + btnPreview.disabled = false; }); }); } if (btnExec) { btnExec.addEventListener('click', function () { if (!trendPayload) return; + btnExec.disabled = true; + btnExec.textContent = '执行中…'; jsonPost('/api/strategy/trend/execute', trendPayload).then(function (d) { if (!d.ok) { alert(d.error); return; } location.reload(); + }).finally(function () { + btnExec.disabled = false; + btnExec.textContent = '确认执行首仓'; }); }); } @@ -47,18 +95,30 @@ var rollPrev = document.getElementById('roll-preview'); if (btnRollP && rollForm) { btnRollP.addEventListener('click', function () { + btnRollP.disabled = true; jsonPost('/api/strategy/roll/preview', formData(rollForm)).then(function (d) { - if (!d.ok) { rollPrev.textContent = d.error; btnRollE.hidden = true; return; } - rollPrev.textContent = JSON.stringify(d.preview, null, 2); + if (!d.ok) { + showPreview(rollPrev, d.error, false); + btnRollE.hidden = true; + return; + } + showPreview(rollPrev, formatRoll(d.preview), true); btnRollE.hidden = false; + }).finally(function () { + btnRollP.disabled = false; }); }); } if (btnRollE && rollForm) { btnRollE.addEventListener('click', function () { + btnRollE.disabled = true; + btnRollE.textContent = '执行中…'; jsonPost('/api/strategy/roll/execute', formData(rollForm)).then(function (d) { if (!d.ok) { alert(d.error); return; } location.reload(); + }).finally(function () { + btnRollE.disabled = false; + btnRollE.textContent = '执行滚仓'; }); }); } diff --git a/templates/settings.html b/templates/settings.html index 9a793ce..76883ce 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -2,113 +2,138 @@ {% block title %}系统设置 - 国内期货监控系统{% endblock %} {% block extra_css %} {% endblock %} {% block content %} -
+
-
-

导航显示

-
- -

关闭后顶栏隐藏对应入口,直接访问 URL 也会跳转回持仓监控。

-
- {% for key, label in nav_toggles.items() %} - - {% endfor %} -
- -
+
+
+

导航显示

+
+ +

关闭后顶栏隐藏对应入口,直接访问 URL 也会跳转回持仓监控。

+
+ {% for key, label in nav_toggles.items() %} + + {% endfor %} +
+ +
+
+ +
+

交易模式

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +

+ 在 .env 配置 SIMNOW_USER,于「持仓监控」连接 CTP;权益与行情优先来自柜台。 +

+
+
-
-

交易模式

-
- -
-
- - +
+
+

行情说明

+
+

+ 当前行情源:{{ quote_label }}
+ CTP 已连接时使用柜台行情;未连接时回退新浪接口。
+ 合约代码按同花顺格式(如 ag2608、IF2606)。 +

+
+
+ +
+

企业微信推送

+ + +
+ + +
+ +

在企业微信群添加机器人后,粘贴 Webhook 地址保存。

+ +
+
+ +
+
+

修改密码

+
+ +
+ +
- - + +
- - + +
-
- - -

- 模拟盘.env 配置 SIMNOW_USER 等,于「持仓监控」连接 CTP。 - 权益与行情优先来自 CTP 柜台。 -

-
+
+ + +
+
+ +
+ +
-
-

行情说明

-

- 当前行情源:{{ quote_label }}
- CTP 已连接时使用柜台行情(与下单、持仓一致);未连接时回退新浪免费接口。
- 合约代码按同花顺格式显示(如 ag2608、IF2606)。 -

-
- -
-

企业微信推送

-
- - - -
-

在企业微信群中添加机器人后,将 Webhook 地址粘贴到上方保存即可。

-
- -
-

修改密码

-
- -
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
+
+

使用提示

+
    +
  • 持仓监控:连接 CTP 后下单、看持仓与品种推荐
  • +
  • 策略交易:趋势回调自动补仓;顺势加仓需先开仓
  • +
  • 手续费:默认 CTP 柜台费率,连接后点同步
  • +
  • 手机端:浏览器菜单可「添加到主屏幕」安装 App
  • +
+
diff --git a/templates/strategy.html b/templates/strategy.html index 169b954..5ab9745 100644 --- a/templates/strategy.html +++ b/templates/strategy.html @@ -1,20 +1,37 @@ {% extends "base.html" %} {% block title %}策略交易 - 国内期货监控系统{% endblock %} +{% block extra_css %} + +{% endblock %} {% block content %} +

趋势回调

+
{% if active_trend %} -

运行中 #{{ active_trend.id }} {{ active_trend.symbol }} {{ active_trend.direction }} - 已开 {{ active_trend.lots_open or 0 }}/{{ active_trend.target_lots }} 手

-
+

运行中 #{{ active_trend.id }} · {{ active_trend.symbol }} · {{ '做多' if active_trend.direction == 'long' else '做空' }}

+

已开 {{ active_trend.lots_open or 0 }} / {{ active_trend.target_lots }} 手 · 止损 {{ active_trend.stop_loss }} · 止盈 {{ active_trend.take_profit }}

+
+

后台按档位自动补仓,触及止盈或手动结束。

{% else %} +

设置止损/补仓边界/止盈 → 预览 → 确认执行首仓;后续自动分档加仓。

-
+
+ +
+
@@ -23,41 +40,61 @@
- - + +
-

-        
+        
+        
         {% endif %}
+        
+

顺势加仓(滚仓)

-

须先有「下单监控」持仓;最多 3 腿;止盈锁首仓。

+
+

在已有持仓上扩大仓位,统一抬高止损;最多 3 腿,止盈锁定首仓。

+ {% if roll_groups %} + {% for g in roll_groups %} +
+ 运行中 · 监控 #{{ g.order_monitor_id }} · {{ g.leg_count or 1 }} 腿 · 止损 {{ g.current_stop_loss }} +
+ {% endfor %} + {% endif %} {% if monitors %}
- +
+ + +
- +
- - + +
-

-            
+            
+            
         
{% else %} -

请先在「持仓监控 → 期货下单」进入策略交易开仓。

+

暂无可用持仓监控

+
    +
  1. 打开 持仓监控,连接 CTP
  2. +
  3. 在「期货下单」填写品种、止损/止盈并开仓
  4. +
  5. 开仓成功后会生成本页可选的监控记录,即可滚仓
  6. +
{% endif %} +
-

策略交易记录 →

+

策略交易记录 →

+
{% endblock %} {% block extra_js %}