Feature/improve symbol lookup in Trackinsight data enhancer (#4296)
* Feature: enhance Trackinsight data fetching with symbol search fallback * Feature: refactor Trackinsight symbol search for improved clarity and error handling * Fixed style concerns and removed code duplication * Minor improvements * Update changelog * Update changelog * Clean up --------- Co-authored-by: Thomas Kaul <4159106+dtslvr@users.noreply.github.com>
This commit is contained in:
parent
ec8fce44a6
commit
4f76ee6758
@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Improved the symbol lookup in the _Trackinsight_ data enhancer for asset profile data
|
||||||
- Improved the language localization for German (`de`)
|
- Improved the language localization for German (`de`)
|
||||||
- Upgraded `@trivago/prettier-plugin-sort-imports` from version `5.2.1` to `5.2.2`
|
- Upgraded `@trivago/prettier-plugin-sort-imports` from version `5.2.1` to `5.2.2`
|
||||||
|
|
||||||
|
@ -44,28 +44,31 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
|
|||||||
return response;
|
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(
|
const profile = await fetch(
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/funds/${symbol}.json`,
|
`${TrackinsightDataEnhancerService.baseUrl}/funds/${trackinsightSymbol}.json`,
|
||||||
{
|
{
|
||||||
signal: AbortSignal.timeout(requestTimeout)
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
return fetch(
|
return {};
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/funds/${
|
|
||||||
symbol.split('.')?.[0]
|
|
||||||
}.json`,
|
|
||||||
{
|
|
||||||
signal: AbortSignal.timeout(
|
|
||||||
this.configurationService.get('REQUEST_TIMEOUT')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then((res) => res.json())
|
|
||||||
.catch(() => {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const isin = profile?.isin?.split(';')?.[0];
|
const isin = profile?.isin?.split(';')?.[0];
|
||||||
@ -75,29 +78,14 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const holdings = await fetch(
|
const holdings = await fetch(
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${symbol}.json`,
|
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${trackinsightSymbol}.json`,
|
||||||
{
|
{
|
||||||
signal: AbortSignal.timeout(
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
this.configurationService.get('REQUEST_TIMEOUT')
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
return fetch(
|
return {};
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${
|
|
||||||
symbol.split('.')?.[0]
|
|
||||||
}.json`,
|
|
||||||
{
|
|
||||||
signal: AbortSignal.timeout(
|
|
||||||
this.configurationService.get('REQUEST_TIMEOUT')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then((res) => res.json())
|
|
||||||
.catch(() => {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -180,4 +168,33 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
|
|||||||
public getTestSymbol() {
|
public getTestSymbol() {
|
||||||
return 'QQQ';
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user