npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crypto-capital

v1.0.1

Published

Cripto Capital é um pacote criado para facilitar a forma de pegar os valores atualizado das criptomoedas e as converções entre elas e moedas tradicionais, utilizando a api da [CoinMarketCap](https://coinmarketcap.com/api/documentation/v1/).

Downloads

3

Readme

Crypto Capital

Cripto Capital é um pacote criado para facilitar a forma de pegar os valores atualizado das criptomoedas e as converções entre elas e moedas tradicionais, utilizando a api da CoinMarketCap.

Instalação

usando npm:

npm i crypto-capital

usando yarn:

yarn add crypto-capital

Exemplo

Para usar importe a classe, crie uma nova instância e forneça sua chave api ao instanciar a classe. Voce pode obter sua chave CoinMarketCap aqui.

const APIKey = "d6e93c00-2399-4296-8ae9-3ecff4bfdf3a";
const cryto = new CryptoCapital(APIKey);

Atualmente estão disponiveis dois metodos ".quotes() e .conversion()":

Metodo .quotes():

O metodo quote exige um array das siglas das cryptomoedas e retorna uma promisse:

cryto.quotes(["BTC"]).then((res) => console.log(res));
// console.log
{
  "data": {
    "BTC": {
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "num_market_pairs": 9082,
      "date_added": "2013-04-28T00:00:00.000Z",
      "tags": [...tags],
      "max_supply": 21000000,
      "circulating_supply": 18937062,
      "total_supply": 18937062,
      "is_active": 1,
      "platform": null,
      "cmc_rank": 1,
      "is_fiat": 0,
      "last_updated": "2022-01-22T18:16:00.000Z",
      "quote": {
        "USD": {
          "price": 34526.19599506767,
          "volume_24h": 44564695510.34316,
          "volume_change_24h": 19.346,
          "percent_change_1h": -1.06712614,
          "percent_change_24h": -10.54840373,
          "percent_change_7d": -20.28563616,
          "percent_change_30d": -31.58034291,
          "percent_change_60d": -39.734065,
          "percent_change_90d": -42.52358372,
          "market_cap": 653824714182.7482,
          "market_cap_dominance": 41.513,
          "fully_diluted_market_cap": 725050115896.42,
          "last_updated": "2022-01-22T18:16:00.000Z"
        }
      }
    }
  }
}

Metodo .conversion():

Usar o metodo coversion exige três parametros: sigla da moeda, montante e um array de moedas alvos.

cryto.conversion("btc", 0.1, ["usd"]).then((res) => console.log(res));
// console
{
  "status": {
    "timestamp": "2022-01-22T18:27:19.288Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 30,
    "credit_count": 1,
    "notice": null
  },
  "data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 0.1,
    "last_updated": "2022-01-22T18:27:00.000Z",
    "quote": {
      "USD": {
        "price": 3466.730521496345,
        "last_updated": "2022-01-22T18:27:00.000Z"
      }
    }
  }
}

Type Guards

Exitem três Type Guards disponiveis para tratar os diferentes tipos de retorno da promisse: isError(), isQuoteResponse() e isConversionResponse():

cryto.quotes(["BTC"]).then((res) => {
  if (isError(res)) {
    console.log(res.status);
  } else if (isQuoteResponse(res)) {
    console.log(res.BTC.id);
  } else {
    console.log(res);
  }
});
cryto.conversion("btc", 0.1, ["usd"]).then((res) => {
  if (isError(res)) {
    console.log(res.status);
  } else if (isConversionResponse(res)) {
    console.log(res.data.BTC.id);
  } else {
    console.log(res);
  }
});

Tecnologias

Licença