Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

currency-rates-store

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

currency-rates-store

A storage bot which sync exchange rates

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

A storage bot to sync exchange rates with any exchange rates api

Example

const CurrStore = require('currency-rates-store');
const pull = require('currency-restapi-currencylayer').Live('YOUR_ACCESS_KEY');


// Default on `USD`, and 3 hours between requests
var store = CurrStore({pull: pull});


// CurrencyRatesStore is an EventEmitter, 
['error', 'warn', 'info'].forEach(lv=> store.on(lv, e=> console.log(e)));


store.on('load', store=>{

  // convert €100 EUR to USD 
  console.log(store.convert(100).from('EUR').to('USD'));
  
  // convert € 1 EUR to USD
  console.log(store.from('EUR').to('CAD'));
  
  // or skip `.from()`, if the `store.base` is `USD`
  console.log(store.convert(100).to('EUR'));
  
  // simply pass the pair
  console.log(store.pair('EURUSD'));
  
  // or pass the symbol one by one
  console.log(store.rate('USD', 'EUR'));
  
  // same as above, if the exchange rates storage is based on `USD`
  console.log(store.rate('EUR'));
  

});

Options

  • pull: An async function. it should callback the latest rates in the following structure. Usually, it wraps exchange rates sites api. Following are modules designed for currency-rates-store

    • currency-restapi-currencylayer
    • currency-restapi-openexchange
  • base: 'USD|EUR|GBP...'. which currency this rates should be based on. Default: USD

  • wait: refresh in milliseconds. Default to 3 hours between refreshs. minimum 10 minutes. However, if any error occurred from pull callback, it will use util-retry to retry the pull 3 times.

{
  base: 'USD|EUR|GBP'   - tell which currency this rates is based on
  rates: {
    USD: 1,             - If base == 'USD', this value should be 1
    GBP: ...
    EUR: ...
    ...
  },
  ts: {Milliseconds}
}

Event: 'load'

function (store) { } Emitted when the first valid rates is recieved

Event: 'error'

function (error) { }

See source code

Event: 'warn'

function (msg) {}

Emitted when the received rates is based on another currency which is different from base property configured on this store. A rebase calculation will happen, and emit this warning.

Event: 'info'

function (info) {} Emitted for logging purpose.

FAQs

Package last updated on 17 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc