Feature/start eliminating data source from order (#622)
* Start eliminating dataSource from order * Update changelog
This commit is contained in:
parent
b2b3fde80e
commit
7df53896f3
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Start eliminating `dataSource` from activity
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed the support for multiple accounts with the same name
|
- Fixed the support for multiple accounts with the same name
|
||||||
|
@ -85,19 +85,6 @@ describe('CurrentRateService', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getValue', async () => {
|
|
||||||
expect(
|
|
||||||
await currentRateService.getValue({
|
|
||||||
currency: 'USD',
|
|
||||||
date: new Date(Date.UTC(2020, 0, 1, 0, 0, 0)),
|
|
||||||
symbol: 'AMZN',
|
|
||||||
userCurrency: 'CHF'
|
|
||||||
})
|
|
||||||
).toMatchObject({
|
|
||||||
marketPrice: 1847.839966
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getValues', async () => {
|
it('getValues', async () => {
|
||||||
expect(
|
expect(
|
||||||
await currentRateService.getValues({
|
await currentRateService.getValues({
|
||||||
|
@ -7,7 +7,6 @@ import { isBefore, isToday } from 'date-fns';
|
|||||||
import { flatten } from 'lodash';
|
import { flatten } from 'lodash';
|
||||||
|
|
||||||
import { GetValueObject } from './interfaces/get-value-object.interface';
|
import { GetValueObject } from './interfaces/get-value-object.interface';
|
||||||
import { GetValueParams } from './interfaces/get-value-params.interface';
|
|
||||||
import { GetValuesParams } from './interfaces/get-values-params.interface';
|
import { GetValuesParams } from './interfaces/get-values-params.interface';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -18,46 +17,6 @@ export class CurrentRateService {
|
|||||||
private readonly marketDataService: MarketDataService
|
private readonly marketDataService: MarketDataService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async getValue({
|
|
||||||
currency,
|
|
||||||
date,
|
|
||||||
symbol,
|
|
||||||
userCurrency
|
|
||||||
}: GetValueParams): Promise<GetValueObject> {
|
|
||||||
if (isToday(date)) {
|
|
||||||
const dataProviderResult = await this.dataProviderService.get([
|
|
||||||
{
|
|
||||||
symbol,
|
|
||||||
dataSource: this.dataProviderService.getPrimaryDataSource()
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
return {
|
|
||||||
symbol,
|
|
||||||
date: resetHours(date),
|
|
||||||
marketPrice: dataProviderResult?.[symbol]?.marketPrice ?? 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const marketData = await this.marketDataService.get({
|
|
||||||
date,
|
|
||||||
symbol
|
|
||||||
});
|
|
||||||
|
|
||||||
if (marketData) {
|
|
||||||
return {
|
|
||||||
date: marketData.date,
|
|
||||||
marketPrice: this.exchangeRateDataService.toCurrency(
|
|
||||||
marketData.marketPrice,
|
|
||||||
currency,
|
|
||||||
userCurrency
|
|
||||||
),
|
|
||||||
symbol: marketData.symbol
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Value not found for ${symbol} at ${resetHours(date)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getValues({
|
public async getValues({
|
||||||
currencies,
|
currencies,
|
||||||
dataGatheringItems,
|
dataGatheringItems,
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
export interface GetValueParams {
|
|
||||||
currency: string;
|
|
||||||
date: Date;
|
|
||||||
symbol: string;
|
|
||||||
userCurrency: string;
|
|
||||||
}
|
|
@ -1,17 +1,9 @@
|
|||||||
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
|
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
|
||||||
import { DataSource } from '@prisma/client';
|
import { DataSource } from '@prisma/client';
|
||||||
import Big from 'big.js';
|
import Big from 'big.js';
|
||||||
import {
|
import { addDays, endOfDay, format, isBefore, isSameDay } from 'date-fns';
|
||||||
addDays,
|
|
||||||
differenceInCalendarDays,
|
|
||||||
endOfDay,
|
|
||||||
format,
|
|
||||||
isBefore,
|
|
||||||
isSameDay
|
|
||||||
} from 'date-fns';
|
|
||||||
|
|
||||||
import { CurrentRateService } from './current-rate.service';
|
import { CurrentRateService } from './current-rate.service';
|
||||||
import { GetValueParams } from './interfaces/get-value-params.interface';
|
|
||||||
import { GetValuesParams } from './interfaces/get-values-params.interface';
|
import { GetValuesParams } from './interfaces/get-values-params.interface';
|
||||||
import { PortfolioOrder } from './interfaces/portfolio-order.interface';
|
import { PortfolioOrder } from './interfaces/portfolio-order.interface';
|
||||||
import { TimelinePeriod } from './interfaces/timeline-period.interface';
|
import { TimelinePeriod } from './interfaces/timeline-period.interface';
|
||||||
@ -275,9 +267,6 @@ jest.mock('./current-rate.service', () => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
CurrentRateService: jest.fn().mockImplementation(() => {
|
CurrentRateService: jest.fn().mockImplementation(() => {
|
||||||
return {
|
return {
|
||||||
getValue: ({ date, symbol }: GetValueParams) => {
|
|
||||||
return Promise.resolve(mockGetValue(symbol, date));
|
|
||||||
},
|
|
||||||
getValues: ({ dataGatheringItems, dateQuery }: GetValuesParams) => {
|
getValues: ({ dataGatheringItems, dateQuery }: GetValuesParams) => {
|
||||||
const result = [];
|
const result = [];
|
||||||
if (dateQuery.lt) {
|
if (dateQuery.lt) {
|
||||||
|
@ -428,7 +428,7 @@ export class PortfolioService {
|
|||||||
})
|
})
|
||||||
.map((order) => ({
|
.map((order) => ({
|
||||||
currency: order.currency,
|
currency: order.currency,
|
||||||
dataSource: order.dataSource,
|
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
|
||||||
date: format(order.date, DATE_FORMAT),
|
date: format(order.date, DATE_FORMAT),
|
||||||
fee: new Big(order.fee),
|
fee: new Big(order.fee),
|
||||||
name: order.SymbolProfile?.name,
|
name: order.SymbolProfile?.name,
|
||||||
@ -1038,7 +1038,7 @@ export class PortfolioService {
|
|||||||
const userCurrency = this.request.user?.Settings?.currency ?? baseCurrency;
|
const userCurrency = this.request.user?.Settings?.currency ?? baseCurrency;
|
||||||
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
|
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
|
||||||
currency: order.currency,
|
currency: order.currency,
|
||||||
dataSource: order.dataSource,
|
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
|
||||||
date: format(order.date, DATE_FORMAT),
|
date: format(order.date, DATE_FORMAT),
|
||||||
fee: new Big(
|
fee: new Big(
|
||||||
this.exchangeRateDataService.toCurrency(
|
this.exchangeRateDataService.toCurrency(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user