fix: Backfill-Stall-Guard gegen Endlosschleife am History-Ende
This commit is contained in:
@@ -10,6 +10,7 @@ const since = Date.now() - TARGET_MONTHS * 30 * 24 * 60 * 60 * 1000;
|
||||
for (const pair of PAIRS) {
|
||||
let endTs: number | undefined = undefined;
|
||||
let total = 0;
|
||||
let prevOldest: number | undefined = undefined;
|
||||
for (;;) {
|
||||
const batch = await fetchCandles(pair, '15m', 300, endTs);
|
||||
if (batch.length === 0) break;
|
||||
@@ -23,7 +24,10 @@ for (const pair of PAIRS) {
|
||||
await insertCandles(pair, closed);
|
||||
total += closed.length;
|
||||
|
||||
// Cursor aus batch (nicht closed): auch die laufende Candle schiebt die Paginierung zurück
|
||||
const oldest = Math.min(...batch.map((c) => c.ts));
|
||||
if (prevOldest !== undefined && oldest >= prevOldest) break; // API-History-Ende erreicht
|
||||
prevOldest = oldest;
|
||||
if (oldest <= since) break;
|
||||
endTs = oldest - 1;
|
||||
await Bun.sleep(200); // Rate-Limit-Schonung
|
||||
|
||||
Reference in New Issue
Block a user