refactor: centralize provider projections
This commit is contained in:
@@ -5,10 +5,8 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { formatDecimal } from '../../../../common/decimal';
|
||||
import { StructuredLogger } from '../../../../common/logging/structured-logger.service';
|
||||
import { MILLISECONDS_PER_DAY } from '../../../../common/time';
|
||||
import { decimal } from '../../../../integrations/tbank/decimal';
|
||||
import { isTbankErrorCode, TbankErrorCode } from '../../../../integrations/tbank/tbank-error-code';
|
||||
import {
|
||||
TbankAccessService,
|
||||
@@ -26,6 +24,7 @@ import {
|
||||
} from '../domain/candle-coverage';
|
||||
import { InstrumentErrorCode } from '../domain/instrument-error-code';
|
||||
import { CandleRepository } from '../infrastructure/candle.repository';
|
||||
import { toSavedCandle } from '../infrastructure/tbank-candle.mapper';
|
||||
import { CatalogEnrichmentService } from './catalog-enrichment.service';
|
||||
import { timestamp } from './instrument-market';
|
||||
|
||||
@@ -413,17 +412,7 @@ export class CandleService {
|
||||
window.from,
|
||||
new Date(Math.min(window.to.valueOf(), now.valueOf())),
|
||||
);
|
||||
const rows = candles.flatMap((candle) => {
|
||||
const time = timestamp(candle.time);
|
||||
if (!time || !candle.close) throw new Error('Invalid candle response');
|
||||
return [
|
||||
{
|
||||
time,
|
||||
close: formatDecimal(decimal(candle.close)),
|
||||
isComplete: candle.isComplete === true,
|
||||
},
|
||||
];
|
||||
});
|
||||
const rows = candles.map(toSavedCandle);
|
||||
if (!(await this.repository.stage(attempt, window, rows, now))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user