Crypto-Convert
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();
(async function(){
await convert.ready();
convert.BTC.USD(1);
convert.ETH.JPY(255);
convert.LINK.LTC(5);
convert.USD.CRO(100.1256);
})();
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,
fiatInterval: (60 * 1e3 * 60),
calculateAverage: true,
binance: true,
bitfinex: true,
coinbase: true,
kraken: true,
onUpdate: (tickers, isFiatUpdate?)=> any
HTTPAgent: null
});
Other Parameters
Get crypto prices last updated timestamp (ms)
console.log(convert.lastUpdated)
Get the list supported currencies
console.log(convert.list);
Get cryptocurrencies metadata (title/symbol/logo/rank)
console.log(convert.cryptoInfo);
Custom Plug-ins
In cases when you want to support a custom currency you can do so like this:
convert.addCurrency(
'ANYCURRENCY',
'USD',
async ()=>{
return price;
},
5000
);
Adding custom plugins is useful for supporting more fiats, precious metals, or anything that can be exchanged.
For removing custom currencies:
convert.removeCurrency('ANYCURRENCY');