Feature/add asset profile details to activities import (#1552)

* Add asset profile details

* Update changelog
pull/1561/head
Thomas Kaul 2 years ago committed by GitHub
parent 52c7adc266
commit 15357bd5b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Changed the execution time of the asset profile data gathering to every Sunday at lunch time - Changed the execution time of the asset profile data gathering to every Sunday at lunch time
- Improved the activities import by providing asset profile details
- Upgraded `@codewithdan/observable-store` from version `2.2.11` to `2.2.15` - Upgraded `@codewithdan/observable-store` from version `2.2.11` to `2.2.15`
- Upgraded `bull` from version `4.8.5` to `4.10.2` - Upgraded `bull` from version `4.8.5` to `4.10.2`
- Upgraded `countup.js` from version `2.0.7` to `2.3.2` - Upgraded `countup.js` from version `2.0.7` to `2.3.2`

@ -6,6 +6,7 @@ import { DataProviderService } from '@ghostfolio/api/services/data-provider/data
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { OrderWithAccount } from '@ghostfolio/common/types'; import { OrderWithAccount } from '@ghostfolio/common/types';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { SymbolProfile } from '@prisma/client';
import Big from 'big.js'; import Big from 'big.js';
import { endOfToday, isAfter, isSameDay, parseISO } from 'date-fns'; import { endOfToday, isAfter, isSameDay, parseISO } from 'date-fns';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
@ -42,7 +43,7 @@ export class ImportService {
} }
} }
await this.validateActivities({ const assetProfiles = await this.validateActivities({
activitiesDto, activitiesDto,
maxActivitiesToImport, maxActivitiesToImport,
userId userId
@ -104,7 +105,8 @@ export class ImportService {
sectors: null, sectors: null,
symbolMapping: null, symbolMapping: null,
updatedAt: undefined, updatedAt: undefined,
url: null url: null,
...assetProfiles[symbol]
}, },
symbolProfileId: undefined, symbolProfileId: undefined,
updatedAt: new Date() updatedAt: new Date()
@ -172,6 +174,9 @@ export class ImportService {
throw new Error(`Too many activities (${maxActivitiesToImport} at most)`); throw new Error(`Too many activities (${maxActivitiesToImport} at most)`);
} }
const assetProfiles: {
[symbol: string]: Partial<SymbolProfile>;
} = {};
const existingActivities = await this.orderService.orders({ const existingActivities = await this.orderService.orders({
include: { SymbolProfile: true }, include: { SymbolProfile: true },
orderBy: { date: 'desc' }, orderBy: { date: 'desc' },
@ -200,22 +205,28 @@ export class ImportService {
} }
if (dataSource !== 'MANUAL') { if (dataSource !== 'MANUAL') {
const quotes = await this.dataProviderService.getQuotes([ const assetProfile = (
{ dataSource, symbol } await this.dataProviderService.getAssetProfiles([
]); { dataSource, symbol }
])
)?.[symbol];
if (quotes[symbol] === undefined) { if (assetProfile === undefined) {
throw new Error( throw new Error(
`activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")`
); );
} }
if (quotes[symbol].currency !== currency) { if (assetProfile.currency !== currency) {
throw new Error( throw new Error(
`activities.${index}.currency ("${currency}") does not match with "${quotes[symbol].currency}"` `activities.${index}.currency ("${currency}") does not match with "${assetProfile.currency}"`
); );
} }
assetProfiles[symbol] = assetProfile;
} }
} }
return assetProfiles;
} }
} }

@ -154,11 +154,7 @@ export class YahooFinanceService implements DataProviderInterface {
response.url = url; response.url = url;
} }
} catch (error) { } catch (error) {
throw new Error( Logger.error(error, 'YahooFinanceService');
`Could not get asset profile for ${aSymbol} (${this.getName()}): [${
error.name
}] ${error.message}`
);
} }
return response; return response;

Loading…
Cancel
Save