From 0b33e9a8b6acc6d26fb0f6eeed8835ea3be15396 Mon Sep 17 00:00:00 2001 From: Boki Date: Sun, 29 Jun 2025 13:04:48 -0400 Subject: [PATCH] finished prices --- .../src/handlers/qm/actions/prices.action.ts | 19 +++++++++++-------- .../handlers/qm/actions/symbol-info.action.ts | 1 - .../src/handlers/qm/qm.handler.ts | 2 +- .../handlers/qm/shared/operation-tracker.ts | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/stock/data-ingestion/src/handlers/qm/actions/prices.action.ts b/apps/stock/data-ingestion/src/handlers/qm/actions/prices.action.ts index a4ce443..7ec3ad5 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/actions/prices.action.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/actions/prices.action.ts @@ -57,7 +57,7 @@ export async function updatePrices( // Build API request for daily prices const searchParams = new URLSearchParams({ zeroTradeDays: 'false', - start: lastRecordDate?.toISOString().split('T')[0] ?? '1960-01-01', + start: lastRecordDate ? new Date(lastRecordDate).toISOString().split('T')[0] + '' : '1960-01-01', interval: '1', marketSession: 'mkt', freq: 'day', @@ -70,7 +70,8 @@ export async function updatePrices( // https://app.quotemedia.com/datatool/getEnhancedChartData.json?zeroTradeDays=false&start=2025-06-22&interval=1&marketSession=mkt&freq=day&adjusted=true&adjustmentType=none&unadjusted=false&datatype=int&symbol=AAPL // TODO: Update with correct prices endpoint const apiUrl = `${QM_CONFIG.PRICES_URL}?${searchParams.toString()}`; - + + console.log('QM Symbol Info API URL:', apiUrl); const response = await fetch(apiUrl, { method: 'GET', headers: session.headers, @@ -190,7 +191,7 @@ export async function schedulePriceUpdates( symbolsQueued: number; errors: number; }> { - const { limit = 1, forceUpdate = false } = input; + const { limit = 10000, forceUpdate = false } = input; const tracker = await getOperationTracker(this); this.logger.info('Scheduling price updates', { limit, forceUpdate }); @@ -217,7 +218,7 @@ export async function schedulePriceUpdates( const symbolDocs = await this.mongodb.find('qmSymbols', { qmSearchCode: { $in: staleSymbols } }, { - projection: { symbol: 1, symbolId: 1, qmSearchCode: 1 } + projection: { qmSearchCode: 1, operations: 1 } }); let queued = 0; @@ -226,13 +227,15 @@ export async function schedulePriceUpdates( // Schedule individual update jobs for each symbol for (const doc of symbolDocs) { try { - if (!doc.symbolId) { - this.logger.warn(`Symbol ${doc.symbol} missing symbolId, skipping`); + + if(doc.qmSearchCode !== 'A') { + // this.logger.warn(`Skipping symbol with missing qmSearchCode ${doc.qmSearchCode}`, { doc }); continue; } await this.scheduleOperation('update-prices', { - qmSearchCode: doc.qmSearchCode + qmSearchCode: doc.qmSearchCode, + lastRecordDate: doc.operations?.price_update?.lastRecordDate }, { priority: 7, // High priority for price data delay: queued * 500 // 0.5 seconds between jobs @@ -240,7 +243,7 @@ export async function schedulePriceUpdates( queued++; } catch (error) { - this.logger.error(`Failed to schedule price update for ${doc.symbol}`, { error }); + this.logger.error(`Failed to schedule price update for ${doc.qmSearchCode}`, { error }); errors++; } } diff --git a/apps/stock/data-ingestion/src/handlers/qm/actions/symbol-info.action.ts b/apps/stock/data-ingestion/src/handlers/qm/actions/symbol-info.action.ts index ccf18dd..20b63f3 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/actions/symbol-info.action.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/actions/symbol-info.action.ts @@ -65,7 +65,6 @@ export async function updateSymbolInfo( } as Record); const apiUrl = `${QM_CONFIG.SYMBOL_URL}?${searchParams.toString()}`; - const response = await fetch(apiUrl, { method: 'GET', headers: session.headers, diff --git a/apps/stock/data-ingestion/src/handlers/qm/qm.handler.ts b/apps/stock/data-ingestion/src/handlers/qm/qm.handler.ts index 7fd83c6..75133a7 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/qm.handler.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/qm.handler.ts @@ -125,7 +125,7 @@ export class QMHandler extends BaseHandler { @Operation('update-prices') updatePrices = updatePrices; - @Disabled() + // @Disabled() @ScheduledOperation('schedule-price-updates', '0 */6 * * *', { priority: 8, immediately: false, diff --git a/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts b/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts index 13d8c91..a7c3c79 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts @@ -209,6 +209,7 @@ export class QMOperationTracker { const filter: any = { $or: [ { [`operations.${operationName}.lastRunAt`]: { $lt: cutoffDate } }, + { [`operations.${operationName}.lastRunAt`]: { $exists: false } }, { [`operations.${operationName}`]: { $exists: false } } ] };