Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

globalexchangerates

A JavaScript/TypeScript client library for interacting with the Global Exchange Rates API. Works in both Node.js and browser environments.

exchange rates, currency, finance, currency rates, currency exchange rates

readme

Global Exchange Rates

Global Exchange Rates Client

This is a TypeScript/JavaScript library designed to interact with the Global Exchange Rates API.

It provides a set of methods for retrieving exchange rates, currency and providers information, and converting amounts between currencies. The library is compatible with both Node.js and browser environments.

Global Exchange Rates API

The Global Exchange Rates API provides a simple and reliable way to download official exchange rates from central banks and tax authorities (providers) worldwide.

You can check the updated list from the official website.

Daily exchange rates of all the available currencies are also provided, calculated using a proprietary algorithm blending the official data from central banks and the market rate from commercial institutions.

Ideal for accounting, CRM and ERP systems, business intelligence, auditing, tax compliance and reporting.

Getting Started

  1. Sign up to the Developer API Portal and start the 30 day free trial.
  2. Get your API key.
  3. Install via npm:
npm install globalexchangerates

Usage

TypeScript

import { GlobalExchangeRatesClient } from 'globalexchangerates';

// Create a client instance
const client = new GlobalExchangeRatesClient('your_api_key');

async function fetchLatestRates() {
  try {
    // Get the latest exchange rates
    const rates = await client.getLatest();
    console.log(rates);

    // Get currencies
    const currencies = await client.getCurrencies();
    console.log(currencies);

    // Convert
    const conversion = await client.convert(100, 'USD', ['EUR', 'GBP', 'JPY']);
    console.log(conversion);
  } catch (error) {
    console.error('Error fetching exchange rates:', error);
  }
}

fetchLatestRates();

JavaScript (ESM)

import { GlobalExchangeRatesClient } from 'globalexchangerates';

// Create a client instance
const client = new GlobalExchangeRatesClient('your_api_key');

// Get the latest exchange rates
client.getLatest()
  .then(rates => console.log(rates))
  .catch(error => console.error('Error fetching exchange rates:', error));

JavaScript (CommonJS)

const { GlobalExchangeRatesClient } = require('globalexchangerates');

// Create a client instance
const client = new GlobalExchangeRatesClient('your_api_key');

// Get the latest exchange rates
client.getLatest()
  .then(rates => console.log(rates))
  .catch(error => console.error('Error fetching exchange rates:', error));

Browser

<!-- Using CDN-->
<script src="https://cdn.jsdelivr.net/npm/globalexchangerates/dist/index.global.js"></script>
<script>
  // Get the latest exchange rates
  client.getLatest()
    .then(rates => console.log(rates))
    .catch(error => console.error('Error fetching exchange rates:', error));
</script>

API Reference

The client provides the following methods:

  • getCurrencies(codes?: string[]): Promise<Currency[]>
  • getLatest(provider?: string, currencies?: string[], baseCurrency?: string): Promise<ExchangeRateResponse>
  • getProviders(codes?: string[], countryCode?: string): Promise<Provider[]>
  • getHistorical(date: Date, latest?: boolean, provider?: string, currencies?: string[], baseCurrency?: string): Promise<ExchangeRateResponse>
  • convert(amount: number, baseCurrency?: string, toCurrencies?: string[], provider?: string, date?: Date): Promise<ConversionResponse>

All methods return promises that resolve to the corresponding data structure.

TypeScript types are included with the package for a better development experience with intelligent code completion.

License

This project is licensed under the MIT License.

Full Documentation

The full API documentation is available at doc.globalexchangerates.org.

Contacts and support

support@globalexchangerates.org.