Hub market: add option expiry Friday yellow dashed splits.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -68,6 +68,7 @@
|
||||
let unsubClick = null;
|
||||
let mainBound = false;
|
||||
let tradingDaySplitEnabled = false;
|
||||
let optionExpirySplitEnabled = false;
|
||||
const BJ_OFFSET_SEC = 8 * 60 * 60;
|
||||
|
||||
function uid() {
|
||||
@@ -409,6 +410,53 @@
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
/** OKX 期权到期:每周五 08:00 UTC(=北京 16:00) */
|
||||
function collectOptionExpiryBoundaries(candles) {
|
||||
if (!candles.length) return [];
|
||||
const minT = Number(candles[0].time);
|
||||
const maxT = Number(candles[candles.length - 1].time);
|
||||
if (!Number.isFinite(minT) || !Number.isFinite(maxT)) return [];
|
||||
const out = [];
|
||||
const cur = new Date(minT * 1000);
|
||||
cur.setUTCHours(0, 0, 0, 0);
|
||||
cur.setUTCDate(cur.getUTCDate() - 1);
|
||||
const endSec = maxT + 2 * 86400;
|
||||
while (cur.getTime() / 1000 <= endSec) {
|
||||
if (cur.getUTCDay() === 5) {
|
||||
const boundary = Math.floor(
|
||||
Date.UTC(cur.getUTCFullYear(), cur.getUTCMonth(), cur.getUTCDate(), 8, 0, 0) / 1000
|
||||
);
|
||||
if (boundary >= minT - 3600 && boundary <= maxT + 3600) {
|
||||
if (!out.length || out[out.length - 1] !== boundary) out.push(boundary);
|
||||
}
|
||||
}
|
||||
cur.setUTCDate(cur.getUTCDate() + 1);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function drawOptionExpirySplits(ctx, w, h) {
|
||||
if (!optionExpirySplitEnabled || !chart) return;
|
||||
const candles = getCandles();
|
||||
if (!candles.length) return;
|
||||
const boundaries = collectOptionExpiryBoundaries(candles);
|
||||
if (!boundaries.length) return;
|
||||
ctx.save();
|
||||
ctx.strokeStyle = "#eab308";
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([5, 4]);
|
||||
boundaries.forEach(function (t) {
|
||||
const x = timeToX(t);
|
||||
if (x == null || !Number.isFinite(x) || x < -2 || x > w + 2) return;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x, 0);
|
||||
ctx.lineTo(x, h);
|
||||
ctx.stroke();
|
||||
});
|
||||
ctx.setLineDash([]);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
function drawRect(ctx, x1, y1, x2, y2, selected) {
|
||||
if (x1 == null || y1 == null || x2 == null || y2 == null) return;
|
||||
const l = Math.min(x1, x2);
|
||||
@@ -743,6 +791,7 @@
|
||||
const h = hostEl.clientHeight;
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
drawTradingDaySplits(ctx, w, h);
|
||||
drawOptionExpirySplits(ctx, w, h);
|
||||
drawings.forEach(function (d) {
|
||||
if (d.hidden) ctx.globalAlpha = 0.14;
|
||||
renderDrawing(ctx, d, w, h, d.id === selectedId);
|
||||
@@ -1451,10 +1500,16 @@
|
||||
scheduleRedraw();
|
||||
}
|
||||
|
||||
function setOptionExpirySplit(enabled) {
|
||||
optionExpirySplitEnabled = !!enabled;
|
||||
scheduleRedraw();
|
||||
}
|
||||
|
||||
window.HubChartDraw = {
|
||||
attach: attach,
|
||||
setViewKey: setViewKey,
|
||||
setTradingDaySplit: setTradingDaySplit,
|
||||
setOptionExpirySplit: setOptionExpirySplit,
|
||||
resize: scheduleRedraw,
|
||||
redraw: scheduleRedraw,
|
||||
destroy: destroy,
|
||||
|
||||
Reference in New Issue
Block a user