From c367014e8bea8ee3854ea1c747ed179af8c2d4ec Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 21 Sep 2026 10:00:46 +0800
Subject: [PATCH] feat(gate): 添加分散止盈功能并重构止盈挂单模式

---
 src/main/resources/static/gate-config.html |   45 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/main/resources/static/gate-config.html b/src/main/resources/static/gate-config.html
index cbb6b2d..782a25c 100644
--- a/src/main/resources/static/gate-config.html
+++ b/src/main/resources/static/gate-config.html
@@ -116,6 +116,23 @@
             <div class="form-group"><label>止损阶梯次数</label><input id="stopLossCount" placeholder="0"></div>
             <div class="form-group"><label>止盈网格跨度</label><input id="takeProfitGridSpan" placeholder="2"></div>
             <div class="form-group"><label>价格驱动开关</label><select id="priceDriveEnabled"><option value="true" selected>开启</option><option value="false">关闭</option></select></div>
+            <div class="form-group"><label>运行轮数(0=不限)</label><input id="rounds" type="number" placeholder="0"></div>
+            <!-- ===== 加仓止损配置 ===== -->
+            <div class="form-group full" style="margin-top:6px;border-top:1px solid var(--border);padding-top:8px">
+                <label style="font-size:13px;font-weight:600;color:var(--text)">加仓 & 止损统计</label>
+            </div>
+            <div class="form-group">
+                <label>止损次数统计方式</label>
+                <select id="stopLossCountMode">
+                    <option value="dual" selected>双向统一统计</option>
+                    <option value="single">单向分别统计</option>
+                </select>
+            </div>
+            <div class="form-group"><label>加仓间隔(次)</label><input id="addPositionInterval" type="number" placeholder="3"></div>
+            <div class="form-group"><label>加仓数量(张)</label><input id="addPositionQuantity" type="number" placeholder="1"></div>
+            <div class="form-group"><label>单边最大仓位量(张)</label><input id="maxPositionPerSide" type="number" placeholder="0(不限制)"></div>
+            <div class="form-group"><label>加仓启动阈值(次)</label><input id="addPositionStartThreshold" type="number" placeholder="1(前N次止损不加仓)"></div>
+            <div class="form-group"><label>止盈挂单</label><select id="placeExcessTakeProfit"><option value="off" selected>关闭</option><option value="concentrated">集中止盈</option><option value="dispersed">分散止盈</option></select></div>
         </form>
     </div>
 
@@ -191,7 +208,8 @@
     } catch(e) {
         // 文件不存在 → 用默认值填充,用户可编辑后保存
         fillForm({ gridRate:0.005, expectedProfit:0.15, maxLoss:1.5,
-            baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2, priceDriveEnabled: true });
+            baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2, priceDriveEnabled: true, rounds: 0,
+            stopLossCountMode:'dual', addPositionInterval:3, addPositionQuantity:1, maxPositionPerSide:0, addPositionStartThreshold:1, placeExcessTakeProfit: 'off' });
         toast('未找到配置,已加载默认值,编辑后请保存', 'success');
     }
     currentApiKey = key;
@@ -210,6 +228,13 @@
     byId('stopLossCount').value = d.stopLossCount ?? '';
     byId('takeProfitGridSpan').value = d.takeProfitGridSpan ?? '';
     byId('priceDriveEnabled').value = (d.priceDriveEnabled === true || d.priceDriveEnabled === 'true') ? 'true' : 'false';
+    byId('rounds').value = d.rounds ?? 0;
+    byId('stopLossCountMode').value = d.stopLossCountMode || 'dual';
+    byId('addPositionInterval').value = d.addPositionInterval ?? 3;
+    byId('addPositionQuantity').value = d.addPositionQuantity ?? 1;
+    byId('maxPositionPerSide').value = d.maxPositionPerSide ?? 0;
+    byId('addPositionStartThreshold').value = d.addPositionStartThreshold ?? 1;
+    byId('placeExcessTakeProfit').value = normalizeTpMode(d.placeExcessTakeProfit);
 }
 
 function collectForm() {
@@ -223,9 +248,25 @@
         maxPositionSize: parseInt(byId('maxPositionSize').value) || 0,
         stopLossCount: parseInt(byId('stopLossCount').value) || 0,
         takeProfitGridSpan: parseInt(byId('takeProfitGridSpan').value) || 2,
-        priceDriveEnabled: byId('priceDriveEnabled').value === 'true'
+        priceDriveEnabled: byId('priceDriveEnabled').value === 'true',
+        rounds: parseInt(byId('rounds').value) || 0,
+        stopLossCountMode: byId('stopLossCountMode').value,
+        addPositionInterval: intVal(byId('addPositionInterval').value, 3),
+        addPositionQuantity: intVal(byId('addPositionQuantity').value, 1),
+        maxPositionPerSide: intVal(byId('maxPositionPerSide').value, 0),
+        addPositionStartThreshold: intVal(byId('addPositionStartThreshold').value, 1),
+        placeExcessTakeProfit: byId('placeExcessTakeProfit').value
     };
 }
+function intVal(str, fallback) {
+    const v = parseInt(str);
+    return isNaN(v) ? fallback : v;
+}
+function normalizeTpMode(v) {
+    if (v === true || v === 'true') return 'concentrated';
+    if (v === 'concentrated' || v === 'dispersed') return v;
+    return 'off';
+}
 
 async function saveConfig() {
     if (!currentApiKey) return toast('请先输入 API Key', 'error');

--
Gitblit v1.9.1