| | |
| | | <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="false" selected>关闭</option><option value="true">开启</option></select></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="dualStopLossEnabled"><option value="false" selected>关闭</option><option value="true">开启</option></select></div> |
| | | <div class="form-group"><label>多仓止损触发价</label><input id="longStopLossPrice" placeholder="如 2540(价格跌至触发平多)"></div> |
| | | <div class="form-group"><label>空仓止损触发价</label><input id="shortStopLossPrice" placeholder="如 2650(价格涨至触发平空)"></div> |
| | | </form> |
| | | </div> |
| | | |
| | |
| | | // 文件不存在 → 用默认值填充,用户可编辑后保存 |
| | | 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, placeExcessTakeProfit: false }); |
| | | stopLossCountMode:'dual', addPositionInterval:3, addPositionQuantity:1, maxPositionPerSide:0, addPositionStartThreshold:1, placeExcessTakeProfit: 'off', |
| | | dualStopLossEnabled: false, longStopLossPrice: null, shortStopLossPrice: null }); |
| | | toast('未找到配置,已加载默认值,编辑后请保存', 'success'); |
| | | } |
| | | currentApiKey = key; |
| | |
| | | byId('addPositionQuantity').value = d.addPositionQuantity ?? 1; |
| | | byId('maxPositionPerSide').value = d.maxPositionPerSide ?? 0; |
| | | byId('addPositionStartThreshold').value = d.addPositionStartThreshold ?? 1; |
| | | byId('placeExcessTakeProfit').value = (d.placeExcessTakeProfit === true || d.placeExcessTakeProfit === 'true') ? 'true' : 'false'; |
| | | byId('placeExcessTakeProfit').value = normalizeTpMode(d.placeExcessTakeProfit); |
| | | byId('dualStopLossEnabled').value = (d.dualStopLossEnabled === true || d.dualStopLossEnabled === 'true') ? 'true' : 'false'; |
| | | byId('longStopLossPrice').value = d.longStopLossPrice || ''; |
| | | byId('shortStopLossPrice').value = d.shortStopLossPrice || ''; |
| | | } |
| | | |
| | | function collectForm() { |
| | |
| | | addPositionQuantity: intVal(byId('addPositionQuantity').value, 1), |
| | | maxPositionPerSide: intVal(byId('maxPositionPerSide').value, 0), |
| | | addPositionStartThreshold: intVal(byId('addPositionStartThreshold').value, 1), |
| | | placeExcessTakeProfit: byId('placeExcessTakeProfit').value === 'true' |
| | | placeExcessTakeProfit: byId('placeExcessTakeProfit').value, |
| | | dualStopLossEnabled: byId('dualStopLossEnabled').value === 'true', |
| | | longStopLossPrice: parseFloat(byId('longStopLossPrice').value) || null, |
| | | shortStopLossPrice: parseFloat(byId('shortStopLossPrice').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'); |