Browse Source

Extend search by ISIN

pull/4204/head
Thomas Kaul 7 months ago
parent
commit
ab574f21c6
  1. 2
      apps/api/src/app/symbol/symbol.controller.ts
  2. 33
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

2
apps/api/src/app/symbol/symbol.controller.ts

@ -47,7 +47,7 @@ export class SymbolController {
try { try {
return this.symbolService.lookup({ return this.symbolService.lookup({
includeIndices, includeIndices,
query: query.toLowerCase(), query,
user: this.request.user user: this.request.user
}); });
} catch { } catch {

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

@ -21,11 +21,12 @@ import {
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { DataSource, SymbolProfile } from '@prisma/client'; import { DataSource, SymbolProfile } from '@prisma/client';
import { format, isAfter, isBefore, isSameDay } from 'date-fns'; import { format, isAfter, isBefore, isSameDay } from 'date-fns';
import { uniqBy } from 'lodash';
@Injectable() @Injectable()
export class FinancialModelingPrepService implements DataProviderInterface { export class FinancialModelingPrepService implements DataProviderInterface {
private apiKey: string; private apiKey: string;
private readonly URL = 'https://financialmodelingprep.com/api/v3'; private readonly URL = this.getUrl({ version: 3 });
public constructor( public constructor(
private readonly configurationService: ConfigurationService private readonly configurationService: ConfigurationService
@ -161,23 +162,33 @@ export class FinancialModelingPrepService implements DataProviderInterface {
let items: LookupItem[] = []; let items: LookupItem[] = [];
try { try {
const result = await fetch( const [resultSearch, resultSearchIsin] = await Promise.all([
`${this.URL}/search?query=${query}&apikey=${this.apiKey}`, fetch(`${this.URL}/search?query=${query}&apikey=${this.apiKey}`, {
signal: AbortSignal.timeout(
this.configurationService.get('REQUEST_TIMEOUT')
)
}).then((res) => res.json()),
fetch(
`${this.getUrl({ version: 4 })}/search/isin?isin=${query}&apikey=${this.apiKey}`,
{ {
signal: AbortSignal.timeout( signal: AbortSignal.timeout(
this.configurationService.get('REQUEST_TIMEOUT') this.configurationService.get('REQUEST_TIMEOUT')
) )
} }
).then((res) => res.json()); ).then((res) => res.json())
]);
const result = uniqBy([...resultSearch, ...resultSearchIsin], 'symbol');
items = result.map(({ currency, name, symbol }) => { items = result.map(({ companyName, currency, name, symbol }) => {
return { return {
// TODO: Add assetClass
// TODO: Add assetSubClass
currency, currency,
name,
symbol, symbol,
dataSource: this.getName() assetClass: undefined, // TODO
assetSubClass: undefined, // TODO
dataProviderInfo: this.getDataProviderInfo(),
dataSource: this.getName(),
name: name ?? companyName
}; };
}); });
} catch (error) { } catch (error) {
@ -194,4 +205,8 @@ export class FinancialModelingPrepService implements DataProviderInterface {
return { items }; return { items };
} }
private getUrl({ version }: { version: number }) {
return `https://financialmodelingprep.com/api/v${version}`;
}
} }

Loading…
Cancel
Save