Get live prices of BTC, ETH, TRX, and other cryptocurrencies using NodeJS

CoinGecko is a free API tool to fetch cryptocurrency prices, publicly available and without limits. At the moment of writing this post, they track more than 6285 coins, and the data is reliable regarding time and delays.

This tutorial presents a basic guide on how to use CoinGecko on NodeJS using the CoinGecko-API library ( https://github.com/miscavage/CoinGecko-API), which is a wrapper to interact with the API.

To install it, we use the npm install command:

npm install coingecko-api

const CoinGecko = require('coingecko-api');

And the new can start fetching prices with the client. In this case, I choose to use the market bitfinex to get prices, and I’m only requesting bitcoin:

const CoinGeckoClient = new CoinGecko();
    let data = await CoinGeckoClient.exchanges.fetchTickers('bitfinex', {
        coin_ids: ['bitcoin']
    });
    var _coinList = {};
    var _datacc = data.data.tickers.filter(t => t.target == 'USD');
    [
        'BTC'
    ].forEach((i) => {
        var _temp = _datacc.filter(t => t.base == i);
        var _res = _temp.length == 0 ? [] : _temp[0];
        _coinList[i] = _res.last;
    })
console.log(_coinList);

#nodejs #cryptocurrency #javascript

Fetching cryptocurrency prices with CoinGecko using NodeJS
14.30 GEEK