import { BaseHandler, Handler, Operation, ScheduledOperation } from '@stock-bot/handlers'; import type { IServiceContainer } from '@stock-bot/services'; import { clearPostgreSQLData } from './operations/clear-postgresql-data.operations'; import { getExchangeStats } from './operations/exchange-stats.operations'; import { getProviderMappingStats } from './operations/provider-mapping-stats.operations'; import { syncQMExchanges } from './operations/qm-exchanges.operations'; import { syncAllExchanges } from './operations/sync-all-exchanges.operations'; import { syncQMProviderMappings } from './operations/sync-qm-provider-mappings.operations'; @Handler('exchanges') class ExchangesHandler extends BaseHandler { constructor(services: IServiceContainer) { super(services); } /** * Sync all exchanges - weekly full sync */ @Operation('sync-all-exchanges') @ScheduledOperation('sync-all-exchanges', '0 0 * * 0', { priority: 10, description: 'Weekly full exchange sync on Sunday at midnight', }) async syncAllExchanges(payload?: { clearFirst?: boolean }): Promise { const finalPayload = payload ?? {}; this.log('info', 'Starting sync of all exchanges', finalPayload); return syncAllExchanges(finalPayload, this); } /** * Sync exchanges from QuestionsAndMethods */ @Operation('sync-qm-exchanges') @ScheduledOperation('sync-qm-exchanges', '0 1 * * *', { priority: 5, description: 'Daily sync of QM exchanges at 1 AM', }) async syncQMExchanges(): Promise { this.log('info', 'Starting QM exchanges sync...'); return syncQMExchanges({}, this); } /** * Sync provider mappings from QuestionsAndMethods */ @Operation('sync-qm-provider-mappings') @ScheduledOperation('sync-qm-provider-mappings', '0 3 * * *', { priority: 7, description: 'Daily sync of QM provider mappings at 3 AM', }) async syncQMProviderMappings(): Promise { this.log('info', 'Starting QM provider mappings sync...'); return syncQMProviderMappings({}, this); } /** * Clear PostgreSQL data - maintenance operation */ @Operation('clear-postgresql-data') async clearPostgreSQLData(payload: { type?: 'exchanges' | 'provider_mappings' | 'all'; confirmation?: string; }): Promise { this.log('warn', 'Clearing PostgreSQL data', payload); return clearPostgreSQLData(payload, this); } /** * Get exchange statistics */ @Operation('get-exchange-stats') async getExchangeStats(): Promise { this.log('info', 'Getting exchange statistics...'); return getExchangeStats({}, this); } /** * Get provider mapping statistics */ @Operation('get-provider-mapping-stats') async getProviderMappingStats(): Promise { this.log('info', 'Getting provider mapping statistics...'); return getProviderMappingStats({}, this); } } export { ExchangesHandler };