Socket
Socket
Sign inDemoInstall

ecb-euro-fx

Package Overview
Dependencies
16
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ecb-euro-fx

Module to get eurofxref daily feeds from ECB and returns them in a nice object format.


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
758 kB
Created
Weekly downloads
 

Readme

Source

ecb-euro-fx

The ecb publishes a daily feed with the latest euro foreign exchange rates (in XML format). This module parses this feed and convert it into a handy javascript object that can be used in any related FX calculations involving the Euro and other currencies.

Install

You can install with [npm]:

$ npm install --save ecb-euro-fx

Usage

The module doesn't require any parameters, but it returns a promise that needs to be handled to use the resulting object:


const ecbFx = require('ecb-euro-fx')
ecbFx().then(ratesObj => { console.log(ratesObj) })

// It will show in the console, an object like:
// { subject: 'Reference rates',
//   sender: 'European Central Bank',
//   time: '2019-05-08',
//   rates:
//    [ { currency: 'USD', rate: '1.1202' },
//      { currency: 'JPY', rate: '123.31' },
//      { currency: 'BGN', rate: '1.9558' },
//      { currency: 'CZK', rate: '25.727' },
//   ...
//  ratesBySymbol:
//   { USD: 1.1202,
//     JPY: 123.31,
//     BGN: 1.9558,
//     CZK: 25.727,

Note that the module returns an array of objects with the rates (as in the ECB feed), but it also provides an object with the ratesBySymbol. You can use this object to right away calculate the FX for a particular rate.

Let's say you want to calculate how many dollars are 50 euro today?


const ecbFx = require('ecb-euro-fx')
ecbFx().then(ratesObj => {
  const dollars = parseInt(50 * ratesObj.ratesBySymbol.USD)
  console.log(`50 Euro are ${dollars} Dollars`)
})

// It will show in the console the dollars with the current FX

Both the request to the ECB servers and the object conversion are cached, so any subsequent call to the module should be really fast.

Running tests

You can run the tests with JEST and check the functionality of this module using:

$ npm install && npm test

License

Copyright © 2019, Juan Convers. Released under the MIT License.

Keywords

FAQs

Last updated on 09 May 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc