From 53df9d3a2b64f356a7c7a913f2fc31d82abc52d8 Mon Sep 17 00:00:00 2001 From: Tobias Palmer Date: Wed, 10 Jun 2020 15:30:04 +0200 Subject: [PATCH] coingecko API --- src/app/services/price.service.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/app/services/price.service.ts b/src/app/services/price.service.ts index 07f18d94..c086694b 100644 --- a/src/app/services/price.service.ts +++ b/src/app/services/price.service.ts @@ -4,7 +4,7 @@ import {BehaviorSubject} from "rxjs/BehaviorSubject"; @Injectable() export class PriceService { - apiUrl = `https://api.coinmarketcap.com/v1/`; + apiUrl = `https://api.coingecko.com/api/v3/coins/nano?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`; price = { lastPrice: 1, @@ -16,16 +16,14 @@ export class PriceService { async getPrice(currency = 'USD') { if (!currency) return; // No currency defined, do not refetch - const convertString = currency !== 'USD' && currency !== 'BTC' ? `?convert=${currency}` : ``; - const response: any = await this.http.get(`${this.apiUrl}ticker/nano/${convertString}`).toPromise(); - if (!response || !response.length) { + const response: any = await this.http.get(`${this.apiUrl}`).toPromise(); + if (!response) { return this.price.lastPrice; } - const quote = response[0]; - const currencyPrice = quote[`price_${currency.toLowerCase()}`]; - const btcPrice = quote.price_btc; - const usdPrice = quote.price_usd; + const quote = response.market_data.current_price; + const currencyPrice = quote[currency.toLowerCase()]; + const btcPrice = quote.btc; this.price.lastPrice = currencyPrice; this.price.lastPriceBTC = btcPrice;