crypto-converter-ken
v1.0.3
Published
<h2>Node application to convert crypto coins.</h2>
Downloads
3
Readme
Crypto Converter Kenzie
It creates a small library in Typescript that handles information about normal and crypto currencies and dealt conversion between coins.
Requirements
Node
Warning
Please, for more stability use node version 14 ou 16.
If you do not know which version you are using, type this on terminal:
$ node --version
If you do want to change your version of Node, type this on terminal:
$ nvm use 14
$ nvm use 16
To start
You are going to need an API key from Coin Market Cap.
- Check the documentation of the used API HERE!
Installation
First, you need to install this lib. On terminal, at the root of your project, type:
$ npm i crypto-converter-ken
Create an .env file and insert the key you got at Coin Market Cap. Example:
API_KEY_COIN_MARKET = a0000000-000e-0d00-0c00-000cd00d00e0
Working
First, import KenCrypto to your file (e.g. app.js), like this:
import { KenCrypto } from "crypto-converter-ken";
Then, instance our lib into a variable, like this:
const ken = new KenCrypto();
Now you can use Quotes and Conversion
Examples:
- It must bring the current quote data for the informed currency(s) comapred to USD (United States Dollar).
ken.quotes(["BTC"]).then((res) => console.log((res as IQuotes).data.BTC));
Output in console:
{
id: 1,
name: 'Bitcoin',
symbol: 'BTC',
slug: 'bitcoin',
date_added: '2013-04-28T00:00:00.000Z',
last_updated: '2022-01-28T02:43:00.000Z',
quote: {
USD: {
price: 36837.90739073404,
last_updated: '2022-01-28T02:43:00.000Z'
}
}
}
In the same example, you can use a variable too:
let quote_data = ken.quotes(["ETH"]).then((res) => console.log((res as IQuotes).data.ETH));
Output in console:
{
id: 1027,
name: 'Ethereum',
symbol: 'ETH',
slug: 'ethereum',
date_added: '2015-08-07T00:00:00.000Z',
last_updated: '2022-01-28T02:51:00.000Z',
quote: {
USD: {
price: 2391.531036761025,
last_updated: '2022-01-28T02:51:00.000Z'
}
}
}
If you want to use more than one currency:
ken.quotes(["BTC", "ETH"]).then((res) => console.log(res as IQuotes));
Output in console:
{
data: {
BTC: {
id: 1,
name: 'Bitcoin',
symbol: 'BTC',
slug: 'bitcoin',
date_added: '2013-04-28T00:00:00.000Z',
last_updated: '2022-01-28T02:55:00.000Z',
quote: [Object]
},
ETH: {
id: 1027,
name: 'Ethereum',
symbol: 'ETH',
slug: 'ethereum',
date_added: '2015-08-07T00:00:00.000Z',
last_updated: '2022-01-28T02:55:00.000Z',
quote: [Object]
}
}
}
- It should bring the conversion values between the desired currencies.
Convert between two crypto coins:
ken
.conversion("BTC", 0.005, ["ETH"])
.then((res) => console.log((res as IConversion).data.BTC));
Output in console:
{
id: 1,
symbol: 'BTC',
name: 'Bitcoin',
amount: 0.005,
last_updated: '2022-01-28T02:22:00.000Z',
quote: {
ETH: {
price: 0.07733428157310678,
last_updated: '2022-01-28T02:21:00.000Z'
}
}
}
Convert between a crypto currency and a regular currency (like Great Britain Pound, GBP):
ken
.conversion("BTC", 0.005, ["GBP"])
.then((res) => console.log((res as IConversion).data.BTC));
Output in console:
{
id: 1,
symbol: 'BTC',
name: 'Bitcoin',
amount: 0.005,
last_updated: '2022-01-28T03:02:00.000Z',
quote: {
GBP: {
price: 137.89626528901127,
last_updated: '2022-01-28T03:02:02.000Z'
}
}
}