Browse Source

feat(coingecko.service): Add `pro` API key support

Create new environment variable `COINGECKO_API_KEY_PRO`.
pull/2827/head
Tanguy Herbron 2 years ago
committed by Thomas Kaul
parent
commit
ba96e13f88
  1. 1
      apps/api/src/services/configuration/configuration.service.ts
  2. 7
      apps/api/src/services/data-provider/coingecko/coingecko.service.ts
  3. 1
      apps/api/src/services/interfaces/environment.interface.ts

1
apps/api/src/services/configuration/configuration.service.ts

@ -16,6 +16,7 @@ export class ConfigurationService {
CACHE_QUOTES_TTL: num({ default: 1 }), CACHE_QUOTES_TTL: num({ default: 1 }),
CACHE_TTL: num({ default: 1 }), CACHE_TTL: num({ default: 1 }),
COINGECKO_API_KEY_DEMO: str({ default: '' }), COINGECKO_API_KEY_DEMO: str({ default: '' }),
COINGECKO_API_KEY_PRO: str({ default: '' }),
DATA_SOURCE_EXCHANGE_RATES: str({ default: DataSource.YAHOO }), DATA_SOURCE_EXCHANGE_RATES: str({ default: DataSource.YAHOO }),
DATA_SOURCE_IMPORT: str({ default: DataSource.YAHOO }), DATA_SOURCE_IMPORT: str({ default: DataSource.YAHOO }),
DATA_SOURCES: json({ DATA_SOURCES: json({

7
apps/api/src/services/data-provider/coingecko/coingecko.service.ts

@ -22,7 +22,7 @@ import got, { Headers } from 'got';
@Injectable() @Injectable()
export class CoinGeckoService implements DataProviderInterface { export class CoinGeckoService implements DataProviderInterface {
private headers: Headers = {}; private headers: Headers = {};
private readonly URL = 'https://api.coingecko.com/api/v3'; private readonly URL: string = 'https://api.coingecko.com/api/v3';
public constructor( public constructor(
private readonly configurationService: ConfigurationService private readonly configurationService: ConfigurationService
@ -30,6 +30,11 @@ export class CoinGeckoService implements DataProviderInterface {
if (this.configurationService.get('COINGECKO_API_KEY_DEMO')) { if (this.configurationService.get('COINGECKO_API_KEY_DEMO')) {
this.headers['x-cg-demo-api-key'] = this.configurationService.get('COINGECKO_API_KEY_DEMO'); this.headers['x-cg-demo-api-key'] = this.configurationService.get('COINGECKO_API_KEY_DEMO');
} }
if (this.configurationService.get('COINGECKO_API_KEY_PRO')) {
this.headers['x-cg-pro-api-key'] = this.configurationService.get('COINGECKO_API_KEY_PRO');
this.URL = 'https://pro-api.coingecko.com/api/v3';
}
} }
public canHandle(symbol: string) { public canHandle(symbol: string) {

1
apps/api/src/services/interfaces/environment.interface.ts

@ -7,6 +7,7 @@ export interface Environment extends CleanedEnvAccessors {
CACHE_QUOTES_TTL: number; CACHE_QUOTES_TTL: number;
CACHE_TTL: number; CACHE_TTL: number;
COINGECKO_API_KEY_DEMO: string; COINGECKO_API_KEY_DEMO: string;
COINGECKO_API_KEY_PRO: string;
DATA_SOURCE_EXCHANGE_RATES: string; DATA_SOURCE_EXCHANGE_RATES: string;
DATA_SOURCE_IMPORT: string; DATA_SOURCE_IMPORT: string;
DATA_SOURCES: string[]; DATA_SOURCES: string[];

Loading…
Cancel
Save