From d0009bfa3e84e6a08e5b968d8a45619a0bf35441 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 10 Aug 2026 14:27:17 +0800
Subject: [PATCH] feat(gate): 添加加仓启动阈值配置功能

---
 src/main/resources/static/gate-config.html |   71 ++++++++++++++++++++++++++---------
 1 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/src/main/resources/static/gate-config.html b/src/main/resources/static/gate-config.html
index 3313236..d86b442 100644
--- a/src/main/resources/static/gate-config.html
+++ b/src/main/resources/static/gate-config.html
@@ -114,6 +114,24 @@
             <div class="form-group"><label>每次下单张数</label><input id="quantity" placeholder="2"></div>
             <div class="form-group"><label>最大持仓张数</label><input id="maxPositionSize" placeholder="4"></div>
             <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>
         </form>
     </div>
 
@@ -135,6 +153,8 @@
 let currentApiKey = '';
 let logLines = [];
 const logPanel = document.getElementById('logPanel');
+
+function byId(id) { return document.getElementById(id); }
 
 function toast(msg, type) {
     const t = document.getElementById('toast');
@@ -181,13 +201,14 @@
     const key = document.getElementById('inputApiKey').value.trim();
     if (!key) return toast('请输入 API Key', 'error');
     try {
-        const d = await fetchApi(API + '/config/load?apiKey=' + encodeURIComponent(key));
+        const d = await fetchApi(API + '/config/load?apiKey=' + encodeURIComponent(key), { method: 'POST' });
         fillForm(d);
         toast('配置已加载', 'success');
     } catch(e) {
         // 文件不存在 → 用默认值填充,用户可编辑后保存
         fillForm({ gridRate:0.005, expectedProfit:0.15, maxLoss:1.5,
-            baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0 });
+            baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2, priceDriveEnabled: true, rounds: 0,
+            stopLossCountMode:'dual', addPositionInterval:3, addPositionQuantity:1, maxPositionPerSide:0, addPositionStartThreshold:1 });
         toast('未找到配置,已加载默认值,编辑后请保存', 'success');
     }
     currentApiKey = key;
@@ -197,29 +218,43 @@
 }
 
 function fillForm(d) {
-    document.getElementById('gridRate').value = d.gridRate || '';
-    document.getElementById('expectedProfit').value = d.expectedProfit || '';
-    document.getElementById('maxLoss').value = d.maxLoss || '';
-    document.getElementById('baseQuantity').value = d.baseQuantity || '';
-    document.getElementById('quantity').value = d.quantity || '';
-    document.getElementById('maxPositionSize').value = d.maxPositionSize ?? '';
-    document.getElementById('stopLossCount').value = d.stopLossCount ?? '';
+    byId('gridRate').value = d.gridRate || '';
+    byId('expectedProfit').value = d.expectedProfit || '';
+    byId('maxLoss').value = d.maxLoss || '';
+    byId('baseQuantity').value = d.baseQuantity || '';
+    byId('quantity').value = d.quantity || '';
+    byId('maxPositionSize').value = d.maxPositionSize ?? '';
+    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;
 }
 
 function collectForm() {
     return {
         apiKey: currentApiKey,
-        gridRate: parseFloat($('#gridRate').value) || 0,
-        expectedProfit: parseFloat($('#expectedProfit').value) || 0,
-        maxLoss: parseFloat($('#maxLoss').value) || 0,
-        baseQuantity: $('#baseQuantity').value,
-        quantity: $('#quantity').value,
-        maxPositionSize: parseInt($('#maxPositionSize').value) || 0,
-        stopLossCount: parseInt($('#stopLossCount').value) || 0
+        gridRate: parseFloat(byId('gridRate').value) || 0,
+        expectedProfit: parseFloat(byId('expectedProfit').value) || 0,
+        maxLoss: parseFloat(byId('maxLoss').value) || 0,
+        baseQuantity: byId('baseQuantity').value,
+        quantity: byId('quantity').value,
+        maxPositionSize: parseInt(byId('maxPositionSize').value) || 0,
+        stopLossCount: parseInt(byId('stopLossCount').value) || 0,
+        takeProfitGridSpan: parseInt(byId('takeProfitGridSpan').value) || 2,
+        priceDriveEnabled: byId('priceDriveEnabled').value === 'true',
+        rounds: parseInt(byId('rounds').value) || 0,
+        stopLossCountMode: byId('stopLossCountMode').value,
+        addPositionInterval: parseInt(byId('addPositionInterval').value) || 3,
+        addPositionQuantity: parseInt(byId('addPositionQuantity').value) || 1,
+        maxPositionPerSide: parseInt(byId('maxPositionPerSide').value) || 0,
+        addPositionStartThreshold: parseInt(byId('addPositionStartThreshold').value) ?? 1
     };
 }
-
-function $(id) { return document.getElementById(id); }
 
 async function saveConfig() {
     if (!currentApiKey) return toast('请先输入 API Key', 'error');

--
Gitblit v1.9.1