Browse Source

Added CurrentRateService.getValues alternative based on db decimation

pull/3139/head
helgehatt 1 year ago
parent
commit
c90d9ee6ce
  1. 29
      apps/api/src/app/portfolio/current-rate.service.ts
  2. 8
      apps/api/src/app/portfolio/interfaces/get-value-range-params.interface.ts

29
apps/api/src/app/portfolio/current-rate.service.ts

@ -15,6 +15,7 @@ import { isBefore, isToday } from 'date-fns';
import { flatten, isEmpty, uniqBy } from 'lodash';
import { GetValueObject } from './interfaces/get-value-object.interface';
import { GetValueRangeParams } from './interfaces/get-value-range-params.interface';
import { GetValuesObject } from './interfaces/get-values-object.interface';
import { GetValuesParams } from './interfaces/get-values-params.interface';
@ -163,6 +164,34 @@ export class CurrentRateService {
return response;
}
public async getValueRange({
dataGatheringItems,
dateRange
}: GetValueRangeParams): Promise<GetValuesObject> {
const values = await this.marketDataService
.getDecimatedRange({
dateRange,
dataSources: dataGatheringItems.map((x) => x.dataSource),
symbols: dataGatheringItems.map((x) => x.symbol)
})
.then((data) => {
return data.map(({ dataSource, date, marketPrice, symbol }) => {
return {
dataSource,
date,
marketPrice,
symbol
};
});
});
return {
dataProviderInfos: [],
errors: [],
values
};
}
private containsToday(dates: Date[]): boolean {
for (const date of dates) {
if (isToday(date)) {

8
apps/api/src/app/portfolio/interfaces/get-value-range-params.interface.ts

@ -0,0 +1,8 @@
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
import { DateRange } from './date-range.interface';
export interface GetValueRangeParams {
dataGatheringItems: IDataGatheringItem[];
dateRange: DateRange;
}
Loading…
Cancel
Save