Browse Source

Feature/use asset profile resolutions in getQuotes() of FMP service (#5743)

* Use asset profile resolutions in getQuotes()

* Update changelog
pull/5702/head^2
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
8d6153fa52
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 30
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

1
CHANGELOG.md

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Disabled the zoom functionality in the _Progressive Web App_ (PWA)
- Optimized the get quotes functionality by utilizing the asset profile resolutions in the _Financial Modeling Prep_ service
## 2.208.0 - 2025-10-11

30
apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

@ -12,6 +12,7 @@ import {
IDataProviderHistoricalResponse,
IDataProviderResponse
} from '@ghostfolio/api/services/interfaces/interfaces';
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
import {
DEFAULT_CURRENCY,
REPLACE_NAME_PARTS
@ -49,7 +50,8 @@ export class FinancialModelingPrepService implements DataProviderInterface {
public constructor(
private readonly configurationService: ConfigurationService,
private readonly cryptocurrencyService: CryptocurrencyService
private readonly cryptocurrencyService: CryptocurrencyService,
private readonly prismaService: PrismaService
) {
this.apiKey = this.configurationService.get(
'API_KEY_FINANCIAL_MODELING_PREP'
@ -220,7 +222,7 @@ export class FinancialModelingPrepService implements DataProviderInterface {
public getDataProviderInfo(): DataProviderInfo {
return {
dataSource: DataSource.FINANCIAL_MODELING_PREP,
dataSource: this.getName(),
isPremium: true,
name: 'Financial Modeling Prep',
url: 'https://financialmodelingprep.com/developer/docs'
@ -359,13 +361,26 @@ export class FinancialModelingPrepService implements DataProviderInterface {
[symbol: string]: Pick<SymbolProfile, 'currency'>;
} = {};
const quotes = await fetch(
const [assetProfileResolutions, quotes] = await Promise.all([
this.prismaService.assetProfileResolution.findMany({
where: {
dataSourceTarget: this.getDataProviderInfo().dataSource,
symbolTarget: { in: symbols }
}
}),
fetch(
`${this.getUrl({ version: 'stable' })}/batch-quote-short?symbols=${symbols.join(',')}&apikey=${this.apiKey}`,
{
signal: AbortSignal.timeout(requestTimeout)
}
).then((res) => res.json());
).then((res) => res.json())
]);
if (assetProfileResolutions.length === symbols.length) {
for (const { currency, symbolTarget } of assetProfileResolutions) {
currencyBySymbolMap[symbolTarget] = { currency };
}
} else {
await Promise.all(
quotes.map(({ symbol }) => {
return this.getAssetProfile({
@ -373,11 +388,14 @@ export class FinancialModelingPrepService implements DataProviderInterface {
symbol
}).then((assetProfile) => {
if (assetProfile?.currency) {
currencyBySymbolMap[symbol] = { currency: assetProfile.currency };
currencyBySymbolMap[symbol] = {
currency: assetProfile.currency
};
}
});
})
);
}
for (const { price, symbol } of quotes) {
let marketState: MarketState = 'delayed';
@ -394,7 +412,7 @@ export class FinancialModelingPrepService implements DataProviderInterface {
marketState,
currency: currencyBySymbolMap[symbol]?.currency,
dataProviderInfo: this.getDataProviderInfo(),
dataSource: DataSource.FINANCIAL_MODELING_PREP,
dataSource: this.getDataProviderInfo().dataSource,
marketPrice: price
};
}

Loading…
Cancel
Save