From bb56340538dfe44ab2946df2cdaf43855c74fa9e Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 21 Sep 2026 09:55:28 +0800
Subject: [PATCH] feat(gate): 添加自定义止损功能
---
src/main/resources/static/gate-config.html | 36 +++++++++++++++++++++++++++++++-----
1 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/src/main/resources/static/gate-config.html b/src/main/resources/static/gate-config.html
index d86b442..0cd16d6 100644
--- a/src/main/resources/static/gate-config.html
+++ b/src/main/resources/static/gate-config.html
@@ -132,6 +132,14 @@
<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>
+ <!-- ===== 自定义止损配置 ===== -->
+ <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="customStopLossEnabled"><option value="false" selected>关闭</option><option value="true">开启</option></select></div>
+ <div class="form-group"><label>多仓止损触发价</label><input id="longCustomStopLossPrice" placeholder="如 2540(价格跌至触发平多)"></div>
+ <div class="form-group"><label>空仓止损触发价</label><input id="shortCustomStopLossPrice" placeholder="如 2650(价格涨至触发平空)"></div>
</form>
</div>
@@ -208,7 +216,8 @@
// 文件不存在 → 用默认值填充,用户可编辑后保存
fillForm({ gridRate:0.005, expectedProfit:0.15, maxLoss:1.5,
baseQuantity:'2', quantity:'2', maxPositionSize:4, stopLossCount:0, takeProfitGridSpan:2, priceDriveEnabled: true, rounds: 0,
- stopLossCountMode:'dual', addPositionInterval:3, addPositionQuantity:1, maxPositionPerSide:0, addPositionStartThreshold:1 });
+ stopLossCountMode:'dual', addPositionInterval:3, addPositionQuantity:1, maxPositionPerSide:0, addPositionStartThreshold:1, placeExcessTakeProfit: 'off',
+ customStopLossEnabled: false, longCustomStopLossPrice: null, shortCustomStopLossPrice: null });
toast('未找到配置,已加载默认值,编辑后请保存', 'success');
}
currentApiKey = key;
@@ -233,6 +242,10 @@
byId('addPositionQuantity').value = d.addPositionQuantity ?? 1;
byId('maxPositionPerSide').value = d.maxPositionPerSide ?? 0;
byId('addPositionStartThreshold').value = d.addPositionStartThreshold ?? 1;
+ byId('placeExcessTakeProfit').value = normalizeTpMode(d.placeExcessTakeProfit);
+ byId('customStopLossEnabled').value = (d.customStopLossEnabled === true || d.customStopLossEnabled === 'true') ? 'true' : 'false';
+ byId('longCustomStopLossPrice').value = d.longCustomStopLossPrice || '';
+ byId('shortCustomStopLossPrice').value = d.shortCustomStopLossPrice || '';
}
function collectForm() {
@@ -249,12 +262,25 @@
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
+ 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,
+ customStopLossEnabled: byId('customStopLossEnabled').value === 'true',
+ longCustomStopLossPrice: parseFloat(byId('longCustomStopLossPrice').value) || null,
+ shortCustomStopLossPrice: parseFloat(byId('shortCustomStopLossPrice').value) || null
};
}
+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