| | |
| | | <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> |
| | | </form> |
| | | </div> |
| | | |
| | |
| | | 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'); |
| | |
| | | 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 }); |
| | | toast('未找到配置,已加载默认值,编辑后请保存', 'success'); |
| | | } |
| | | currentApiKey = key; |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | 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 |
| | | }; |
| | | } |
| | | |
| | | function $(id) { return document.getElementById(id); } |
| | | |
| | | async function saveConfig() { |
| | | if (!currentApiKey) return toast('请先输入 API Key', 'error'); |