Browse Source

Improve handling of indices

pull/7738/head
Thomas Kaul 2 days ago
parent
commit
137d24eeda
  1. 69
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

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

@ -591,28 +591,17 @@ export class FinancialModelingPrepService
};
});
} else {
const queryParams = new URLSearchParams({
query,
apikey: this.apiKey
});
const [nameResults, symbolResults] = await Promise.all([
this.fetchService
.fetch(
`${this.getUrl({ version: 'stable' })}/search-name?${queryParams.toString()}`,
{
signal: AbortSignal.timeout(requestTimeout)
}
)
.then((res) => res.json()),
this.fetchService
.fetch(
`${this.getUrl({ version: 'stable' })}/search-symbol?${queryParams.toString()}`,
{
signal: AbortSignal.timeout(requestTimeout)
}
)
.then((res) => res.json())
this.getSearchResults({
query,
requestTimeout,
endpoint: 'search-name'
}),
this.getSearchResults({
query,
requestTimeout,
endpoint: 'search-symbol'
})
]);
const result = uniqBy(
@ -682,20 +671,12 @@ export class FinancialModelingPrepService
requestTimeout: number;
symbol: string;
}): Promise<Pick<SymbolProfile, 'currency' | 'name'>> {
const queryParams = new URLSearchParams({
apikey: this.apiKey,
const results = await this.getSearchResults({
requestTimeout,
endpoint: 'search-symbol',
query: symbol
});
const results = await this.fetchService
.fetch(
`${this.getUrl({ version: 'stable' })}/search-symbol?${queryParams.toString()}`,
{
signal: AbortSignal.timeout(requestTimeout)
}
)
.then((res) => res.json());
const index = results?.find(({ exchange, symbol: symbolOfResult }) => {
return exchange === 'INDEX' && symbolOfResult === symbol;
});
@ -710,6 +691,30 @@ export class FinancialModelingPrepService
};
}
private async getSearchResults({
endpoint,
query,
requestTimeout
}: {
endpoint: 'search-name' | 'search-symbol';
query: string;
requestTimeout: number;
}) {
const queryParams = new URLSearchParams({
query,
apikey: this.apiKey
});
return this.fetchService
.fetch(
`${this.getUrl({ version: 'stable' })}/${endpoint}?${queryParams.toString()}`,
{
signal: AbortSignal.timeout(requestTimeout)
}
)
.then((res) => res.json());
}
private getUrl({ version }: { version: number | 'stable' }) {
const baseUrl = 'https://financialmodelingprep.com';

Loading…
Cancel
Save