Skip to content

Commit dfd1e1f

Browse files
committed
fix: record extended Binance 5m close times
1 parent 1db540d commit dfd1e1f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

research/regime-trend-v1/five-minute-data-tools.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function validateArchiveCandles(candles, month) {
100100
const { start, endExclusive } = monthBounds(month);
101101
const gaps = [];
102102
const shortenedCloses = [];
103+
const extendedCloses = [];
103104
let missingIntervalCount = 0;
104105

105106
for (let index = 0; index < candles.length; index += 1) {
@@ -120,18 +121,27 @@ export function validateArchiveCandles(candles, month) {
120121
) {
121122
throw new Error(`Invalid 5m OHLC bounds at ${candle.timestamp}`);
122123
}
124+
123125
const expectedClose = candle.timestamp + FIVE_MINUTES_MS - 1;
124-
if (candle.closeTime < candle.timestamp || candle.closeTime > expectedClose) {
125-
throw new Error(`Invalid 5m close time at ${candle.timestamp}`);
126+
if (candle.closeTime < candle.timestamp) {
127+
throw new Error(`5m close time precedes open time at ${candle.timestamp}`);
126128
}
127-
if (candle.closeTime !== expectedClose) {
129+
if (candle.closeTime < expectedClose) {
128130
shortenedCloses.push({
129131
open_time: candle.timestamp,
130132
close_time: candle.closeTime,
131133
expected_close_time: expectedClose,
132134
shortened_by_ms: expectedClose - candle.closeTime
133135
});
136+
} else if (candle.closeTime > expectedClose) {
137+
extendedCloses.push({
138+
open_time: candle.timestamp,
139+
close_time: candle.closeTime,
140+
expected_close_time: expectedClose,
141+
extended_by_ms: candle.closeTime - expectedClose
142+
});
134143
}
144+
135145
if (index > 0) {
136146
const previous = candles[index - 1];
137147
const delta = candle.timestamp - previous.timestamp;
@@ -159,8 +169,11 @@ export function validateArchiveCandles(candles, month) {
159169
missing_interval_count: missingIntervalCount,
160170
leading_missing_intervals: leadingMissing,
161171
trailing_missing_intervals: trailingMissing,
172+
irregular_close_count: shortenedCloses.length + extendedCloses.length,
162173
shortened_close_count: shortenedCloses.length,
174+
extended_close_count: extendedCloses.length,
163175
gaps,
164-
shortened_closes: shortenedCloses
176+
shortened_closes: shortenedCloses,
177+
extended_closes: extendedCloses
165178
};
166179
}

0 commit comments

Comments
 (0)