|
@ -4,7 +4,10 @@ import { DataProviderService } from '@ghostfolio/api/services/data-provider/data |
|
|
import { MarketDataService } from '@ghostfolio/api/services/market-data.service'; |
|
|
import { MarketDataService } from '@ghostfolio/api/services/market-data.service'; |
|
|
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|
|
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service'; |
|
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service'; |
|
|
import { PROPERTY_BENCHMARKS } from '@ghostfolio/common/config'; |
|
|
import { |
|
|
|
|
|
MAX_CHART_ITEMS, |
|
|
|
|
|
PROPERTY_BENCHMARKS |
|
|
|
|
|
} from '@ghostfolio/common/config'; |
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper'; |
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper'; |
|
|
import { |
|
|
import { |
|
|
BenchmarkMarketDataDetails, |
|
|
BenchmarkMarketDataDetails, |
|
@ -16,7 +19,6 @@ import { SymbolProfile } from '@prisma/client'; |
|
|
import Big from 'big.js'; |
|
|
import Big from 'big.js'; |
|
|
import { format } from 'date-fns'; |
|
|
import { format } from 'date-fns'; |
|
|
import ms from 'ms'; |
|
|
import ms from 'ms'; |
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class BenchmarkService { |
|
|
export class BenchmarkService { |
|
@ -157,16 +159,18 @@ export class BenchmarkService { |
|
|
}) |
|
|
}) |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
marketDataItems.push({ |
|
|
const step = Math.round( |
|
|
...currentSymbolItem, |
|
|
marketDataItems.length / Math.min(marketDataItems.length, MAX_CHART_ITEMS) |
|
|
createdAt: new Date(), |
|
|
); |
|
|
date: new Date(), |
|
|
|
|
|
id: uuidv4() |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const marketPriceAtStartDate = marketDataItems?.[0]?.marketPrice ?? 0; |
|
|
const marketPriceAtStartDate = marketDataItems?.[0]?.marketPrice ?? 0; |
|
|
return { |
|
|
return { |
|
|
marketData: marketDataItems.map((marketDataItem) => { |
|
|
marketData: [ |
|
|
|
|
|
...marketDataItems |
|
|
|
|
|
.filter((marketDataItem, index) => { |
|
|
|
|
|
return index % step === 0; |
|
|
|
|
|
}) |
|
|
|
|
|
.map((marketDataItem) => { |
|
|
return { |
|
|
return { |
|
|
date: format(marketDataItem.date, DATE_FORMAT), |
|
|
date: format(marketDataItem.date, DATE_FORMAT), |
|
|
value: |
|
|
value: |
|
@ -177,7 +181,16 @@ export class BenchmarkService { |
|
|
marketDataItem.marketPrice |
|
|
marketDataItem.marketPrice |
|
|
) * 100 |
|
|
) * 100 |
|
|
}; |
|
|
}; |
|
|
}) |
|
|
}), |
|
|
|
|
|
{ |
|
|
|
|
|
date: format(new Date(), DATE_FORMAT), |
|
|
|
|
|
value: |
|
|
|
|
|
this.calculateChangeInPercentage( |
|
|
|
|
|
marketPriceAtStartDate, |
|
|
|
|
|
currentSymbolItem.marketPrice |
|
|
|
|
|
) * 100 |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|