Browse Source
			
			
			Feature/automate countries for stocks in symbol profile data (#314)
			
				* Automate countries for stocks in symbol profile data
* Update changelog
			
			
				pull/315/head
			
			
		 
		
			
				
					
						 Thomas Kaul
					
					4 years ago
						Thomas Kaul
					
					4 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 5 changed files with 
29 additions and 
1 deletions
			 
			
		 
		
			
				- 
					
					
					 
					CHANGELOG.md
				
- 
					
					
					 
					apps/api/src/services/data-gathering.service.ts
				
- 
					
					
					 
					apps/api/src/services/data-provider/yahoo-finance/interfaces/interfaces.ts
				
- 
					
					
					 
					apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
				
- 
					
					
					 
					apps/api/src/services/interfaces/interfaces.ts
				
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. | 
			
		
	
		
			
				
					|  |  |  | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | 
			
		
	
		
			
				
					|  |  |  | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | ## Unreleased | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | ### Added | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | - Extended the data management of symbol profile data by countries (automated for stocks) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | ## 1.42.0 - 22.08.2021 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | ### Added | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -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 | 
			
		
	
		
			
				
					|  |  |  |           }, | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -25,6 +25,7 @@ export interface IYahooFinancePrice { | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | export interface IYahooFinanceSummaryProfile { | 
			
		
	
		
			
				
					|  |  |  |   country?: string; | 
			
		
	
		
			
				
					|  |  |  |   industry?: string; | 
			
		
	
		
			
				
					|  |  |  |   sector?: string; | 
			
		
	
		
			
				
					|  |  |  |   website?: string; | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -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,23 @@ 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(([, country]) => { | 
			
		
	
		
			
				
					|  |  |  |               return country.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; | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -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; | 
			
		
	
	
		
			
				
					|  |  | 
 |