simple-open-exchange-rates
v0.3.0
Published
Simple currency conversion using OpenExchangeRates.org
Downloads
8
Maintainers
Readme
Simple Open Exchange Rates
Extremely simple way to convert rates between currencies using rates at OpenExchangeRates.org.
Pulls the exchange rate remotely and saves locally to a text file.
Getting Started
Register for a client key at OpenExchangeRates.org
Install the package:
npm install currency-converter
Use it:
var cc = require('currency-converter')({
CLIENTKEY: YOUR_OPEN_EXCHANGE_RATES_KEY, [fetchInterval: 3600000]
});
NOTE: Default fetchInterval value is set to one hour.
Usage
This module makes it extremely easy for you to convert currencies.
The very basic input takes in two parameters. convertFrom & convertTo must be valid country codes. See list here.
The module fetches live rates on initialize, saves it locally, and retrieves locally saved rates by default, unless otherwise specified.
.convert(amount, convertFrom, convertTo, [live])
Converts an amount specified to a specific currency. live is an optional parameter that uses live rates from openexchangerates.org
Response:
const converted = await cc.rates(1, 'USD', 'EUR');
// {
// "currency": "EUR",
// "symbol": "€",
// "amount": 0.76
// }
.rates(convertFrom, convertTo, [live])
Returns the conversion rate between two currencies:
const rate = await cc.rates('USD', 'EUR');
// 0.76
Fetch the live rate:
const rate = await cc.rates('USD', 'EUR', true);
// 0.76
.currencies
The map of currency codes to info about the currency
cc.currencies.EUR
// {
// "currency": "EUR",
// "symbol": "€",
// "amount": 0.76
// }
.shutdown
Stop the periodic polling for rates.
cc.shutdown();
If you don't do this, your script will never terminate normally since there will be a dangling timeout.
Credits
A fork of dmamaril/npm-currency-converter but that project is unmaintained.