Browse Source

add sector data for ETFs

Co-authored-by: Thomas Kaul <4159106+dtslvr@users.noreply.github.com>
pull/410/head
Valentin Zickner 4 years ago
parent
commit
4b3a94a91a
  1. 17
      apps/api/src/services/data-provider/trackinsight-enhancer/trackinsight-enhancer.service.ts
  2. 1
      apps/api/src/services/interfaces/interfaces.ts

17
apps/api/src/services/data-provider/trackinsight-enhancer/trackinsight-enhancer.service.ts

@ -5,6 +5,13 @@ 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 TrackinsightEnhancerService implements DataEnhancerInterface {
public async enhance(
symbol: string,
@ -39,6 +46,16 @@ export class TrackinsightEnhancerService implements DataEnhancerInterface {
}
}
if (!response.sectors || response.sectors.length === 0) {
response.sectors = [];
for (const [name, value] of Object.entries<any>(holdings.sectors)) {
response.sectors.push({
name: sectorsMapping[name] ?? name,
weight: value.weight
});
}
}
return Promise.resolve(response);
}
}

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

@ -45,6 +45,7 @@ export interface IDataProviderResponse {
marketPrice: number;
marketState: MarketState;
name?: string;
sectors?: { name: string; weight: number }[];
url?: string;
}

Loading…
Cancel
Save