Browse Source

Better trackinsight inaccuracy handling

pull/5027/head
Daniel Devaud 2 years ago
parent
commit
f14959e6ab
  1. 21
      apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts

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

@ -3,6 +3,7 @@ import { Country } from '@ghostfolio/common/interfaces/country.interface';
import { Sector } from '@ghostfolio/common/interfaces/sector.interface'; import { Sector } from '@ghostfolio/common/interfaces/sector.interface';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { SymbolProfile } from '@prisma/client'; import { SymbolProfile } from '@prisma/client';
import { Min } from 'class-validator';
import got from 'got'; import got from 'got';
@Injectable() @Injectable()
@ -26,9 +27,7 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
response: Partial<SymbolProfile>; response: Partial<SymbolProfile>;
symbol: string; symbol: string;
}): Promise<Partial<SymbolProfile>> { }): Promise<Partial<SymbolProfile>> {
if ( if (!(response.assetSubClass === 'ETF')) {
!(response.assetClass === 'EQUITY' && response.assetSubClass === 'ETF')
) {
return response; return response;
} }
@ -38,9 +37,9 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
.json<any>() .json<any>()
.catch(() => { .catch(() => {
return got( return got(
`${TrackinsightDataEnhancerService.baseUrl}/funds/${symbol.split( `${TrackinsightDataEnhancerService.baseUrl}/funds/${
'.' symbol.split('.')?.[0]
)?.[0]}.json` }.json`
) )
.json<any>() .json<any>()
.catch(() => { .catch(() => {
@ -60,9 +59,9 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
.json<any>() .json<any>()
.catch(() => { .catch(() => {
return got( return got(
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${symbol.split( `${TrackinsightDataEnhancerService.baseUrl}/holdings/${
'.' symbol.split('.')?.[0]
)?.[0]}.json` }.json`
) )
.json<any>() .json<any>()
.catch(() => { .catch(() => {
@ -70,8 +69,8 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
}); });
}); });
if (holdings?.weight < 0.95) { if (holdings?.weight < 1 - Math.min(holdings?.count * 0.000015, 0.95)) {
// Skip if data is inaccurate // Skip if data is inaccurate, dependent on holdings count there might be rounding issues
return response; return response;
} }

Loading…
Cancel
Save