|
|
@ -2,21 +2,24 @@ import { DataEnhancerInterface } from '@ghostfolio/api/services/data-provider/in |
|
|
|
import { IDataProviderResponse } from '@ghostfolio/api/services/interfaces/interfaces'; |
|
|
|
import bent from 'bent'; |
|
|
|
|
|
|
|
const countries = require('countries-list/dist/countries.json'); |
|
|
|
const getJSON = bent('json'); |
|
|
|
|
|
|
|
const sectorsMapping = { |
|
|
|
'Consumer Discretionary': 'Consumer Cyclical', |
|
|
|
'Consumer Defensive': 'Consumer Staples', |
|
|
|
'Health Care': 'Healthcare', |
|
|
|
'Information Technology': 'Technology' |
|
|
|
}; |
|
|
|
export class TrackinsightDataEnhancerService implements DataEnhancerInterface { |
|
|
|
private static countries = require('countries-list/dist/countries.json'); |
|
|
|
private static sectorsMapping = { |
|
|
|
'Consumer Discretionary': 'Consumer Cyclical', |
|
|
|
'Consumer Defensive': 'Consumer Staples', |
|
|
|
'Health Care': 'Healthcare', |
|
|
|
'Information Technology': 'Technology' |
|
|
|
}; |
|
|
|
|
|
|
|
export class TrackinsightEnhancerService implements DataEnhancerInterface { |
|
|
|
public async enhance( |
|
|
|
symbol: string, |
|
|
|
response: IDataProviderResponse |
|
|
|
): Promise<IDataProviderResponse> { |
|
|
|
public async enhance({ |
|
|
|
response, |
|
|
|
symbol |
|
|
|
}: { |
|
|
|
response: IDataProviderResponse; |
|
|
|
symbol: string; |
|
|
|
}): Promise<IDataProviderResponse> { |
|
|
|
if ( |
|
|
|
!(response.assetClass === 'EQUITY' && response.assetSubClass === 'ETF') |
|
|
|
) { |
|
|
@ -36,7 +39,9 @@ export class TrackinsightEnhancerService implements DataEnhancerInterface { |
|
|
|
for (const [name, value] of Object.entries<any>(holdings.countries)) { |
|
|
|
let countryCode: string; |
|
|
|
|
|
|
|
for (const [key, country] of Object.entries<any>(countries)) { |
|
|
|
for (const [key, country] of Object.entries<any>( |
|
|
|
TrackinsightDataEnhancerService.countries |
|
|
|
)) { |
|
|
|
if (country.name === name) { |
|
|
|
countryCode = key; |
|
|
|
break; |
|
|
@ -54,7 +59,7 @@ export class TrackinsightEnhancerService implements DataEnhancerInterface { |
|
|
|
response.sectors = []; |
|
|
|
for (const [name, value] of Object.entries<any>(holdings.sectors)) { |
|
|
|
response.sectors.push({ |
|
|
|
name: sectorsMapping[name] ?? name, |
|
|
|
name: TrackinsightDataEnhancerService.sectorsMapping[name] ?? name, |
|
|
|
weight: value.weight |
|
|
|
}); |
|
|
|
} |