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

@public-js/exchange-rates

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@public-js/exchange-rates

An extensive exchange rates API client supporting multiple services for best results

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

@public-js/exchange-rates

Build Version Downloads Size

CodeQL Codacy Codecov Code Climate

An extensive exchange rates API client supporting multiple services for best results


Installing

Add the package to your project by running:

npm i @public-js/exchange-rates

Usage

Instantiate a class:

import { ExchangeRates } from '@public-js/exchange-rates';

const service = await new ExchangeRates({
  OpenexchangeratesOrg: env.OXR_API_KEY,
  ExchangerateHost: true,
});

Fetch the latest rates:

const rates = await service.getRates('USD', ['EUR', 'CNY']);
console.log(rates); // {"CNY":6.8936,"EUR":0.901185}

Fetch the historical rates:

const rates = await service.getRates('USD', ['EUR', 'CNY'], '2023-01-15');
console.log(rates); // {"CNY":6.8936,"EUR":0.901185}

Supported services

Note The majority of services require an API key/token to work. This doesn't apply to ExchangerateHost, which needs any truthy value provided as a key to be active.

How does it work

When the ExchangeRates class is instantiated it requires a configuration object to be provided. The said object has to list the desired services and their respective API keys/tokens.

Since some of the services don't handle unsupported currency codes well, they will be queried for a full rates list which then gets filtered out. This process is repeated for each service until all of them are queried or the required currencies are fetched.

The order of the services is listed in the "Supported services" section, it can't be altered at a time and is pre-defined based on data reliability, precision and currency coverage. It is possible however to enable only part of the supported services by providing only some of the API keys.

Resources

License

MIT, full license text. Read more about it on TLDRLegal.

Keywords

FAQs

Package last updated on 27 Oct 2023

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