Browse Source

Automate countries for stocks in symbol profile data

pull/314/head
Thomas 4 years ago
parent
commit
fb3c5855b7
  1. 4
      apps/api/src/services/data-gathering.service.ts
  2. 1
      apps/api/src/services/data-provider/yahoo-finance/interfaces/interfaces.ts
  3. 20
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
  4. 1
      apps/api/src/services/interfaces/interfaces.ts

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

@ -136,13 +136,14 @@ export class DataGatheringService {
for (const [
symbol,
{ assetClass, assetSubClass, currency, dataSource, name }
{ assetClass, assetSubClass, countries, currency, dataSource, name }
] of Object.entries(currentData)) {
try {
await this.prismaService.symbolProfile.upsert({
create: {
assetClass,
assetSubClass,
countries,
currency,
dataSource,
name,
@ -151,6 +152,7 @@ export class DataGatheringService {
update: {
assetClass,
assetSubClass,
countries,
currency,
name
},

1
apps/api/src/services/data-provider/yahoo-finance/interfaces/interfaces.ts

@ -25,6 +25,7 @@ export interface IYahooFinancePrice {
}
export interface IYahooFinanceSummaryProfile {
country?: string;
industry?: string;
sector?: string;
website?: string;

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

@ -16,6 +16,7 @@ import {
} from '@prisma/client';
import * as bent from 'bent';
import Big from 'big.js';
import { countries } from 'countries-list';
import { format } from 'date-fns';
import * as yahooFinance from 'yahoo-finance';
@ -92,6 +93,25 @@ export class YahooFinanceService implements DataProviderInterface {
.toNumber();
}
// Add country if stock and available
if (
assetSubClass === AssetSubClass.STOCK &&
value.summaryProfile?.country
) {
try {
const [code] = Object.entries(countries).find(
([, currentCountry]) => {
return currentCountry.name === value.summaryProfile?.country;
}
);
if (code) {
response[symbol].countries = [{ code, weight: 1 }];
}
} catch {}
}
// Add url if available
const url = value.summaryProfile?.website;
if (url) {
response[symbol].url = url;

1
apps/api/src/services/interfaces/interfaces.ts

@ -37,6 +37,7 @@ export interface IDataProviderHistoricalResponse {
export interface IDataProviderResponse {
assetClass?: AssetClass;
assetSubClass?: AssetSubClass;
countries?: { code: string; weight: number }[];
currency: Currency;
dataSource: DataSource;
exchange?: string;

Loading…
Cancel
Save