Skip to content

Commit

Permalink
Use api.coinstats.app for currency prices
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanerk authored May 22, 2020
1 parent 3ce46fd commit c7484fd
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/app/services/price.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {BehaviorSubject} from "rxjs/BehaviorSubject";

@Injectable()
export class PriceService {
apiUrl = `https://api.coinmarketcap.com/v1/`;
apiUrl = `https://api.coinstats.app/public/v1/`;

price = {
lastPrice: 1,
Expand All @@ -16,16 +16,15 @@ 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();
const convertString = currency !== 'USD' && currency !== 'BTC' ? `?currency=${currency}` : ``;
const response: any = await this.http.get(`${this.apiUrl}coins/nano${convertString}`).toPromise();
if (!response || !response.length) {
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 currencyPrice = quote.price;
const btcPrice = quote.priceBtc;

this.price.lastPrice = currencyPrice;
this.price.lastPriceBTC = btcPrice;
Expand Down

0 comments on commit c7484fd

Please sign in to comment.