fix: backfill symbol_demand for sidebar-added symbols + analyst ratings schema fix
- Add await ctx.cache.subscribe() to addSymbol mutation so symbols added via the sidebar get registered in symbol_demand and yfinance jobs are queued immediately - Backfill PEP, WYNN, STZ, CELH into symbol_demand + adapter_queue - Upgrade yahoo-finance2 3.15.3 -> 3.15.4 and pass validateResult:false to quoteSummary() to handle Yahoo schema drift - Add error detail logging for analyst ratings schema failures - Update .gitignore with common ignores
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Investor Flow — X backfill (Slice 16 follow-up).
|
||||
// On first-add of a tracked account, walk the account's timeline AND the symbol's
|
||||
// cashtag back N days (default 30) and persist every post into x_cookie_posts.
|
||||
// Rate-limited by XCookieAdapter's own 1 req / 3s TokenBucket, so this is a
|
||||
// background job — callers fire-and-forget (do not await in the request path).
|
||||
import type { DatabaseSync } from 'node:sqlite';
|
||||
import { XCookieAdapter } from '../adapters/XCookieAdapter.ts';
|
||||
|
||||
const DEFAULT_BACKFILL_DAYS = 30;
|
||||
|
||||
export async function backfillAccount(
|
||||
db: DatabaseSync,
|
||||
symbol: string,
|
||||
handle: string,
|
||||
days: number = DEFAULT_BACKFILL_DAYS,
|
||||
): Promise<void> {
|
||||
const row = db.prepare('SELECT ct0_enc, auth_token_enc FROM x_credentials WHERE id=?').get('singleton') as
|
||||
{ ct0_enc?: string | null; auth_token_enc?: string | null } | undefined;
|
||||
if (!row || !row.ct0_enc || !row.auth_token_enc) {
|
||||
console.warn('[x-backfill] skipped — no X credentials configured');
|
||||
return;
|
||||
}
|
||||
|
||||
const cryptoMod: any = await import('../lib/crypto.ts');
|
||||
const creds = {
|
||||
ct0: cryptoMod.default.decrypt(row.ct0_enc),
|
||||
auth_token: cryptoMod.default.decrypt(row.auth_token_enc),
|
||||
};
|
||||
const adapter = new XCookieAdapter(creds, undefined, db);
|
||||
|
||||
try {
|
||||
await adapter.trustedTimeline(handle, { walkBackDays: days });
|
||||
console.log(`[x-backfill] timeline ${handle} (${days}d) done`);
|
||||
} catch (e) {
|
||||
console.error(`[x-backfill] timeline ${handle} failed:`, e instanceof Error ? e.message : e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user