fixed fetch and initial work on ceo

This commit is contained in:
Boki 2025-06-22 11:47:16 -04:00
parent a63ccc96f5
commit 7abc446671
4 changed files with 135 additions and 59 deletions

View file

@ -1,7 +1,6 @@
import {
BaseHandler,
Handler,
Operation,
ScheduledOperation,
type ExecutionContext,
type IServiceContainer
@ -29,25 +28,47 @@ export class CeoHandler extends BaseHandler {
}
this.logger.info(`Fetching CEO channels for page ${page} with proxy ${proxy}`);
const result = fetch('https://proxy-detection.stare.gg/all?api_key=bd406bf53ddc6abe1d9de5907830a955', {
const response = await fetch('https://api.ceo.ca/api/home?exchange=all&sort_by=symbol&sector=All&tab=companies&page='+page, {
method: 'GET',
proxy: proxy,
headers: {
'User-Agent': getRandomUserAgent()
}
})
// const result = fetch('https://api.ceo.ca/api/home?exchange=all&sort_by=symbol&sector=All&tab=companies&page=1')
// Call the session maintenance action
// const { checkSessions } = await import('./actions/session.action');
// return await checkSessions(this);
return ;
}
const results = await response.json();
const channels = results.channel_categories[0].channels;
const totalChannels = results.channel_categories[0].total_channels;
const totalPages = Math.ceil(totalChannels / channels.length);
const exchanges: {exchange: string, countryCode: string}[] = []
const symbols = channels.map((channel: any) =>{
// check if exchange is in the exchanges array object
if(!exchanges.find((e: any) => e.exchange === channel.exchange)) {
exchanges.push({
exchange: channel.exchange,
countryCode: 'CA'
});
}
const details = channel.company_details || {};
return {
symbol: channel.symbol,
exchange: channel.exchange,
name: channel.title,
type: channel.type,
ceoId: channel.channel,
marketCap: details.market_cap,
volumeRatio: details.volume_ratio,
avgVolume: details.avg_volume,
stockType: details.stock_type,
issueType: details.issue_type,
sharesOutstanding: details.shares_outstanding,
float: details.float,
}
})
@Operation('create-session')
async createSession(input: unknown, context: ExecutionContext): Promise<unknown> {
// // Call the individual session creation action
// const { createSingleSession } = await import('./actions/session.action');
// return await createSingleSession(this, input);
return ;
await this.mongodb.batchUpsert('ceoSymbols', symbols, ['symbol', 'exchange']);
await this.mongodb.batchUpsert('ceoExchanges', exchanges, ['exchange']);
this.logger.info(`Fetched CEO channels for page ${page}/${totalPages}`);
return { page, totalPages };
}
}