840e88daad
Key monitors use 5m close triggers with WeChat alerts and box/convergence auto orders; add pending-order worker, structured WeChat notify, AI settings/messages, session clock, CTP margin sizing, and dual-layer position limits. Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
3.6 KiB
JavaScript
90 lines
3.6 KiB
JavaScript
/* Copyright (c) 2025-2026 马建军. All rights reserved.
|
|
* 专有软件 — 未经授权禁止复制、传播、转售。
|
|
* 详见 LICENSE.zh-CN.txt
|
|
*/
|
|
(function () {
|
|
var keyTimer = null;
|
|
var typeEl = document.getElementById('key-type');
|
|
var tradeModeWrap = document.getElementById('key-trade-mode-wrap');
|
|
var rrWrap = document.getElementById('key-rr-wrap');
|
|
var rrEl = document.getElementById('key-rr');
|
|
var trailingWrap = document.getElementById('key-trailing-wrap');
|
|
var trailingEl = document.getElementById('key-trailing');
|
|
var rowActions = document.getElementById('key-row-actions');
|
|
var rowPrices = document.getElementById('key-row-prices');
|
|
|
|
function isAutoType(typ) {
|
|
return typ === '箱体突破' || typ === '收敛突破';
|
|
}
|
|
|
|
function syncKeyForm() {
|
|
var typ = typeEl ? typeEl.value : '';
|
|
var auto = isAutoType(typ);
|
|
if (tradeModeWrap) tradeModeWrap.classList.toggle('is-hidden', !auto);
|
|
if (rrWrap) rrWrap.classList.toggle('is-hidden', !auto);
|
|
if (trailingWrap) trailingWrap.classList.toggle('is-hidden', !auto);
|
|
if (rowActions) rowActions.classList.toggle('key-actions-zone', !auto);
|
|
if (rowPrices) rowPrices.classList.toggle('key-zone-mode', !auto);
|
|
if (!auto && trailingEl) trailingEl.checked = false;
|
|
if (auto && trailingEl && trailingEl.checked && rrEl) {
|
|
if (parseFloat(rrEl.value) < 3) rrEl.value = '3';
|
|
}
|
|
}
|
|
|
|
function fmtDist(v) {
|
|
if (v === null || v === undefined) return '--';
|
|
return Number(v).toFixed(2);
|
|
}
|
|
|
|
function pollKeyPrices() {
|
|
var list = document.getElementById('key-monitor-list');
|
|
if (!list || !list.querySelector('.key-item')) return;
|
|
|
|
fetch('/api/key_prices')
|
|
.then(function (r) { return r.json(); })
|
|
.then(function (rows) {
|
|
rows.forEach(function (row) {
|
|
var el = list.querySelector('.key-item[data-key-id="' + row.id + '"]');
|
|
if (!el) return;
|
|
var priceEl = el.querySelector('.live-price');
|
|
var upEl = el.querySelector('.dist-up');
|
|
var downEl = el.querySelector('.dist-down');
|
|
if (priceEl) priceEl.textContent = row.price != null ? row.price : '--';
|
|
if (upEl) upEl.textContent = fmtDist(row.dist_upper);
|
|
if (downEl) downEl.textContent = fmtDist(row.dist_lower);
|
|
});
|
|
})
|
|
.catch(function () { /* ignore */ });
|
|
}
|
|
|
|
function stopPolling() {
|
|
if (keyTimer) {
|
|
clearInterval(keyTimer);
|
|
keyTimer = null;
|
|
}
|
|
}
|
|
|
|
function startPolling() {
|
|
stopPolling();
|
|
pollKeyPrices();
|
|
keyTimer = setInterval(pollKeyPrices, 1000);
|
|
}
|
|
|
|
function bindForm() {
|
|
if (typeEl) typeEl.addEventListener('change', syncKeyForm);
|
|
if (trailingEl) {
|
|
trailingEl.addEventListener('change', function () {
|
|
if (trailingEl.checked && rrEl && parseFloat(rrEl.value) < 3) {
|
|
rrEl.value = '3';
|
|
}
|
|
});
|
|
}
|
|
syncKeyForm();
|
|
}
|
|
|
|
if (window.qihuoPageBoot) window.qihuoPageBoot(function () { bindForm(); startPolling(); }, '#key-monitor-list');
|
|
else if (window.qihuoOnPageLoad) window.qihuoOnPageLoad(function () { bindForm(); startPolling(); });
|
|
else document.addEventListener('DOMContentLoaded', function () { bindForm(); startPolling(); });
|
|
if (window.qihuoOnPageLeave) window.qihuoOnPageLeave(stopPolling);
|
|
})();
|