Feature/Refactored got
calls to use AbortSignal.timeout()
without AbortController()
(#4153)
* Feature/refactor got calls to use AbortSignal.timeout Instead of manually creating AbortController and controlling the abort with setTimeout. Feature available since node v16.14.0 and v17.3.0[^1] and is built to replace the exact scenario that all these requests have. [^1]:https://nodejs.org/docs/latest-v22.x/api/globals.html#static-method-abortsignaltimeoutdelay * Update changelog --------- Co-authored-by: Thomas Kaul <4159106+dtslvr@users.noreply.github.com>
This commit is contained in:
parent
ff7caf9c5c
commit
74bc8222d6
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Improved support for automatic deletion of unused asset profiles when deleting activities
|
- Improved support for automatic deletion of unused asset profiles when deleting activities
|
||||||
- Migrated the coupon redemption to the notification service for prompt dialogs
|
- Migrated the coupon redemption to the notification service for prompt dialogs
|
||||||
|
- Refactored `got` calls to use `AbortSignal.timeout()` without `AbortController()`
|
||||||
- Improved the language localization for German (`de`)
|
- Improved the language localization for German (`de`)
|
||||||
- Eliminated `body-parser` in favor of using `@nestjs/platform-express`
|
- Eliminated `body-parser` in favor of using `@nestjs/platform-express`
|
||||||
- Upgraded the _Stripe_ dependencies
|
- Upgraded the _Stripe_ dependencies
|
||||||
|
@ -155,18 +155,14 @@ export class InfoService {
|
|||||||
|
|
||||||
private async countDockerHubPulls(): Promise<number> {
|
private async countDockerHubPulls(): Promise<number> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { pull_count } = await got(
|
const { pull_count } = await got(
|
||||||
`https://hub.docker.com/v2/repositories/ghostfolio/ghostfolio`,
|
`https://hub.docker.com/v2/repositories/ghostfolio/ghostfolio`,
|
||||||
{
|
{
|
||||||
headers: { 'User-Agent': 'request' },
|
headers: { 'User-Agent': 'request' },
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -180,15 +176,11 @@ export class InfoService {
|
|||||||
|
|
||||||
private async countGitHubContributors(): Promise<number> {
|
private async countGitHubContributors(): Promise<number> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { body } = await got('https://github.com/ghostfolio/ghostfolio', {
|
const { body } = await got('https://github.com/ghostfolio/ghostfolio', {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
const $ = cheerio.load(body);
|
const $ = cheerio.load(body);
|
||||||
@ -207,18 +199,14 @@ export class InfoService {
|
|||||||
|
|
||||||
private async countGitHubStargazers(): Promise<number> {
|
private async countGitHubStargazers(): Promise<number> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { stargazers_count } = await got(
|
const { stargazers_count } = await got(
|
||||||
`https://api.github.com/repos/ghostfolio/ghostfolio`,
|
`https://api.github.com/repos/ghostfolio/ghostfolio`,
|
||||||
{
|
{
|
||||||
headers: { 'User-Agent': 'request' },
|
headers: { 'User-Agent': 'request' },
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -335,12 +323,6 @@ export class InfoService {
|
|||||||
PROPERTY_BETTER_UPTIME_MONITOR_ID
|
PROPERTY_BETTER_UPTIME_MONITOR_ID
|
||||||
)) as string;
|
)) as string;
|
||||||
|
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { data } = await got(
|
const { data } = await got(
|
||||||
`https://uptime.betterstack.com/api/v2/monitors/${monitorId}/sla?from=${format(
|
`https://uptime.betterstack.com/api/v2/monitors/${monitorId}/sla?from=${format(
|
||||||
subDays(new Date(), 90),
|
subDays(new Date(), 90),
|
||||||
@ -353,7 +335,9 @@ export class InfoService {
|
|||||||
)}`
|
)}`
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
|
@ -44,18 +44,14 @@ export class LogoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getBuffer(aUrl: string) {
|
private getBuffer(aUrl: string) {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
return got(
|
return got(
|
||||||
`https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${aUrl}&size=64`,
|
`https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${aUrl}&size=64`,
|
||||||
{
|
{
|
||||||
headers: { 'User-Agent': 'request' },
|
headers: { 'User-Agent': 'request' },
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).buffer();
|
).buffer();
|
||||||
}
|
}
|
||||||
|
@ -69,16 +69,12 @@ export class CoinGeckoService implements DataProviderInterface {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { name } = await got(`${this.apiUrl}/coins/${symbol}`, {
|
const { name } = await got(`${this.apiUrl}/coins/${symbol}`, {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}).json<any>();
|
}).json<any>();
|
||||||
|
|
||||||
response.name = name;
|
response.name = name;
|
||||||
@ -118,12 +114,6 @@ export class CoinGeckoService implements DataProviderInterface {
|
|||||||
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const { prices } = await got(
|
const { prices } = await got(
|
||||||
`${
|
`${
|
||||||
this.apiUrl
|
this.apiUrl
|
||||||
@ -133,7 +123,7 @@ export class CoinGeckoService implements DataProviderInterface {
|
|||||||
{
|
{
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -179,12 +169,6 @@ export class CoinGeckoService implements DataProviderInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const quotes = await got(
|
const quotes = await got(
|
||||||
`${this.apiUrl}/simple/price?ids=${symbols.join(
|
`${this.apiUrl}/simple/price?ids=${symbols.join(
|
||||||
','
|
','
|
||||||
@ -192,7 +176,7 @@ export class CoinGeckoService implements DataProviderInterface {
|
|||||||
{
|
{
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -228,16 +212,12 @@ export class CoinGeckoService implements DataProviderInterface {
|
|||||||
let items: LookupItem[] = [];
|
let items: LookupItem[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { coins } = await got(`${this.apiUrl}/search?query=${query}`, {
|
const { coins } = await got(`${this.apiUrl}/search?query=${query}`, {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}).json<any>();
|
}).json<any>();
|
||||||
|
|
||||||
items = coins.map(({ id: symbol, name }) => {
|
items = coins.map(({ id: symbol, name }) => {
|
||||||
|
@ -43,18 +43,12 @@ export class OpenFigiDataEnhancerService implements DataEnhancerInterface {
|
|||||||
this.configurationService.get('API_KEY_OPEN_FIGI');
|
this.configurationService.get('API_KEY_OPEN_FIGI');
|
||||||
}
|
}
|
||||||
|
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const mappings = await got
|
const mappings = await got
|
||||||
.post(`${OpenFigiDataEnhancerService.baseUrl}/v3/mapping`, {
|
.post(`${OpenFigiDataEnhancerService.baseUrl}/v3/mapping`, {
|
||||||
headers,
|
headers,
|
||||||
json: [{ exchCode: exchange, idType: 'TICKER', idValue: ticker }],
|
json: [{ exchCode: exchange, idType: 'TICKER', idValue: ticker }],
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
})
|
})
|
||||||
.json<any[]>();
|
.json<any[]>();
|
||||||
|
|
||||||
|
@ -45,34 +45,24 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
let abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const profile = await got(
|
const profile = await got(
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/funds/${symbol}.json`,
|
`${TrackinsightDataEnhancerService.baseUrl}/funds/${symbol}.json`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.json<any>()
|
.json<any>()
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
return got(
|
return got(
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/funds/${
|
`${TrackinsightDataEnhancerService.baseUrl}/funds/${
|
||||||
symbol.split('.')?.[0]
|
symbol.split('.')?.[0]
|
||||||
}.json`,
|
}.json`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.json<any>()
|
.json<any>()
|
||||||
@ -87,34 +77,26 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
|
|||||||
response.isin = isin;
|
response.isin = isin;
|
||||||
}
|
}
|
||||||
|
|
||||||
abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const holdings = await got(
|
const holdings = await got(
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${symbol}.json`,
|
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${symbol}.json`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.json<any>()
|
.json<any>()
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
return got(
|
return got(
|
||||||
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${
|
`${TrackinsightDataEnhancerService.baseUrl}/holdings/${
|
||||||
symbol.split('.')?.[0]
|
symbol.split('.')?.[0]
|
||||||
}.json`,
|
}.json`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.json<any>()
|
.json<any>()
|
||||||
|
@ -91,16 +91,10 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
const response: {
|
const response: {
|
||||||
[date: string]: IDataProviderHistoricalResponse;
|
[date: string]: IDataProviderHistoricalResponse;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const historicalResult = await got(
|
const historicalResult = await got(
|
||||||
`${this.URL}/div/${symbol}?api_token=${
|
`${this.URL}/div/${symbol}?api_token=${
|
||||||
this.apiKey
|
this.apiKey
|
||||||
@ -110,7 +104,7 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
)}`,
|
)}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -146,12 +140,6 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
symbol = this.convertToEodSymbol(symbol);
|
symbol = this.convertToEodSymbol(symbol);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const response = await got(
|
const response = await got(
|
||||||
`${this.URL}/eod/${symbol}?api_token=${
|
`${this.URL}/eod/${symbol}?api_token=${
|
||||||
this.apiKey
|
this.apiKey
|
||||||
@ -161,7 +149,7 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
)}&period=${granularity}`,
|
)}&period=${granularity}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -217,19 +205,13 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const realTimeResponse = await got(
|
const realTimeResponse = await got(
|
||||||
`${this.URL}/real-time/${eodHistoricalDataSymbols[0]}?api_token=${
|
`${this.URL}/real-time/${eodHistoricalDataSymbols[0]}?api_token=${
|
||||||
this.apiKey
|
this.apiKey
|
||||||
}&fmt=json&s=${eodHistoricalDataSymbols.join(',')}`,
|
}&fmt=json&s=${eodHistoricalDataSymbols.join(',')}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -418,17 +400,13 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
})[] = [];
|
})[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const response = await got(
|
const response = await got(
|
||||||
`${this.URL}/search/${aQuery}?api_token=${this.apiKey}`,
|
`${this.URL}/search/${aQuery}?api_token=${this.apiKey}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
|
@ -72,17 +72,11 @@ export class FinancialModelingPrepService implements DataProviderInterface {
|
|||||||
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const { historical } = await got(
|
const { historical } = await got(
|
||||||
`${this.URL}/historical-price-full/${symbol}?apikey=${this.apiKey}`,
|
`${this.URL}/historical-price-full/${symbol}?apikey=${this.apiKey}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -130,17 +124,11 @@ export class FinancialModelingPrepService implements DataProviderInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const quotes = await got(
|
const quotes = await got(
|
||||||
`${this.URL}/quote/${symbols.join(',')}?apikey=${this.apiKey}`,
|
`${this.URL}/quote/${symbols.join(',')}?apikey=${this.apiKey}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
@ -176,17 +164,13 @@ export class FinancialModelingPrepService implements DataProviderInterface {
|
|||||||
let items: LookupItem[] = [];
|
let items: LookupItem[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const result = await got(
|
const result = await got(
|
||||||
`${this.URL}/search?query=${query}&apikey=${this.apiKey}`,
|
`${this.URL}/search?query=${query}&apikey=${this.apiKey}`,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
|
@ -86,12 +86,6 @@ export class GhostfolioService implements DataProviderInterface {
|
|||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const { dividends } = await got(
|
const { dividends } = await got(
|
||||||
`${this.URL}/v2/data-providers/ghostfolio/dividends/${symbol}?from=${format(from, DATE_FORMAT)}&granularity=${granularity}&to=${format(
|
`${this.URL}/v2/data-providers/ghostfolio/dividends/${symbol}?from=${format(from, DATE_FORMAT)}&granularity=${granularity}&to=${format(
|
||||||
to,
|
to,
|
||||||
@ -100,7 +94,7 @@ export class GhostfolioService implements DataProviderInterface {
|
|||||||
{
|
{
|
||||||
headers: await this.getRequestHeaders(),
|
headers: await this.getRequestHeaders(),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<DividendsResponse>();
|
).json<DividendsResponse>();
|
||||||
|
|
||||||
@ -136,12 +130,6 @@ export class GhostfolioService implements DataProviderInterface {
|
|||||||
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const { historicalData } = await got(
|
const { historicalData } = await got(
|
||||||
`${this.URL}/v2/data-providers/ghostfolio/historical/${symbol}?from=${format(from, DATE_FORMAT)}&granularity=${granularity}&to=${format(
|
`${this.URL}/v2/data-providers/ghostfolio/historical/${symbol}?from=${format(from, DATE_FORMAT)}&granularity=${granularity}&to=${format(
|
||||||
to,
|
to,
|
||||||
@ -150,7 +138,7 @@ export class GhostfolioService implements DataProviderInterface {
|
|||||||
{
|
{
|
||||||
headers: await this.getRequestHeaders(),
|
headers: await this.getRequestHeaders(),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<HistoricalResponse>();
|
).json<HistoricalResponse>();
|
||||||
|
|
||||||
@ -204,18 +192,12 @@ export class GhostfolioService implements DataProviderInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, requestTimeout);
|
|
||||||
|
|
||||||
const { quotes } = await got(
|
const { quotes } = await got(
|
||||||
`${this.URL}/v2/data-providers/ghostfolio/quotes?symbols=${symbols.join(',')}`,
|
`${this.URL}/v2/data-providers/ghostfolio/quotes?symbols=${symbols.join(',')}`,
|
||||||
{
|
{
|
||||||
headers: await this.getRequestHeaders(),
|
headers: await this.getRequestHeaders(),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
}
|
}
|
||||||
).json<QuotesResponse>();
|
).json<QuotesResponse>();
|
||||||
|
|
||||||
@ -253,18 +235,14 @@ export class GhostfolioService implements DataProviderInterface {
|
|||||||
let searchResult: LookupResponse = { items: [] };
|
let searchResult: LookupResponse = { items: [] };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
searchResult = await got(
|
searchResult = await got(
|
||||||
`${this.URL}/v2/data-providers/ghostfolio/lookup?query=${query}`,
|
`${this.URL}/v2/data-providers/ghostfolio/lookup?query=${query}`,
|
||||||
{
|
{
|
||||||
headers: await this.getRequestHeaders(),
|
headers: await this.getRequestHeaders(),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<LookupResponse>();
|
).json<LookupResponse>();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -275,17 +275,13 @@ export class ManualService implements DataProviderInterface {
|
|||||||
scraperConfiguration: ScraperConfiguration
|
scraperConfiguration: ScraperConfiguration
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
let locale = scraperConfiguration.locale;
|
let locale = scraperConfiguration.locale;
|
||||||
const { body, headers } = await got(scraperConfiguration.url, {
|
const { body, headers } = await got(scraperConfiguration.url, {
|
||||||
headers: scraperConfiguration.headers as Headers,
|
headers: scraperConfiguration.headers as Headers,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (headers['content-type'].includes('application/json')) {
|
if (headers['content-type'].includes('application/json')) {
|
||||||
|
@ -135,12 +135,6 @@ export class RapidApiService implements DataProviderInterface {
|
|||||||
oneYearAgo: { value: number; valueText: string };
|
oneYearAgo: { value: number; valueText: string };
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const abortController = new AbortController();
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
abortController.abort();
|
|
||||||
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
||||||
|
|
||||||
const { fgi } = await got(
|
const { fgi } = await got(
|
||||||
`https://fear-and-greed-index.p.rapidapi.com/v1/fgi`,
|
`https://fear-and-greed-index.p.rapidapi.com/v1/fgi`,
|
||||||
{
|
{
|
||||||
@ -150,7 +144,9 @@ export class RapidApiService implements DataProviderInterface {
|
|||||||
'x-rapidapi-key': this.configurationService.get('API_KEY_RAPID_API')
|
'x-rapidapi-key': this.configurationService.get('API_KEY_RAPID_API')
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
signal: abortController.signal
|
signal: AbortSignal.timeout(
|
||||||
|
this.configurationService.get('REQUEST_TIMEOUT')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
).json<any>();
|
).json<any>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user