Browse Source
Feature/start eliminating data source from order (#622)
* Start eliminating dataSource from order
* Update changelog
pull/625/head
Thomas Kaul
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
7 additions and
74 deletions
-
CHANGELOG.md
-
apps/api/src/app/portfolio/current-rate.service.spec.ts
-
apps/api/src/app/portfolio/current-rate.service.ts
-
apps/api/src/app/portfolio/interfaces/get-value-params.interface.ts
-
apps/api/src/app/portfolio/portfolio-calculator.spec.ts
-
apps/api/src/app/portfolio/portfolio.service.ts
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
|
|
|
|
## Unreleased |
|
|
|
|
|
|
|
### Changed |
|
|
|
|
|
|
|
- Start eliminating `dataSource` from activity |
|
|
|
|
|
|
|
### Fixed |
|
|
|
|
|
|
|
- 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 () => { |
|
|
|
expect( |
|
|
|
await currentRateService.getValues({ |
|
|
|
|
|
@ -7,7 +7,6 @@ import { isBefore, isToday } from 'date-fns'; |
|
|
|
import { flatten } from 'lodash'; |
|
|
|
|
|
|
|
import { GetValueObject } from './interfaces/get-value-object.interface'; |
|
|
|
import { GetValueParams } from './interfaces/get-value-params.interface'; |
|
|
|
import { GetValuesParams } from './interfaces/get-values-params.interface'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
@ -18,46 +17,6 @@ export class CurrentRateService { |
|
|
|
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({ |
|
|
|
currencies, |
|
|
|
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 { DataSource } from '@prisma/client'; |
|
|
|
import Big from 'big.js'; |
|
|
|
import { |
|
|
|
addDays, |
|
|
|
differenceInCalendarDays, |
|
|
|
endOfDay, |
|
|
|
format, |
|
|
|
isBefore, |
|
|
|
isSameDay |
|
|
|
} from 'date-fns'; |
|
|
|
import { addDays, endOfDay, format, isBefore, isSameDay } from 'date-fns'; |
|
|
|
|
|
|
|
import { CurrentRateService } from './current-rate.service'; |
|
|
|
import { GetValueParams } from './interfaces/get-value-params.interface'; |
|
|
|
import { GetValuesParams } from './interfaces/get-values-params.interface'; |
|
|
|
import { PortfolioOrder } from './interfaces/portfolio-order.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
|
|
|
|
CurrentRateService: jest.fn().mockImplementation(() => { |
|
|
|
return { |
|
|
|
getValue: ({ date, symbol }: GetValueParams) => { |
|
|
|
return Promise.resolve(mockGetValue(symbol, date)); |
|
|
|
}, |
|
|
|
getValues: ({ dataGatheringItems, dateQuery }: GetValuesParams) => { |
|
|
|
const result = []; |
|
|
|
if (dateQuery.lt) { |
|
|
|
|
|
@ -428,7 +428,7 @@ export class PortfolioService { |
|
|
|
}) |
|
|
|
.map((order) => ({ |
|
|
|
currency: order.currency, |
|
|
|
dataSource: order.dataSource, |
|
|
|
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource, |
|
|
|
date: format(order.date, DATE_FORMAT), |
|
|
|
fee: new Big(order.fee), |
|
|
|
name: order.SymbolProfile?.name, |
|
|
@ -1038,7 +1038,7 @@ export class PortfolioService { |
|
|
|
const userCurrency = this.request.user?.Settings?.currency ?? baseCurrency; |
|
|
|
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ |
|
|
|
currency: order.currency, |
|
|
|
dataSource: order.dataSource, |
|
|
|
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource, |
|
|
|
date: format(order.date, DATE_FORMAT), |
|
|
|
fee: new Big( |
|
|
|
this.exchangeRateDataService.toCurrency( |
|
|
|