getting aligned and refactored
This commit is contained in:
parent
60ada5f6a3
commit
a3459f5865
16 changed files with 296 additions and 273 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { MasterExchange } from '@stock-bot/mongodb';
|
||||
import { getMongoDBClient } from '../../../clients';
|
||||
import type { IServiceContainer } from '@stock-bot/handlers';
|
||||
import type { JobPayload } from '../../../types/job-payloads';
|
||||
|
||||
const logger = getLogger('sync-ib-exchanges');
|
||||
|
|
@ -15,12 +16,13 @@ interface IBExchange {
|
|||
}
|
||||
|
||||
export async function syncIBExchanges(
|
||||
payload: JobPayload
|
||||
payload: JobPayload,
|
||||
container: IServiceContainer
|
||||
): Promise<{ syncedCount: number; totalExchanges: number }> {
|
||||
logger.info('Syncing IB exchanges from database...');
|
||||
|
||||
try {
|
||||
const mongoClient = getMongoDBClient();
|
||||
const mongoClient = container.mongodb;
|
||||
const db = mongoClient.getDatabase();
|
||||
|
||||
// Filter by country code US and CA
|
||||
|
|
@ -37,7 +39,7 @@ export async function syncIBExchanges(
|
|||
|
||||
for (const exchange of ibExchanges) {
|
||||
try {
|
||||
await createOrUpdateMasterExchange(exchange);
|
||||
await createOrUpdateMasterExchange(exchange, container);
|
||||
syncedCount++;
|
||||
|
||||
logger.debug('Synced IB exchange', {
|
||||
|
|
@ -64,8 +66,8 @@ export async function syncIBExchanges(
|
|||
/**
|
||||
* Create or update master exchange record 1:1 from IB exchange
|
||||
*/
|
||||
async function createOrUpdateMasterExchange(ibExchange: IBExchange): Promise<void> {
|
||||
const mongoClient = getMongoDBClient();
|
||||
async function createOrUpdateMasterExchange(ibExchange: IBExchange, container: IServiceContainer): Promise<void> {
|
||||
const mongoClient = container.mongodb;
|
||||
const db = mongoClient.getDatabase();
|
||||
const collection = db.collection<MasterExchange>('masterExchanges');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue