slice 4c (omlx/ornith-35): YFinanceAdapter candles 10y backfill + adjustments fetchOne

This commit is contained in:
Investor Flow Build
2026-06-29 21:58:39 -04:00
parent 796d7b58b3
commit 2a99e008e3
+7 -1
View File
@@ -5,6 +5,7 @@
import type { CacheKey, TtlClass, Provenance, Quote, PriceCandle, SymbolMeta, TickerKind } from '../cache/CacheRepository.ts';
import { parseCacheKey } from '../cache/CacheRepository.ts';
import type { SourceFetch, FetchResult } from './SourceAdapter.ts';
import { parseAdjustments } from './yfinance-adjustments.ts';
// Polite UA including operator contact (yfinance community norm; EDGAR requires similar).
const OPERATOR_EMAIL = process.env.YF_OPERATOR_EMAIL ?? 'operator@example.com';
@@ -31,10 +32,15 @@ export class YFinanceAdapter implements SourceFetch {
case 'candles': {
const [symbol, timeframe] = id.split(':');
const interval = timeframeToInterval(timeframe);
const days = timeframe === '1wk' ? 365 : 95; // slice 1: recent range for sparkline; slice 4 backfills `max`
const days = timeframe === '1wk' ? 3650 : 3650; // permanent backfill (~10 years)
const raw = await yf.chart(symbol, { period1: new Date(Date.now() - days * 86_400_000), interval });
return { value: parseCandles(raw), ttlClass: 'daily_permanent', provenance: { fetchedAt, sourceKind: 'yfinance', rawSourceId: `${symbol}:${timeframe}` } };
}
case 'adjustments': {
const symbol = id;
const raw = await yf.chart(symbol, { period1: new Date(Date.now() - 3650 * 86_400_000), interval: '1d' });
return { value: parseAdjustments(symbol, raw), ttlClass: 'daily_permanent', provenance: { fetchedAt, sourceKind: 'yfinance', rawSourceId: `${symbol}:adjustments` } };
}
case 'symbol': {
const raw = await yf.quoteSummary(id, { modules: ['summaryProfile'] });
return { value: parseSymbol(raw, id), ttlClass: 'symbol_meta', provenance: { fetchedAt, sourceKind: 'yfinance', rawSourceId: id } };