Skip to content

💱 A NodeJS cryptocurrency converter library that doesn't require subscribing to any API calls.

License

Notifications You must be signed in to change notification settings

olarotseyi/nodejs-crypto-converter

 
 

Repository files navigation

NodeJS Crypto Converter

Build Status Known Vulnerabilities supported node versions codecov license: MIT Maintainability npm version npm

A minimal crypto crypto converter library for NodeJS that works out of the box.

Getting started

Installation

This package can be installed using npm

npm install crypto-converter-lt

or, yarn

yarn add crypto-converter-lt

Usage

Import crypto-converter-lt.

const CC = require('crypto-converter-lt')

Then instantiate with either the empty constructor

let cryptoConverter = new CC()

Or, with a json object

let cryptoConverter = new CC({from:"BTC", to:"ETH", amount:100})

The convert method will return the conversion based on the last conversion rate and can be used as a promise.

cryptoConverter.convert().then((response) => {
    console.log(response) //or do something else
})

convert can also take the amount as a parameter.

cryptoConverter.convert(100).then((response) => {
    console.log(response) //or do something else
})

To find the rates use the rates method.

cryptoConverter.rates().then((response) => {
    console.log(response) //or do something else
})

Rates can be cached for cryptocurrency pairs. To implement rate caching, instantiate an object of CryptoConverter only once in your project, in a CyptoConverter file, and setup rates caching then import the instance of CryptoConverter from the CyptoConverter file in your project across the rest of your project. Use chaining to convert cryptocurrencies when caching is implemented. Below is an example of a CyptoConverter file.

Note: Rates are not actually deleted after the ratesCacheDuration. The rate remains in the rates cache of the CyptoConverter object until a request is made for the same cryptocurrency pair after the rates cache duration has been exceeded at which point, the old rate is overwritten.

const CC = require('crypto-converter-lt')

let cryptoConverter = new CC()

let ratesCacheOptions = {
    isRatesCaching: true, // Set this boolean to true to implement rate caching
    ratesCacheDuration: 3600 // Set this to a positive number to set the number of seconds you want the rates to be cached. Defaults to 3600 seconds (1 hour)
}

cryptoConverter = cryptoConverter.setupRatesCache(ratesCacheOptions)

module.exports = cryptoConverter

Chaining is also supported.

cryptoConverter.from("LTC").to("ETH").amount(125).convert().then((response) => {
    console.log(response) //or do something else
})

Issues

If any issues are found, they can be reported here.

License

This project is licensed under the MIT license.

About

💱 A NodeJS cryptocurrency converter library that doesn't require subscribing to any API calls.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%