修复趋势回调止盈误显与行情区成交量被裁切的问题

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 13:45:19 +08:00
parent 21ef97cbdb
commit 01d26e9833
5 changed files with 245 additions and 54 deletions
+45 -8
View File
@@ -5,6 +5,9 @@
const AUTO_REFRESH_MS = 5000;
const DEFAULT_VISIBLE_BARS = 200;
const RIGHT_OFFSET_BARS = 10;
const CANDLE_SCALE_BOTTOM = 0.26;
const VOLUME_SCALE_TOP = 0.73;
const VOLUME_SCALE_BOTTOM = 0.06;
const TF_MS = {
"1m": 60_000,
"5m": 5 * 60_000,
@@ -111,6 +114,30 @@
if (el) el.textContent = "—";
});
if (elPosOrders) elPosOrders.innerHTML = "";
syncChartWrapLayout();
}
function resizeChart() {
if (!chart || !chartHost) return;
chart.applyOptions({ width: chartHost.clientWidth, height: chartHost.clientHeight });
updatePriceTag();
}
let resizeChartRaf = 0;
function scheduleChartResize() {
if (resizeChartRaf) cancelAnimationFrame(resizeChartRaf);
resizeChartRaf = requestAnimationFrame(function () {
resizeChartRaf = 0;
syncChartWrapLayout();
});
}
function syncChartWrapLayout() {
const wrap = chartHost && chartHost.closest(".market-chart-wrap");
if (wrap && elPosPanel) {
wrap.classList.toggle("has-pos-panel", !elPosPanel.classList.contains("hidden"));
}
resizeChart();
}
function renderPosPanel(ctx) {
@@ -126,7 +153,15 @@
}
if (elPosEntry) elPosEntry.textContent = ctx.entry != null ? fmtPrice(ctx.entry) : "—";
if (elPosSl) elPosSl.textContent = ctx.stop_loss != null ? fmtPrice(ctx.stop_loss) : "—";
if (elPosTp) elPosTp.textContent = ctx.take_profit != null ? fmtPrice(ctx.take_profit) : "—";
if (elPosTp) {
if (ctx.tp_monitored) {
elPosTp.textContent = "程序监控";
elPosTp.classList.add("market-pos-tp-monitored");
} else {
elPosTp.textContent = ctx.take_profit != null ? fmtPrice(ctx.take_profit) : "—";
elPosTp.classList.remove("market-pos-tp-monitored");
}
}
if (elPosSize) elPosSize.textContent = ctx.contracts != null ? String(ctx.contracts) : "—";
if (elPosOrders) {
const orders = Array.isArray(ctx.orders) ? ctx.orders : [];
@@ -155,6 +190,7 @@
.join("");
}
}
scheduleChartResize();
}
function clearPositionLines() {
@@ -172,8 +208,10 @@
const specs = [
{ price: posContext.entry, color: "#5b9cf5", title: "入场" },
{ price: posContext.stop_loss, color: "#ff4d6d", title: "止损" },
{ price: posContext.take_profit, color: "#00ff9d", title: "止盈" },
];
if (!posContext.tp_monitored && posContext.take_profit != null) {
specs.push({ price: posContext.take_profit, color: "#00ff9d", title: "止盈" });
}
specs.forEach(function (s) {
if (s.price == null || !Number.isFinite(Number(s.price))) return;
positionLines.push(
@@ -496,10 +534,10 @@
if (!volumeSeries) return false;
chart.priceScale("right").applyOptions({
scaleMargins: { top: 0.06, bottom: 0.28 },
scaleMargins: { top: 0.06, bottom: CANDLE_SCALE_BOTTOM },
});
chart.priceScale("volume").applyOptions({
scaleMargins: { top: 0.78, bottom: 0 },
scaleMargins: { top: VOLUME_SCALE_TOP, bottom: VOLUME_SCALE_BOTTOM },
});
applyPriceAutoScale();
@@ -522,11 +560,9 @@
});
window.addEventListener("resize", function () {
if (!chart) return;
chart.applyOptions({ width: chartHost.clientWidth, height: chartHost.clientHeight });
updatePriceTag();
scheduleChartResize();
});
chart.applyOptions({ width: chartHost.clientWidth, height: chartHost.clientHeight });
scheduleChartResize();
return true;
}
@@ -712,6 +748,7 @@
updateVisibleRangeMarkers();
syncPosContextForView(exKey, sym);
showLatestOhlcv();
scheduleChartResize();
const limit = data.limit || lastCandles.length;
let hint =