work on qm filings
This commit is contained in:
parent
710577eb3d
commit
960daf4cad
17 changed files with 2319 additions and 32 deletions
|
|
@ -14,8 +14,11 @@ export async function updateFilings(
|
|||
this: QMHandler,
|
||||
input: {
|
||||
symbol: string;
|
||||
symbolId: number;
|
||||
exchange: string;
|
||||
lastRecordDate?: Date | null;
|
||||
qmSearchCode: string;
|
||||
page: number;
|
||||
totalPages?: number;
|
||||
},
|
||||
_context?: ExecutionContext
|
||||
): Promise<{
|
||||
|
|
@ -24,9 +27,9 @@ export async function updateFilings(
|
|||
message: string;
|
||||
data?: any;
|
||||
}> {
|
||||
const { symbol, symbolId, qmSearchCode } = input;
|
||||
const { qmSearchCode, page, symbol, exchange, lastRecordDate, totalPages } = input;
|
||||
|
||||
this.logger.info('Fetching filings', { symbol, symbolId });
|
||||
this.logger.info(`Fetching filings ${qmSearchCode} - ${page}/${totalPages}`, { qmSearchCode, page });
|
||||
|
||||
const sessionManager = QMSessionManager.getInstance();
|
||||
await sessionManager.initialize(this.cache, this.logger);
|
||||
|
|
@ -42,15 +45,17 @@ export async function updateFilings(
|
|||
try {
|
||||
// Build API request for filings
|
||||
const searchParams = new URLSearchParams({
|
||||
symbol: symbol,
|
||||
symbolId: symbolId.toString(),
|
||||
qmodTool: 'Filings',
|
||||
webmasterId: '500',
|
||||
limit: '50' // Get recent filings
|
||||
symbol: qmSearchCode,
|
||||
webmasterId: "500",
|
||||
page: "1",
|
||||
xbrlSubDoc: "true",
|
||||
inclIxbrl: "true",
|
||||
inclXbrl: "true",
|
||||
resultsPerPage: "25",
|
||||
});
|
||||
|
||||
// TODO: Update with correct filings endpoint
|
||||
const apiUrl = `${QM_CONFIG.BASE_URL}/datatool/filings.json?${searchParams.toString()}`;
|
||||
const apiUrl = `${QM_CONFIG.FILING_URL}?${searchParams.toString()}`;
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
|
|
@ -75,10 +80,9 @@ export async function updateFilings(
|
|||
filingsData.map((filing: any) => ({
|
||||
...filing,
|
||||
symbol,
|
||||
symbolId,
|
||||
updated_at: new Date()
|
||||
exchange,
|
||||
})),
|
||||
['symbol', 'filingDate', 'formType', 'accessionNumber'] // Unique keys
|
||||
['qmSearchCode', 'filingId'] // Unique keys
|
||||
);
|
||||
|
||||
// Update symbol to track last filings update
|
||||
|
|
@ -88,6 +92,8 @@ export async function updateFilings(
|
|||
recordCount: filingsData.length
|
||||
});
|
||||
|
||||
|
||||
|
||||
this.logger.info('Filings updated successfully', {
|
||||
symbol,
|
||||
filingsCount: filingsData.length
|
||||
|
|
@ -155,16 +161,18 @@ export async function scheduleFilingsUpdates(
|
|||
symbolsQueued: number;
|
||||
errors: number;
|
||||
}> {
|
||||
const { limit = 100, forceUpdate = false } = input;
|
||||
const { limit = 1, forceUpdate = false } = input;
|
||||
|
||||
this.logger.info('Scheduling filings updates', { limit, forceUpdate });
|
||||
|
||||
try {
|
||||
// Get symbols that need updating
|
||||
const staleSymbols = await this.operationRegistry.getStaleSymbols('qm', 'filings_update', {
|
||||
minHoursSinceRun: forceUpdate ? 0 : 24, // Daily for filings
|
||||
limit
|
||||
});
|
||||
// const staleSymbols = await this.operationRegistry.getStaleSymbols('qm', 'filings_update', {
|
||||
// minHoursSinceRun: forceUpdate ? 0 : 24, // Daily for filings
|
||||
// limit
|
||||
// });
|
||||
|
||||
const staleSymbols = ['X:CA']
|
||||
|
||||
if (staleSymbols.length === 0) {
|
||||
this.logger.info('No symbols need filings updates');
|
||||
|
|
@ -181,7 +189,7 @@ export async function scheduleFilingsUpdates(
|
|||
const symbolDocs = await this.mongodb.find('qmSymbols', {
|
||||
qmSearchCode: { $in: staleSymbols }
|
||||
}, {
|
||||
projection: { symbol: 1, symbolId: 1, qmSearchCode: 1 }
|
||||
projection: { qmSearchCode: 1, operations: 1, symbol: 1, exchange: 1 }
|
||||
});
|
||||
|
||||
let queued = 0;
|
||||
|
|
@ -197,11 +205,11 @@ export async function scheduleFilingsUpdates(
|
|||
|
||||
await this.scheduleOperation('update-filings', {
|
||||
symbol: doc.symbol,
|
||||
symbolId: doc.symbolId,
|
||||
qmSearchCode: doc.qmSearchCode
|
||||
exchange: doc.exchange,
|
||||
qmSearchCode: doc.qmSearchCode,
|
||||
lastRecordDate: doc.operations?.filings_update?.lastRecordDate || null,
|
||||
}, {
|
||||
priority: 5, // Lower priority than financial data
|
||||
delay: queued * 2000 // 2 seconds between jobs
|
||||
});
|
||||
|
||||
queued++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue