diff --git a/prices/prices.controller.ts b/prices/prices.controller.ts index 7ab9f27..91e6393 100644 --- a/prices/prices.controller.ts +++ b/prices/prices.controller.ts @@ -52,7 +52,7 @@ export class PricesController { @ApiResponse({ description: 'Returns the price of EUR in USD', }) - getEuroPrice(): PriceQueryCurrencies { + getEuroPrice(): Promise { return this.pricesService.getEuroPrice(); } @@ -60,7 +60,7 @@ export class PricesController { @ApiResponse({ description: 'Returns the current price of the DEPS token', }) - async getDepsPrice(): Promise { - return await this.pricesService.getDepsPrice(); + getDepsPrice(): Promise { + return this.pricesService.getDepsPrice(); } } diff --git a/prices/prices.service.ts b/prices/prices.service.ts index f8e7cb6..cb17069 100644 --- a/prices/prices.service.ts +++ b/prices/prices.service.ts @@ -65,7 +65,13 @@ export class PricesService { async getDepsPrice(): Promise { if (!this.depsPrice) this.depsPrice = await this.fetchFromEcosystemDeps(this.getDeps()); - return { usd: Number(this.depsPrice.usd.toFixed(4)), eur: Number(this.depsPrice.eur.toFixed(4)) }; + if (!this.euroPrice) this.euroPrice = await this.fetchEuroPrice(); + + return { + usd: Number(this.depsPrice.usd.toFixed(4)), + eur: Number(this.depsPrice.eur.toFixed(4)), + btc: Number((this.depsPrice.eur * this.euroPrice.btc).toFixed(9)), + }; } getCollateral(): ApiPriceERC20Mapping { @@ -84,8 +90,14 @@ export class PricesService { return c; } - getEuroPrice(): PriceQueryCurrencies { - return this.euroPrice; + async getEuroPrice(): Promise { + if (!this.euroPrice) this.euroPrice = await this.fetchEuroPrice(); + + return { + usd: Number(this.euroPrice.usd.toFixed(4)), + eur: Number(this.euroPrice.eur.toFixed(4)), + btc: Number(this.euroPrice.btc.toFixed(9)), + }; } async fetchFromEcosystemDeps(erc: ERC20Info): Promise { @@ -135,13 +147,18 @@ export class PricesService { } async fetchEuroPrice(): Promise { - const url = `/api/v3/simple/price?ids=usd&vs_currencies=eur`; - const data = await (await COINGECKO_CLIENT(url)).json(); + const url = `/api/v3/simple/price?ids=usd&vs_currencies=eur%2Cbtc`; + const data = await(await COINGECKO_CLIENT(url)).json(); if (data.status) { this.logger.debug(data.status?.error_message || 'Error fetching price from coingecko'); return null; } - return { eur: 1, usd: 1 / Number(data.usd.eur) }; + + return { + eur: 1, + usd: 1 / Number(data.usd.eur), + btc: 1 / Number(data.usd.eur / data.usd.btc), + }; } async fetchFromZchfSources(): Promise { diff --git a/prices/prices.types.ts b/prices/prices.types.ts index 3aec356..90e2a36 100644 --- a/prices/prices.types.ts +++ b/prices/prices.types.ts @@ -17,6 +17,7 @@ export type ERC20Info = { export type PriceQueryCurrencies = { usd?: number; eur?: number; + btc?: number; }; export type PriceQuery = ERC20Info & {