diff --git a/server/src/scripts/clickhouse-to-lmdbx.ts b/server/src/scripts/clickhouse-to-lmdbx.ts index 0d29641..c4746aa 100644 --- a/server/src/scripts/clickhouse-to-lmdbx.ts +++ b/server/src/scripts/clickhouse-to-lmdbx.ts @@ -16,27 +16,10 @@ async function syncAggregates({ key: T; date: string; }) { - const maxRetries = 3; // Maximum number of retries - let retryCount = 0; - - while (retryCount < maxRetries) { - try { - const aggregatesFrom = (await fromDatabase.getAggregates({ key, date })).map( - (aggregateWithoutKey) => ({ ...aggregateWithoutKey, key }) - ); - await toDatabase.insertAggregates(aggregatesFrom); - break; // Exit the loop if successful - } catch (error) { - retryCount++; - const delay = Math.pow(2, retryCount) * 1000; // Exponential backoff strategy - console.warn(`Retrying due to error: ${error}. Retry count: ${retryCount}, Delay: ${delay}ms`); - await new Promise((resolve) => setTimeout(resolve, delay)); - } - } - - if (retryCount === maxRetries) { - console.error(`Failed to sync aggregates after ${maxRetries} retries.`); - } + const aggregatesFrom = (await fromDatabase.getAggregates({ key, date })).map( + (aggregateWithoutKey) => ({ ...aggregateWithoutKey, key }) + ); + await toDatabase.insertAggregates(aggregatesFrom); } const symbols = ["AMD", "AAPL", "MSFT", "GOOGL", "NFLX", "NVDA"]; @@ -49,22 +32,25 @@ async function run() { console.error("Dates should be in YYYY-MM-DD format"); process.exit(1); } - - while (retryCount < maxRetries) { - try { - // ... rest of the code remains unchanged - - await run(); - } catch (error) { - console.warn(`Error occurred: ${error}. Retrying...`); - retryCount++; - const delay = Mathe.pow(2, retryCount) * 1000; // Exponential backoff strategy - console.warn(`Retry count: ${retryCount}, Delay: ${delay}ms`); - await new Promise((resolve) => setTimeout(resolve, delay)); + for (let date = startDate; date <= endDate; date = nextDate(date)) { + // const symbols = await stockDatabaseClickhouse.getSymbols({ date }); + for (const symbol of symbols) { + console.log(date, symbol); + const keys = await optionContractDatabaseClickhouse.getKeys({ + key: { symbol }, + date, + }); + for (const key of keys) { + // console.log(date, symbol, key.expirationDate, key.strike, key.type); + await syncAggregates({ + fromDatabase: optionContractDatabaseClickhouse, + toDatabase: optionContractDatabaseLmdbx, + key, + date, + }); + } } } - - if (retryCount === maxRetries) { - console.error(`Failed to sync aggregates after ${maxRetries} retries.`); - } } + +await run();