Browse Source

Refactor params to object

pull/2987/head
Thomas Kaul 2 years ago
parent
commit
f271934453
  1. 12
      apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts
  2. 16
      apps/api/src/services/data-provider/coingecko/coingecko.service.ts
  3. 4
      apps/api/src/services/data-provider/data-provider.service.ts
  4. 14
      apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
  5. 12
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts
  6. 12
      apps/api/src/services/data-provider/google-sheets/google-sheets.service.ts
  7. 6
      apps/api/src/services/data-provider/interfaces/data-provider.interface.ts
  8. 14
      apps/api/src/services/data-provider/manual/manual.service.ts
  9. 12
      apps/api/src/services/data-provider/rapid-api/rapid-api.service.ts
  10. 12
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

12
apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts

@ -36,12 +36,14 @@ export class AlphaVantageService implements DataProviderInterface {
return !!this.configurationService.get('API_KEY_ALPHA_VANTAGE');
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
return {
dataSource: this.getName(),
symbol: aSymbol
symbol,
dataSource: this.getName()
};
}

16
apps/api/src/services/data-provider/coingecko/coingecko.service.ts

@ -51,15 +51,17 @@ export class CoinGeckoService implements DataProviderInterface {
return true;
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
const response: Partial<SymbolProfile> = {
symbol,
assetClass: AssetClass.CASH,
assetSubClass: AssetSubClass.CRYPTOCURRENCY,
currency: DEFAULT_CURRENCY,
dataSource: this.getName(),
symbol: aSymbol
dataSource: this.getName()
};
try {
@ -69,7 +71,7 @@ export class CoinGeckoService implements DataProviderInterface {
abortController.abort();
}, this.configurationService.get('REQUEST_TIMEOUT'));
const { name } = await got(`${this.apiUrl}/coins/${aSymbol}`, {
const { name } = await got(`${this.apiUrl}/coins/${symbol}`, {
headers: this.headers,
// @ts-ignore
signal: abortController.signal
@ -80,7 +82,7 @@ export class CoinGeckoService implements DataProviderInterface {
let message = error;
if (error?.code === 'ABORT_ERR') {
message = `RequestError: The operation to get the asset profile for ${aSymbol} was aborted because the request to the data provider took more than ${this.configurationService.get(
message = `RequestError: The operation to get the asset profile for ${symbol} was aborted because the request to the data provider took more than ${this.configurationService.get(
'REQUEST_TIMEOUT'
)}ms`;
}

4
apps/api/src/services/data-provider/data-provider.service.ts

@ -91,7 +91,9 @@ export class DataProviderService {
for (const symbol of symbols) {
const promise = Promise.resolve(
this.getDataProvider(DataSource[dataSource]).getAssetProfile(symbol)
this.getDataProvider(DataSource[dataSource]).getAssetProfile({
symbol
})
);
promises.push(

14
apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts

@ -43,19 +43,21 @@ export class EodHistoricalDataService implements DataProviderInterface {
return true;
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
const [searchResult] = await this.getSearchResult(aSymbol);
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
const [searchResult] = await this.getSearchResult(symbol);
return {
symbol,
assetClass: searchResult?.assetClass,
assetSubClass: searchResult?.assetSubClass,
currency: this.convertCurrency(searchResult?.currency),
dataSource: this.getName(),
isin: searchResult?.isin,
name: searchResult?.name,
symbol: aSymbol
name: searchResult?.name
};
}

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

@ -36,12 +36,14 @@ export class FinancialModelingPrepService implements DataProviderInterface {
return true;
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
return {
dataSource: this.getName(),
symbol: aSymbol
symbol,
dataSource: this.getName()
};
}

12
apps/api/src/services/data-provider/google-sheets/google-sheets.service.ts

@ -32,12 +32,14 @@ export class GoogleSheetsService implements DataProviderInterface {
return true;
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
return {
dataSource: this.getName(),
symbol: aSymbol
symbol,
dataSource: this.getName()
};
}

6
apps/api/src/services/data-provider/interfaces/data-provider.interface.ts

@ -10,7 +10,11 @@ import { DataSource, SymbolProfile } from '@prisma/client';
export interface DataProviderInterface {
canHandle(symbol: string): boolean;
getAssetProfile(aSymbol: string): Promise<Partial<SymbolProfile>>;
getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>>;
getDataProviderInfo(): DataProviderInfo;

14
apps/api/src/services/data-provider/manual/manual.service.ts

@ -42,16 +42,18 @@ export class ManualService implements DataProviderInterface {
return true;
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
const assetProfile: Partial<SymbolProfile> = {
dataSource: this.getName(),
symbol: aSymbol
symbol,
dataSource: this.getName()
};
const [symbolProfile] = await this.symbolProfileService.getSymbolProfiles([
{ dataSource: this.getName(), symbol: aSymbol }
{ symbol, dataSource: this.getName() }
]);
if (symbolProfile) {

12
apps/api/src/services/data-provider/rapid-api/rapid-api.service.ts

@ -29,12 +29,14 @@ export class RapidApiService implements DataProviderInterface {
return !!this.configurationService.get('API_KEY_RAPID_API');
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
return {
dataSource: this.getName(),
symbol: aSymbol
symbol,
dataSource: this.getName()
};
}

12
apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

@ -32,11 +32,13 @@ export class YahooFinanceService implements DataProviderInterface {
return true;
}
public async getAssetProfile(
aSymbol: string
): Promise<Partial<SymbolProfile>> {
const { assetClass, assetSubClass, currency, name, symbol } =
await this.yahooFinanceDataEnhancerService.getAssetProfile(aSymbol);
public async getAssetProfile({
symbol
}: {
symbol: string;
}): Promise<Partial<SymbolProfile>> {
const { assetClass, assetSubClass, currency, name } =
await this.yahooFinanceDataEnhancerService.getAssetProfile(symbol);
return {
assetClass,

Loading…
Cancel
Save