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) {
|
for (const pair of PAIRS) {
|
||||||
let endTs: number | undefined = undefined;
|
let endTs: number | undefined = undefined;
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
let prevOldest: number | undefined = undefined;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const batch = await fetchCandles(pair, '15m', 300, endTs);
|
const batch = await fetchCandles(pair, '15m', 300, endTs);
|
||||||
if (batch.length === 0) break;
|
if (batch.length === 0) break;
|
||||||
@@ -23,7 +24,10 @@ for (const pair of PAIRS) {
|
|||||||
await insertCandles(pair, closed);
|
await insertCandles(pair, closed);
|
||||||
total += closed.length;
|
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));
|
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;
|
if (oldest <= since) break;
|
||||||
endTs = oldest - 1;
|
endTs = oldest - 1;
|
||||||
await Bun.sleep(200); // Rate-Limit-Schonung
|
await Bun.sleep(200); // Rate-Limit-Schonung
|
||||||
|
|||||||
Reference in New Issue
Block a user