fixed up more type issues
This commit is contained in:
parent
3a10560de4
commit
87037e013f
9 changed files with 210 additions and 52 deletions
|
|
@ -4,7 +4,8 @@
|
|||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { MasterExchange } from '@stock-bot/mongodb-client';
|
||||
import type { HandlerConfigWithSchedule } from '@stock-bot/queue';
|
||||
import { handlerRegistry } from '@stock-bot/queue';
|
||||
import { createJobHandler, handlerRegistry } from '@stock-bot/queue';
|
||||
import type { IBExchange } from '../types/exchange.types';
|
||||
|
||||
const logger = getLogger('exchange-sync');
|
||||
|
||||
|
|
@ -15,16 +16,16 @@ export function initializeExchangeSyncProvider() {
|
|||
name: 'exchange-sync',
|
||||
|
||||
operations: {
|
||||
'sync-ib-exchanges': async _payload => {
|
||||
'sync-ib-exchanges': createJobHandler(async () => {
|
||||
logger.info('Syncing IB exchanges to master table');
|
||||
return await syncIBExchanges();
|
||||
},
|
||||
}),
|
||||
|
||||
'get-master-exchange': async (payload: { masterExchangeId: string }) => {
|
||||
'get-master-exchange': createJobHandler(async (payload: { masterExchangeId: string }) => {
|
||||
logger.debug('Getting master exchange details', payload);
|
||||
const exchange = await getMasterExchangeDetails(payload.masterExchangeId);
|
||||
return { exchange, ...payload };
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
scheduledJobs: [
|
||||
|
|
@ -60,7 +61,7 @@ async function syncIBExchanges(): Promise<{ syncedCount: number; totalExchanges:
|
|||
|
||||
// Filter by country code US and CA
|
||||
const ibExchanges = await db
|
||||
.collection('ibExchanges')
|
||||
.collection<IBExchange>('ibExchanges')
|
||||
.find({
|
||||
country_code: { $in: ['US', 'CA'] },
|
||||
})
|
||||
|
|
@ -99,14 +100,7 @@ async function syncIBExchanges(): Promise<{ syncedCount: number; totalExchanges:
|
|||
/**
|
||||
* Create or update master exchange record 1:1 from IB exchange
|
||||
*/
|
||||
async function createOrUpdateMasterExchange(ibExchange: {
|
||||
id?: string;
|
||||
name?: string;
|
||||
code?: string;
|
||||
country_code?: string;
|
||||
currency?: string;
|
||||
_id?: unknown;
|
||||
}): Promise<void> {
|
||||
async function createOrUpdateMasterExchange(ibExchange: IBExchange): Promise<void> {
|
||||
const { connectMongoDB, getDatabase } = await import('@stock-bot/mongodb-client');
|
||||
|
||||
await connectMongoDB();
|
||||
|
|
@ -191,11 +185,7 @@ async function getMasterExchangeDetails(masterExchangeId: string): Promise<Maste
|
|||
/**
|
||||
* Generate master exchange ID from IB exchange
|
||||
*/
|
||||
function generateMasterExchangeId(ibExchange: {
|
||||
name?: string;
|
||||
code?: string;
|
||||
id?: string;
|
||||
}): string {
|
||||
function generateMasterExchangeId(ibExchange: IBExchange): string {
|
||||
// Use code if available, otherwise use ID, otherwise generate from name
|
||||
if (ibExchange.code) {
|
||||
return ibExchange.code.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
||||
|
|
@ -220,7 +210,7 @@ function generateMasterExchangeId(ibExchange: {
|
|||
/**
|
||||
* Generate aliases for the exchange
|
||||
*/
|
||||
function generateAliases(ibExchange: { name?: string; code?: string }): string[] {
|
||||
function generateAliases(ibExchange: IBExchange): string[] {
|
||||
const aliases: string[] = [];
|
||||
|
||||
if (ibExchange.name && ibExchange.name.includes(' ')) {
|
||||
|
|
@ -244,7 +234,7 @@ function generateAliases(ibExchange: { name?: string; code?: string }): string[]
|
|||
/**
|
||||
* Infer timezone from exchange name/location
|
||||
*/
|
||||
function inferTimezone(ibExchange: { name?: string }): string {
|
||||
function inferTimezone(ibExchange: IBExchange): string {
|
||||
if (!ibExchange.name) {
|
||||
return 'UTC';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue