Fix option day splits to daily Beijing 16:00 lines.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -410,27 +410,24 @@
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
/** OKX 期权到期:每周五 08:00 UTC(=北京 16:00) */
|
||||
/** OKX 期权到期切日:每天 08:00 UTC(=北京 16:00),对应日期权 1/2/3 日间隔 */
|
||||
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 [];
|
||||
// 北京日历日 → UTC 当天 08:00(=北京 16:00)
|
||||
const minP = utcSecToBjParts(minT);
|
||||
const maxP = utcSecToBjParts(maxT);
|
||||
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);
|
||||
}
|
||||
let curMs = Date.UTC(minP.y, minP.m, minP.d, 8, 0, 0) - 86400000;
|
||||
const endMs = Date.UTC(maxP.y, maxP.m, maxP.d, 8, 0, 0) + 2 * 86400000;
|
||||
while (curMs <= endMs) {
|
||||
const boundary = Math.floor(curMs / 1000);
|
||||
if (boundary >= minT - 3600 && boundary <= maxT + 3600) {
|
||||
if (!out.length || out[out.length - 1] !== boundary) out.push(boundary);
|
||||
}
|
||||
cur.setUTCDate(cur.getUTCDate() + 1);
|
||||
curMs += 86400000;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user