|
|
|
@ -107,33 +107,46 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { |
|
|
|
response: Partial<SymbolProfile>; |
|
|
|
symbol: string; |
|
|
|
}): Promise<Partial<SymbolProfile>> { |
|
|
|
if (response.dataSource !== 'YAHOO' && !response.isin) { |
|
|
|
const { isin } = response; |
|
|
|
|
|
|
|
if (response.dataSource !== 'YAHOO' && !isin) { |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
let yahooSymbol: string; |
|
|
|
let yahooSymbol: string | undefined; |
|
|
|
|
|
|
|
if (response.dataSource === 'YAHOO') { |
|
|
|
yahooSymbol = symbol; |
|
|
|
} else { |
|
|
|
const { quotes } = await this.yahooFinance.search(response.isin); |
|
|
|
yahooSymbol = quotes[0].symbol as string; |
|
|
|
} |
|
|
|
} else if (isin) { |
|
|
|
const { quotes } = await this.yahooFinance.search(isin); |
|
|
|
const firstQuote = quotes?.[0]; |
|
|
|
|
|
|
|
const { countries, sectors, url } = |
|
|
|
await this.getAssetProfile(yahooSymbol); |
|
|
|
|
|
|
|
if ((countries as unknown as Prisma.JsonArray)?.length > 0) { |
|
|
|
response.countries = countries; |
|
|
|
if (firstQuote?.isYahooFinance) { |
|
|
|
yahooSymbol = firstQuote.symbol; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ((sectors as unknown as Prisma.JsonArray)?.length > 0) { |
|
|
|
response.sectors = sectors; |
|
|
|
if (!yahooSymbol) { |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
if (url) { |
|
|
|
response.url = url; |
|
|
|
const assetProfile = await this.getAssetProfile(yahooSymbol); |
|
|
|
|
|
|
|
if (assetProfile) { |
|
|
|
const { countries, sectors, url } = assetProfile; |
|
|
|
|
|
|
|
if ((countries as unknown as Prisma.JsonArray)?.length > 0) { |
|
|
|
response.countries = countries; |
|
|
|
} |
|
|
|
|
|
|
|
if ((sectors as unknown as Prisma.JsonArray)?.length > 0) { |
|
|
|
response.sectors = sectors; |
|
|
|
} |
|
|
|
|
|
|
|
if (url) { |
|
|
|
response.url = url; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
this.logger.error(error.message); |
|
|
|
@ -175,8 +188,8 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { |
|
|
|
|
|
|
|
public async getAssetProfile( |
|
|
|
aSymbol: string |
|
|
|
): Promise<Partial<SymbolProfile>> { |
|
|
|
let response: Partial<SymbolProfile> = {}; |
|
|
|
): Promise<Partial<SymbolProfile> | undefined> { |
|
|
|
let response: Partial<SymbolProfile> | undefined = {}; |
|
|
|
|
|
|
|
try { |
|
|
|
let symbol = aSymbol; |
|
|
|
@ -199,6 +212,10 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { |
|
|
|
modules: ['price', 'summaryProfile', 'topHoldings'] |
|
|
|
}); |
|
|
|
|
|
|
|
if (!assetProfile?.price?.symbol) { |
|
|
|
throw new Error(`No price data found for ${symbol}`); |
|
|
|
} |
|
|
|
|
|
|
|
const { assetClass, assetSubClass } = this.parseAssetClass({ |
|
|
|
quoteType: assetProfile.price.quoteType, |
|
|
|
shortName: assetProfile.price.shortName |
|
|
|
@ -206,19 +223,19 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { |
|
|
|
|
|
|
|
response.assetClass = assetClass; |
|
|
|
response.assetSubClass = assetSubClass; |
|
|
|
response.currency = assetProfile.price?.currency; |
|
|
|
response.currency = assetProfile.price.currency; |
|
|
|
response.dataSource = this.getName(); |
|
|
|
response.name = this.formatName({ |
|
|
|
longName: assetProfile.price?.longName, |
|
|
|
quoteType: assetProfile.price?.quoteType, |
|
|
|
shortName: assetProfile.price?.shortName, |
|
|
|
symbol: assetProfile.price?.symbol |
|
|
|
longName: assetProfile.price.longName, |
|
|
|
quoteType: assetProfile.price.quoteType, |
|
|
|
shortName: assetProfile.price.shortName, |
|
|
|
symbol: assetProfile.price.symbol |
|
|
|
}); |
|
|
|
response.symbol = this.convertFromYahooFinanceSymbol( |
|
|
|
assetProfile.price.symbol |
|
|
|
); |
|
|
|
|
|
|
|
if (['ETF', 'MUTUALFUND'].includes(assetSubClass)) { |
|
|
|
if (assetSubClass === 'ETF' || assetSubClass === 'MUTUALFUND') { |
|
|
|
response.holdings = |
|
|
|
assetProfile.topHoldings?.holdings |
|
|
|
?.filter(({ holdingName }) => { |
|
|
|
@ -301,8 +318,8 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { |
|
|
|
quoteType, |
|
|
|
shortName |
|
|
|
}: { |
|
|
|
quoteType: string; |
|
|
|
shortName: string; |
|
|
|
quoteType?: string; |
|
|
|
shortName?: string | null; |
|
|
|
}): { |
|
|
|
assetClass: AssetClass; |
|
|
|
assetSubClass: AssetSubClass; |
|
|
|
|