|
|
@ -1,13 +1,11 @@
|
|
|
|
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
|
|
|
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
|
|
|
|
|
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
|
|
|
|
import { DataProviderInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-provider.interface';
|
|
|
|
import { DataProviderInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-provider.interface';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
IDataProviderHistoricalResponse,
|
|
|
|
IDataProviderHistoricalResponse,
|
|
|
|
IDataProviderResponse
|
|
|
|
IDataProviderResponse
|
|
|
|
} from '@ghostfolio/api/services/interfaces/interfaces';
|
|
|
|
} from '@ghostfolio/api/services/interfaces/interfaces';
|
|
|
|
import {
|
|
|
|
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config';
|
|
|
|
DEFAULT_CURRENCY,
|
|
|
|
|
|
|
|
DEFAULT_REQUEST_TIMEOUT
|
|
|
|
|
|
|
|
} from '@ghostfolio/common/config';
|
|
|
|
|
|
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper';
|
|
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper';
|
|
|
|
import { DataProviderInfo } from '@ghostfolio/common/interfaces';
|
|
|
|
import { DataProviderInfo } from '@ghostfolio/common/interfaces';
|
|
|
|
import { Granularity } from '@ghostfolio/common/types';
|
|
|
|
import { Granularity } from '@ghostfolio/common/types';
|
|
|
@ -25,7 +23,9 @@ import got from 'got';
|
|
|
|
export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
private readonly URL = 'https://api.coingecko.com/api/v3';
|
|
|
|
private readonly URL = 'https://api.coingecko.com/api/v3';
|
|
|
|
|
|
|
|
|
|
|
|
public constructor() {}
|
|
|
|
public constructor(
|
|
|
|
|
|
|
|
private readonly configurationService: ConfigurationService
|
|
|
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
public canHandle(symbol: string) {
|
|
|
|
public canHandle(symbol: string) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -47,7 +47,7 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
abortController.abort();
|
|
|
|
abortController.abort();
|
|
|
|
}, DEFAULT_REQUEST_TIMEOUT);
|
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
|
|
|
|
|
|
|
|
|
|
const { name } = await got(`${this.URL}/coins/${aSymbol}`, {
|
|
|
|
const { name } = await got(`${this.URL}/coins/${aSymbol}`, {
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
@ -59,7 +59,9 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
let message = error;
|
|
|
|
let message = error;
|
|
|
|
|
|
|
|
|
|
|
|
if (error?.code === 'ABORT_ERR') {
|
|
|
|
if (error?.code === 'ABORT_ERR') {
|
|
|
|
message = `RequestError: The operation was aborted because the request to the data provider took more than ${DEFAULT_REQUEST_TIMEOUT}ms`;
|
|
|
|
message = `RequestError: The operation was aborted because the request to the data provider took more than ${this.configurationService.get(
|
|
|
|
|
|
|
|
'REQUEST_TIMEOUT'
|
|
|
|
|
|
|
|
)}ms`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Logger.error(message, 'CoinGeckoService');
|
|
|
|
Logger.error(message, 'CoinGeckoService');
|
|
|
@ -95,7 +97,7 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
abortController.abort();
|
|
|
|
abortController.abort();
|
|
|
|
}, DEFAULT_REQUEST_TIMEOUT);
|
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
|
|
|
|
|
|
|
|
|
|
const { prices } = await got(
|
|
|
|
const { prices } = await got(
|
|
|
|
`${
|
|
|
|
`${
|
|
|
@ -141,7 +143,7 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async getQuotes({
|
|
|
|
public async getQuotes({
|
|
|
|
requestTimeout = DEFAULT_REQUEST_TIMEOUT,
|
|
|
|
requestTimeout = this.configurationService.get('REQUEST_TIMEOUT'),
|
|
|
|
symbols
|
|
|
|
symbols
|
|
|
|
}: {
|
|
|
|
}: {
|
|
|
|
requestTimeout?: number;
|
|
|
|
requestTimeout?: number;
|
|
|
@ -183,7 +185,9 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
let message = error;
|
|
|
|
let message = error;
|
|
|
|
|
|
|
|
|
|
|
|
if (error?.code === 'ABORT_ERR') {
|
|
|
|
if (error?.code === 'ABORT_ERR') {
|
|
|
|
message = `RequestError: The operation was aborted because the request to the data provider took more than ${DEFAULT_REQUEST_TIMEOUT}ms`;
|
|
|
|
message = `RequestError: The operation was aborted because the request to the data provider took more than ${this.configurationService.get(
|
|
|
|
|
|
|
|
'REQUEST_TIMEOUT'
|
|
|
|
|
|
|
|
)}ms`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Logger.error(message, 'CoinGeckoService');
|
|
|
|
Logger.error(message, 'CoinGeckoService');
|
|
|
@ -210,7 +214,7 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
abortController.abort();
|
|
|
|
abortController.abort();
|
|
|
|
}, DEFAULT_REQUEST_TIMEOUT);
|
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT'));
|
|
|
|
|
|
|
|
|
|
|
|
const { coins } = await got(`${this.URL}/search?query=${query}`, {
|
|
|
|
const { coins } = await got(`${this.URL}/search?query=${query}`, {
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
@ -231,7 +235,9 @@ export class CoinGeckoService implements DataProviderInterface {
|
|
|
|
let message = error;
|
|
|
|
let message = error;
|
|
|
|
|
|
|
|
|
|
|
|
if (error?.code === 'ABORT_ERR') {
|
|
|
|
if (error?.code === 'ABORT_ERR') {
|
|
|
|
message = `RequestError: The operation was aborted because the request to the data provider took more than ${DEFAULT_REQUEST_TIMEOUT}ms`;
|
|
|
|
message = `RequestError: The operation was aborted because the request to the data provider took more than ${this.configurationService.get(
|
|
|
|
|
|
|
|
'REQUEST_TIMEOUT'
|
|
|
|
|
|
|
|
)}ms`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Logger.error(message, 'CoinGeckoService');
|
|
|
|
Logger.error(message, 'CoinGeckoService');
|
|
|
|