work on eod

This commit is contained in:
Boki 2025-07-06 23:42:43 -04:00
parent 8f65c19d46
commit 5ca8fafe7e
10 changed files with 271 additions and 49 deletions

View file

@ -13,18 +13,14 @@ export async function scheduleFetchPrices(
const logger = this.logger;
try {
logger.info('Scheduling price fetch jobs for Canadian symbols');
logger.info('Scheduling price fetch jobs for all symbols');
// Calculate date one week ago
const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
// Get Canadian exchanges (TSX, TSV, CNQ, NEO)
const canadianExchanges = ['TO', 'V', 'CN', 'NEO'];
// Find symbols that haven't been updated in the last week
// Find ALL symbols that haven't been updated in the last week
const symbols = await this.mongodb.collection('eodSymbols').find({
Exchange: { $in: canadianExchanges },
delisted: false,
$or: [
{ lastPriceUpdate: { $lt: oneWeekAgo } },
@ -33,17 +29,30 @@ export async function scheduleFetchPrices(
}).toArray();
if (!symbols || symbols.length === 0) {
logger.info('No Canadian symbols need price updates');
logger.info('No symbols need price updates');
return { success: true, jobsScheduled: 0 };
}
logger.info(`Found ${symbols.length} Canadian symbols needing price updates`);
logger.info(`Found ${symbols.length} symbols needing price updates`, {
symbols: symbols.map(s => ({
symbol: s.Code,
exchange: s.Exchange,
name: s.Name,
lastUpdate: s.lastPriceUpdate
}))
});
let jobsScheduled = 0;
// Schedule jobs with staggered delays
for (let i = 0; i < symbols.length; i++) {
const symbol = symbols[i];
logger.debug(`Scheduling price fetch for ${symbol.Code}.${symbol.Exchange}`, {
name: symbol.Name,
lastUpdate: symbol.lastPriceUpdate,
delay: i * 100
});
await this.scheduleOperation('fetch-prices', {
symbol: symbol.Code,
exchange: symbol.Exchange
@ -78,7 +87,7 @@ export async function fetchPrices(
const { symbol, exchange } = input;
try {
logger.info('Fetching prices', { symbol, exchange });
logger.info(`Fetching prices for ${symbol}.${exchange}`);
// Get API key from config
const apiKey = EOD_CONFIG.API_TOKEN;
@ -90,7 +99,6 @@ export async function fetchPrices(
const url = new URL(`https://eodhd.com/api/eod/${symbol}.${exchange}`);
url.searchParams.append('api_token', apiKey);
url.searchParams.append('fmt', 'json');
// Fetch price data from EOD API
const response = await fetch(url.toString());
@ -107,6 +115,15 @@ export async function fetchPrices(
logger.info(`Fetched ${priceData.length} price records for ${symbol}.${exchange}`);
// Log date range of prices
if (priceData.length > 0) {
logger.debug(`Price data range for ${symbol}.${exchange}:`, {
oldest: priceData[0].date,
newest: priceData[priceData.length - 1].date,
count: priceData.length
});
}
// Add metadata to each price record
const pricesWithMetadata = priceData.map(price => ({
symbol,