Feature/refactor data gathering items (#4032)

* Refactoring
pull/4033/head
Thomas Kaul 2 weeks ago committed by GitHub
parent 04d5416c6d
commit 190bb4b6fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -52,27 +52,24 @@ export class CurrentRateService {
.then((dataResultProvider) => {
const result: GetValueObject[] = [];
for (const dataGatheringItem of dataGatheringItems) {
if (
dataResultProvider?.[dataGatheringItem.symbol]?.dataProviderInfo
) {
for (const { dataSource, symbol } of dataGatheringItems) {
if (dataResultProvider?.[symbol]?.dataProviderInfo) {
dataProviderInfos.push(
dataResultProvider[dataGatheringItem.symbol].dataProviderInfo
dataResultProvider[symbol].dataProviderInfo
);
}
if (dataResultProvider?.[dataGatheringItem.symbol]?.marketPrice) {
if (dataResultProvider?.[symbol]?.marketPrice) {
result.push({
dataSource: dataGatheringItem.dataSource,
dataSource,
symbol,
date: today,
marketPrice:
dataResultProvider?.[dataGatheringItem.symbol]?.marketPrice,
symbol: dataGatheringItem.symbol
marketPrice: dataResultProvider?.[symbol]?.marketPrice
});
} else {
quoteErrors.push({
dataSource: dataGatheringItem.dataSource,
symbol: dataGatheringItem.symbol
dataSource,
symbol
});
}
}

@ -413,15 +413,16 @@ export class PortfolioService {
);
}
const dataGatheringItems = positions.map(({ dataSource, symbol }) => {
const assetProfileIdentifiers = positions.map(({ dataSource, symbol }) => {
return {
dataSource,
symbol
};
});
const symbolProfiles =
await this.symbolProfileService.getSymbolProfiles(dataGatheringItems);
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
assetProfileIdentifiers
);
const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {};
for (const symbolProfile of symbolProfiles) {
@ -848,7 +849,7 @@ export class PortfolioService {
if (isEmpty(historicalData)) {
try {
historicalData = await this.dataProviderService.getHistoricalRaw({
dataGatheringItems: [
assetProfileIdentifiers: [
{ dataSource: DataSource.YAHOO, symbol: aSymbol }
],
from: portfolioStart,
@ -953,7 +954,7 @@ export class PortfolioService {
return !quantity.eq(0);
});
const dataGatheringItems = positions.map(({ dataSource, symbol }) => {
const assetProfileIdentifiers = positions.map(({ dataSource, symbol }) => {
return {
dataSource,
symbol
@ -961,7 +962,10 @@ export class PortfolioService {
});
const [dataProviderResponses, symbolProfiles] = await Promise.all([
this.dataProviderService.getQuotes({ user, items: dataGatheringItems }),
this.dataProviderService.getQuotes({
user,
items: assetProfileIdentifiers
}),
this.symbolProfileService.getSymbolProfiles(
positions.map(({ dataSource, symbol }) => {
return { dataSource, symbol };

@ -86,7 +86,7 @@ export class SymbolService {
try {
historicalData = await this.dataProviderService.getHistoricalRaw({
dataGatheringItems: [{ dataSource, symbol }],
assetProfileIdentifiers: [{ dataSource, symbol }],
from: date,
to: date
});

@ -91,11 +91,11 @@ export class DataProviderService {
const promises = [];
for (const [dataSource, dataGatheringItems] of Object.entries(
for (const [dataSource, assetProfileIdentifiers] of Object.entries(
itemsGroupedByDataSource
)) {
const symbols = dataGatheringItems.map((dataGatheringItem) => {
return dataGatheringItem.symbol;
const symbols = assetProfileIdentifiers.map(({ symbol }) => {
return symbol;
});
for (const symbol of symbols) {
@ -242,11 +242,11 @@ export class DataProviderService {
}
public async getHistoricalRaw({
dataGatheringItems,
assetProfileIdentifiers,
from,
to
}: {
dataGatheringItems: AssetProfileIdentifier[];
assetProfileIdentifiers: AssetProfileIdentifier[];
from: Date;
to: Date;
}): Promise<{
@ -255,25 +255,32 @@ export class DataProviderService {
for (const { currency, rootCurrency } of DERIVED_CURRENCIES) {
if (
this.hasCurrency({
dataGatheringItems,
assetProfileIdentifiers,
currency: `${DEFAULT_CURRENCY}${currency}`
})
) {
// Skip derived currency
dataGatheringItems = dataGatheringItems.filter(({ symbol }) => {
return symbol !== `${DEFAULT_CURRENCY}${currency}`;
});
assetProfileIdentifiers = assetProfileIdentifiers.filter(
({ symbol }) => {
return symbol !== `${DEFAULT_CURRENCY}${currency}`;
}
);
// Add root currency
dataGatheringItems.push({
assetProfileIdentifiers.push({
dataSource: this.getDataSourceForExchangeRates(),
symbol: `${DEFAULT_CURRENCY}${rootCurrency}`
});
}
}
dataGatheringItems = uniqWith(dataGatheringItems, (obj1, obj2) => {
return obj1.dataSource === obj2.dataSource && obj1.symbol === obj2.symbol;
});
assetProfileIdentifiers = uniqWith(
assetProfileIdentifiers,
(obj1, obj2) => {
return (
obj1.dataSource === obj2.dataSource && obj1.symbol === obj2.symbol
);
}
);
const result: {
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
@ -283,7 +290,7 @@ export class DataProviderService {
data: { [date: string]: IDataProviderHistoricalResponse };
symbol: string;
}>[] = [];
for (const { dataSource, symbol } of dataGatheringItems) {
for (const { dataSource, symbol } of assetProfileIdentifiers) {
const dataProvider = this.getDataProvider(dataSource);
if (dataProvider.canHandle(symbol)) {
if (symbol === `${DEFAULT_CURRENCY}USX`) {
@ -418,7 +425,7 @@ export class DataProviderService {
const promises: Promise<any>[] = [];
for (const [dataSource, dataGatheringItems] of Object.entries(
for (const [dataSource, assetProfileIdentifiers] of Object.entries(
itemsGroupedByDataSource
)) {
const dataProvider = this.getDataProvider(DataSource[dataSource]);
@ -431,7 +438,7 @@ export class DataProviderService {
continue;
}
const symbols = dataGatheringItems
const symbols = assetProfileIdentifiers
.filter(({ symbol }) => {
return !isDerivedCurrency(getCurrencyFromSymbol(symbol));
})
@ -634,13 +641,13 @@ export class DataProviderService {
}
private hasCurrency({
currency,
dataGatheringItems
assetProfileIdentifiers,
currency
}: {
assetProfileIdentifiers: AssetProfileIdentifier[];
currency: string;
dataGatheringItems: AssetProfileIdentifier[];
}) {
return dataGatheringItems.some(({ dataSource, symbol }) => {
return assetProfileIdentifiers.some(({ dataSource, symbol }) => {
return (
dataSource === this.getDataSourceForExchangeRates() &&
symbol === currency

@ -89,7 +89,7 @@ export class DataGatheringProcessor {
);
const historicalData = await this.dataProviderService.getHistoricalRaw({
dataGatheringItems: [{ dataSource, symbol }],
assetProfileIdentifiers: [{ dataSource, symbol }],
from: currentDate,
to: new Date()
});

@ -122,7 +122,7 @@ export class DataGatheringService {
}) {
try {
const historicalData = await this.dataProviderService.getHistoricalRaw({
dataGatheringItems: [{ dataSource, symbol }],
assetProfileIdentifiers: [{ dataSource, symbol }],
from: date,
to: date
});

Loading…
Cancel
Save