@ -44,28 +44,31 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
return response ;
}
let trackinsightSymbol = await this . searchTrackinsightSymbol ( {
requestTimeout ,
symbol
} ) ;
if ( ! trackinsightSymbol ) {
trackinsightSymbol = await this . searchTrackinsightSymbol ( {
requestTimeout ,
symbol : symbol . split ( '.' ) ? . [ 0 ]
} ) ;
}
if ( ! trackinsightSymbol ) {
return response ;
}
const profile = await fetch (
` ${ TrackinsightDataEnhancerService . baseUrl } /funds/ ${ symbol } .json ` ,
` ${ TrackinsightDataEnhancerService . baseUrl } /funds/ ${ trackinsightS ymbol} .json ` ,
{
signal : AbortSignal.timeout ( requestTimeout )
}
)
. then ( ( res ) = > res . json ( ) )
. catch ( ( ) = > {
return fetch (
` ${ TrackinsightDataEnhancerService . baseUrl } /funds/ ${
symbol . split ( '.' ) ? . [ 0 ]
} . json ` ,
{
signal : AbortSignal.timeout (
this . configurationService . get ( 'REQUEST_TIMEOUT' )
)
}
)
. then ( ( res ) = > res . json ( ) )
. catch ( ( ) = > {
return { } ;
} ) ;
return { } ;
} ) ;
const isin = profile ? . isin ? . split ( ';' ) ? . [ 0 ] ;
@ -75,29 +78,14 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
}
const holdings = await fetch (
` ${ TrackinsightDataEnhancerService . baseUrl } /holdings/ ${ s ymbol} .json ` ,
` ${ TrackinsightDataEnhancerService . baseUrl } /holdings/ ${ trackinsightS ymbol} .json ` ,
{
signal : AbortSignal.timeout (
this . configurationService . get ( 'REQUEST_TIMEOUT' )
)
signal : AbortSignal.timeout ( requestTimeout )
}
)
. then ( ( res ) = > res . json ( ) )
. catch ( ( ) = > {
return fetch (
` ${ TrackinsightDataEnhancerService . baseUrl } /holdings/ ${
symbol . split ( '.' ) ? . [ 0 ]
} . json ` ,
{
signal : AbortSignal.timeout (
this . configurationService . get ( 'REQUEST_TIMEOUT' )
)
}
)
. then ( ( res ) = > res . json ( ) )
. catch ( ( ) = > {
return { } ;
} ) ;
return { } ;
} ) ;
if (
@ -180,4 +168,33 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
public getTestSymbol() {
return 'QQQ' ;
}
private async searchTrackinsightSymbol ( {
requestTimeout ,
symbol
} : {
requestTimeout : number ;
symbol : string ;
} ) {
return fetch (
` https://www.trackinsight.com/search-api/search_v2/ ${ symbol } /_/ticker/default/0/3 ` ,
{
signal : AbortSignal.timeout ( requestTimeout )
}
)
. then ( ( res ) = > res . json ( ) )
. then ( ( jsonRes ) = > {
if (
jsonRes [ 'results' ] ? . [ 'count' ] === 1 ||
jsonRes [ 'results' ] ? . [ 'docs' ] ? . [ 0 ] ? . [ 'ticker' ] === symbol
) {
return jsonRes [ 'results' ] [ 'docs' ] [ 0 ] [ 'ticker' ] ;
}
return undefined ;
} )
. catch ( ( ) = > {
return undefined ;
} ) ;
}
}