stock-bot/apps/stock/data-ingestion/src/handlers/tt/tt.handler.ts
2026-04-04 12:40:49 -04:00

48 lines
1.2 KiB
TypeScript

import {
BaseHandler,
Handler,
ScheduledOperation,
} from '@stock-bot/handlers';
import type { DataIngestionServices } from '../../types';
import { importData } from './actions';
@Handler('tt')
export class TtHandler extends BaseHandler<DataIngestionServices> {
constructor(services: any) {
super(services);
}
async onInit(): Promise<void> {
if (!this.mongodb) return;
const indexes = [
{
indexSpec: { contract: 1, date: 1 },
options: { name: 'contract_date_unique_idx', unique: true, background: true },
},
{
indexSpec: { symbol: 1, date: 1 },
options: { name: 'symbol_date_idx', background: true },
},
{
indexSpec: { date: 1 },
options: { name: 'date_idx', background: true },
},
];
for (const index of indexes) {
try {
await this.mongodb.createIndex('ttFutures', index.indexSpec, index.options);
} catch (error) {
this.logger.debug(`ttFutures index ${index.options.name} may already exist:`, error);
}
}
}
@ScheduledOperation('tt-import', '0 0 * * 0', {
priority: 5,
description: 'Import TurtleTrader futures data',
immediately: true,
})
importData = importData;
}