1.3.1 • Published 2 years ago

conversao-crypto-rodrigo v1.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Using the library

You can basically use this library for two things:

  • Check the quote on any crypto currency in the world, this basic quote is given to you in USD (United States Dollar).

  • Convert one specific crypto currency into one, or many others.

Installing the library

To install the library, all you have to do is run the following shell command in the root of your project:

npm install conversao-crypto-rodrigo

Importing it into your project

Just like any other lib, you must import it into your project in order to use it, we do it as follows:

const cryptoConversor = require('conversa-crypto-rodrigo');

Just so we are clear, you can give it any name when you import it, cryptoConversor was just an example.

Getting a currency's quote in USD

Now that you've installed and imported the lib into your project, you can use the quote method giving it all the symbols of the currencies you wanna quote. In the example below, I wanna quote the values of 1 bitcoin e 1 etherium, in USD:

const currenciesQuotes = cryptoConversor.quote(['BTC', 'ETH']) 

Running this, just like that, might give you the following error:

{ error: 'BTC was not found or missing SECRET_API_KEY on .env file'}

If you get this error, it prabibly means you haven't added your secret API key to a .env file. So go ahead and create a .env file. Inside it, you should have the value of your secret API key, which can be obtained here.

Once you have created an account and/or logged in, you should be able to have access to the key, now all you have to do is add to the file like this:

SECRET_API_KEY="YOUR_SECRET_KEY"

It is safer if you put all of your key in between quotes. Done, all yout major configuration is now good to go! A successfull response for the lib, should look like this:

[
    {
      id: 1,
      name: 'Bitcoin',
      symbol: 'BTC',
      slug: 'bitcoin',
      date_added: '2013-04-28T00:00:00.000Z',
      last_updated: '2022-02-15T09:34:00.000Z',
      quotes: [Object]
    },
    {
      id: 1027,
      name: 'Ethereum',
      symbol: 'ETH',
      slug: 'ethereum',
      date_added: '2015-08-07T00:00:00.000Z',
      last_updated: '2022-02-15T09:34:00.000Z',
      quotes: [Object]
    }
]

The quotes object contains all the information regarding the USD values of that crypto.

Note

This lib relies on an API request, so it should be use in an async function, otherwise you will receive only promises and not the real results!

Converting one crypto into one or many others

For that, all you have to do is use the conversion method in the cryptoConversor object. You must give it the origin crypto's symbol, the amount you want to convert, and an array with all the cryptos you want it to the be converted to.

So lets assume I want to figure out how much Etherium and Tether are 3 bitcoins worth, I would use the method like this:

const currenciesConversion = cryptoConversor.conversion('BTC', 3, ['ETH','USDT']);

The successfull result should look like this:

{
    id: 1,
    symbol: 'BTC',
    name: 'Bitcoin',
    amount: 3,
    last_updated: '2022-02-15T09:59:00.000Z',
    quotes: [ [Object], [Object] ]
  }

In the quotes key of the response we have the two objects with the corresponding conversions.

Note:

You must keep in mind that both methods require an SECRET_API_KEY in the .env file (as mentioned before), and both methods have asynchronous responses, so you shoud use async and await.

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago