2.1.7 • Published 1 month ago

crypto-convert v2.1.7

Weekly downloads
14
License
Elis
Repository
github
Last release
1 month ago

Crypto-Convert

npm npm

Convert crypto to fiat and vice-versa instantly.

  • Top 100+ Cryptocurrencies Supported
  • 20+ fiats Supported
  • Instantly convert, no slow promises.
  • Cross-compatible on Node.js & Browser
  • Price & Ticker information updated on a configurable interval from multiple secure sources (Binance, Bitfinex, Coinbase, Kraken)
  • Any pair can be converted, be it Crypto -> Crypto or Fiat -> Crypto.

HTTP API

Free public API

https://api.coinconvert.net/convert/btc/usd?amount=1

Installation

npm i crypto-convert

Import

import CryptoConvert from 'crypto-convert';

Or with require, import it like this to get TypeScript:

const CryptoConvert = require("crypto-convert").default;

CDN For Browsers

<script src='https://coinconvert.net/assets/js/crypto-convert.min.js'></script>

Usage

const convert = new CryptoConvert(/*options?*/);

(async function(){

	await convert.ready(); //Wait for the initial cache to load
	
	convert.BTC.USD(1);
	convert.ETH.JPY(255);
	convert.LINK.LTC(5);
	convert.USD.CRO(100.1256);

	//... convert any pair
	// prices are automatically updated on background

})();

Note: You should only initialize the CryptoConvert class once. It's recommend to make a seperate file for it.

Configuration

Here are some of the options you can specify on initialization:

new CryptoConvert({
	cryptoInterval: 5000, //Crypto prices update interval in ms (default 5 seconds on Node.js & 15 seconds on Browsers)
	fiatInterval: (60 * 1e3 * 60), //Fiat prices update interval (default every 1 hour)
	calculateAverage: true, //Calculate the average crypto price from exchanges
	binance: true, //Use binance rates
	bitfinex: true, //Use bitfinex rates
	coinbase: true, //Use coinbase rates
	kraken: true, //Use kraken rates
	onUpdate: (tickers, isFiatUpdate?)=> any //Callback on every crypto update
	HTTPAgent: null //HTTP Agent for server-side proxies (Node.js only)
});

Other Parameters

Get crypto prices last updated timestamp (ms)

console.log(convert.lastUpdated)
// Prints:
// 1664657163857

Get the list supported currencies

console.log(convert.list);
// Prints:
// {
//		crypto: ['BTC','ETH', ... + 148 more],
//		fiats: ['USD', 'EUR', ... + 25 more]	
// }

Get cryptocurrencies metadata (title/symbol/logo/rank)

console.log(convert.cryptoInfo);

// Prints:
// {
//		BTC: {
//		    "id": 1,
//		    "title": "Bitcoin",
//		    "symbol": "BTC",
//		    "logo": "[logo_url]",
//		    "rank": 1
//		}
//		ETH: {
//			...
//		}
//		... +148 more
// }

Custom Plug-ins

In cases when you want to support a custom currency you can do so like this:

convert.addCurrency(
	'ANYCURRENCY',  //Your custom currency symbol here
	'USD', //The quote fiat price. Must be a supported fiat currency.
	async ()=>{
		//...call your api here
		return price;
	}, 
	5000 //Update interval in ms
);

Adding custom plugins is useful for supporting more fiats, precious metals, or anything that can be exchanged.

For removing custom currencies:

convert.removeCurrency('ANYCURRENCY');
2.1.7

1 month ago

2.1.6

8 months ago

2.1.5

1 year ago

2.1.2

2 years ago

2.0.3

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.0.5

2 years ago

2.1.3

2 years ago

2.0.4

2 years ago

2.1.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

2.0.0-latest

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago