|
|
@ -1,13 +1,11 @@ |
|
|
|
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 { |
|
|
|
IDataProviderHistoricalResponse, |
|
|
|
IDataProviderResponse |
|
|
|
} from '@ghostfolio/api/services/interfaces/interfaces'; |
|
|
|
import { |
|
|
|
DEFAULT_CURRENCY, |
|
|
|
DEFAULT_REQUEST_TIMEOUT |
|
|
|
} from '@ghostfolio/common/config'; |
|
|
|
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; |
|
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper'; |
|
|
|
import { DataProviderInfo } from '@ghostfolio/common/interfaces'; |
|
|
|
import { Granularity } from '@ghostfolio/common/types'; |
|
|
@ -25,7 +23,9 @@ import got from 'got'; |
|
|
|
export class CoinGeckoService implements DataProviderInterface { |
|
|
|
private readonly URL = 'https://api.coingecko.com/api/v3'; |
|
|
|
|
|
|
|
public constructor() {} |
|
|
|
public constructor( |
|
|
|
private readonly configurationService: ConfigurationService |
|
|
|
) {} |
|
|
|
|
|
|
|
public canHandle(symbol: string) { |
|
|
|
return true; |
|
|
@ -47,7 +47,7 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
abortController.abort(); |
|
|
|
}, DEFAULT_REQUEST_TIMEOUT); |
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT')); |
|
|
|
|
|
|
|
const { name } = await got(`${this.URL}/coins/${aSymbol}`, { |
|
|
|
// @ts-ignore
|
|
|
@ -59,7 +59,9 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
let message = error; |
|
|
|
|
|
|
|
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'); |
|
|
@ -95,7 +97,7 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
abortController.abort(); |
|
|
|
}, DEFAULT_REQUEST_TIMEOUT); |
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT')); |
|
|
|
|
|
|
|
const { prices } = await got( |
|
|
|
`${ |
|
|
@ -141,7 +143,7 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
} |
|
|
|
|
|
|
|
public async getQuotes({ |
|
|
|
requestTimeout = DEFAULT_REQUEST_TIMEOUT, |
|
|
|
requestTimeout = this.configurationService.get('REQUEST_TIMEOUT'), |
|
|
|
symbols |
|
|
|
}: { |
|
|
|
requestTimeout?: number; |
|
|
@ -183,7 +185,9 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
let message = error; |
|
|
|
|
|
|
|
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'); |
|
|
@ -210,7 +214,7 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
abortController.abort(); |
|
|
|
}, DEFAULT_REQUEST_TIMEOUT); |
|
|
|
}, this.configurationService.get('REQUEST_TIMEOUT')); |
|
|
|
|
|
|
|
const { coins } = await got(`${this.URL}/search?query=${query}`, { |
|
|
|
// @ts-ignore
|
|
|
@ -231,7 +235,9 @@ export class CoinGeckoService implements DataProviderInterface { |
|
|
|
let message = error; |
|
|
|
|
|
|
|
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'); |
|
|
|