6e423eebfb
新增 vnpy CTP 桥接、以损定仓/固定张数、趋势回调与滚仓策略、按资金推荐品种及交易风控;模拟盘走 SimNow,实盘预留期货公司配置。 Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
3.0 KiB
JavaScript
77 lines
3.0 KiB
JavaScript
(function () {
|
|
var trendPayload = null;
|
|
|
|
function jsonPost(url, body) {
|
|
return fetch(url, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body || {})
|
|
}).then(function (r) { return r.json(); });
|
|
}
|
|
|
|
function formData(form) {
|
|
var fd = new FormData(form);
|
|
var o = {};
|
|
fd.forEach(function (v, k) { o[k] = v; });
|
|
return o;
|
|
}
|
|
|
|
var trendForm = document.getElementById('trend-form');
|
|
var btnPreview = document.getElementById('btn-trend-preview');
|
|
var btnExec = document.getElementById('btn-trend-exec');
|
|
var previewEl = document.getElementById('trend-preview');
|
|
|
|
if (btnPreview && trendForm) {
|
|
btnPreview.addEventListener('click', function () {
|
|
jsonPost('/api/strategy/trend/preview', formData(trendForm)).then(function (d) {
|
|
if (!d.ok) { previewEl.textContent = d.error || '预览失败'; btnExec.hidden = true; return; }
|
|
trendPayload = formData(trendForm);
|
|
previewEl.textContent = JSON.stringify(d.plan, null, 2);
|
|
btnExec.hidden = false;
|
|
});
|
|
});
|
|
}
|
|
if (btnExec) {
|
|
btnExec.addEventListener('click', function () {
|
|
if (!trendPayload) return;
|
|
jsonPost('/api/strategy/trend/execute', trendPayload).then(function (d) {
|
|
if (!d.ok) { alert(d.error); return; }
|
|
location.reload();
|
|
});
|
|
});
|
|
}
|
|
|
|
var rollForm = document.getElementById('roll-form');
|
|
var btnRollP = document.getElementById('btn-roll-preview');
|
|
var btnRollE = document.getElementById('btn-roll-exec');
|
|
var rollPrev = document.getElementById('roll-preview');
|
|
if (btnRollP && rollForm) {
|
|
btnRollP.addEventListener('click', function () {
|
|
jsonPost('/api/strategy/roll/preview', formData(rollForm)).then(function (d) {
|
|
if (!d.ok) { rollPrev.textContent = d.error; btnRollE.hidden = true; return; }
|
|
rollPrev.textContent = JSON.stringify(d.preview, null, 2);
|
|
btnRollE.hidden = false;
|
|
});
|
|
});
|
|
}
|
|
if (btnRollE && rollForm) {
|
|
btnRollE.addEventListener('click', function () {
|
|
jsonPost('/api/strategy/roll/execute', formData(rollForm)).then(function (d) {
|
|
if (!d.ok) { alert(d.error); return; }
|
|
location.reload();
|
|
});
|
|
});
|
|
}
|
|
|
|
var btnStop = document.getElementById('btn-trend-stop');
|
|
if (btnStop) {
|
|
btnStop.addEventListener('click', function () {
|
|
var pid = document.querySelector('#trend-stop-form input[name=plan_id]');
|
|
jsonPost('/api/strategy/trend/stop', { plan_id: pid ? pid.value : 0 }).then(function (d) {
|
|
if (!d.ok) { alert(d.error); return; }
|
|
location.reload();
|
|
});
|
|
});
|
|
}
|
|
})();
|