slice 4c (omlx/ornith-35): YFinanceAdapter candles 10y backfill + adjustments fetchOne
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import type { CacheKey, TtlClass, Provenance, Quote, PriceCandle, SymbolMeta, TickerKind } from '../cache/CacheRepository.ts';
|
import type { CacheKey, TtlClass, Provenance, Quote, PriceCandle, SymbolMeta, TickerKind } from '../cache/CacheRepository.ts';
|
||||||
import { parseCacheKey } from '../cache/CacheRepository.ts';
|
import { parseCacheKey } from '../cache/CacheRepository.ts';
|
||||||
import type { SourceFetch, FetchResult } from './SourceAdapter.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).
|
// Polite UA including operator contact (yfinance community norm; EDGAR requires similar).
|
||||||
const OPERATOR_EMAIL = process.env.YF_OPERATOR_EMAIL ?? 'operator@example.com';
|
const OPERATOR_EMAIL = process.env.YF_OPERATOR_EMAIL ?? 'operator@example.com';
|
||||||
@@ -31,10 +32,15 @@ export class YFinanceAdapter implements SourceFetch {
|
|||||||
case 'candles': {
|
case 'candles': {
|
||||||
const [symbol, timeframe] = id.split(':');
|
const [symbol, timeframe] = id.split(':');
|
||||||
const interval = timeframeToInterval(timeframe);
|
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 });
|
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}` } };
|
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': {
|
case 'symbol': {
|
||||||
const raw = await yf.quoteSummary(id, { modules: ['summaryProfile'] });
|
const raw = await yf.quoteSummary(id, { modules: ['summaryProfile'] });
|
||||||
return { value: parseSymbol(raw, id), ttlClass: 'symbol_meta', provenance: { fetchedAt, sourceKind: 'yfinance', rawSourceId: id } };
|
return { value: parseSymbol(raw, id), ttlClass: 'symbol_meta', provenance: { fetchedAt, sourceKind: 'yfinance', rawSourceId: id } };
|
||||||
|
|||||||
Reference in New Issue
Block a user