🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@kabeep/forex

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

@kabeep/forex

A JavaScript foreign exchange library via fawazahmed0's API

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

forex

💱 A JavaScript foreign exchange library via fawazahmed0's API.

NodeJS License NPM Codecov BundlePhobia CircleCI

English | 简体中文

Insights

📖 Introduction

forex stands for Foreign Exchange, and its purpose is not FX trading.

Please use it with caution for investment-related decisions.

Get daily exchange rates in the browser or terminal for free and without rate limits.

See documentation or demo.

⚙️ Installation

npm install @kabeep/forex --save
yarn add @kabeep/forex
pnpm add @kabeep/forex

🚀 Usage

CommonJS

const { ForexClient } = require('@kabeep/forex');

ESModule

import { ForexClient } from '@kabeep/forex';

Methods: getCurrencies(date, options)

Fetches the list of available currencies.

const client = new ForexClient();
// => {
//    code: 200,
//    message: 'OK',
//    data: [
//        { code: 'eur', name: 'Euro' },
//        { code: 'usd', name: 'US Dollar' },
//        { code: 'cny', name: 'Chinese Yuan Renminbi' },
//        { code: 'btc', name: 'Bitcoin', }
//        ... More items
//    ]
// }
client.getCurrencies('latest');

// or
client.getCurrencies(new Date(2024, 11, 1));
ParameterTypeOptionalDefaultDescription
dateDate | "latest"true"latest"The date for fetching currencies, or "latest" for the most recent
optionsRequestInittrue{}Additional request options

Returns: Promise<HttpResponse<AvailableCurrency[]>>

Result Object:

KeyTypeRequiredDescription
codenumbertrueHTTP response status codes
messagestringtrueHTTP response status messages
dataAvailableCurrency[]falseList of available currency

interface AvailableCurrency:

KeyTypeRequiredDescription
codestringtrueCode of currency
namestringfalseName of currency

Methods: getRates(code, date, options)

Fetches the exchange rates for a specific currency.

const client = new ForexClient();
// => {
//    code: 200,
//    message: 'OK',
//    data: [
//        { code: 'eur', rate: 100_000 },
//        { code: 'usd', rate: 100_000 },
//        { code: 'cny', rate: 100_000 },
//        ... More items
//    ]
// }
client.getRates('USD');

// or
client.getRates('US');
ParameterTypeOptionalDefaultDescription
codestringtruethis.options.baseCurrencyThe currency code or locale code to get rates for
dateDate | "latest"true"latest"The date for fetching currencies, or "latest" for the most recent
optionsRequestInittrue{}Additional request options

Returns: Promise<HttpResponse<ExchangeRate[]>>

Result Object:

KeyTypeRequiredDescription
codenumbertrueHTTP response status codes
messagestringtrueHTTP response status messages
dataExchangeRate[]falseList of exchange rates

interface ExchangeRate:

KeyTypeRequiredDescription
codestringtrueCode of currency
ratenumberfalseRate of currency

Methods: getRate(baseCode, destCode, date, options)

Fetches the exchange rate between two currencies.

const client = new ForexClient();
// => {
//    code: 200,
//    message: 'OK',
//    data: 0.94759027
// }
client.getRate('USD', 'EUR');

// => {
//    code: 200,
//    message: 'OK',
//    data: 7.78004385
// }
client.getRate('US', 'HK');
ParameterTypeOptionalDefaultDescription
baseCodestringtruethis.options.baseCurrencyThe base currency code or locale code
destCodestringtrue-The destination currency code or locale code
dateDate | "latest"true"latest"The date for fetching currencies, or "latest" for the most recent
optionsRequestInittrue{}Additional request options

Returns: Promise<HttpResponse<number>>

Result Object:

KeyTypeRequiredDescription
codenumbertrueHTTP response status codes
messagestringtrueHTTP response status messages
datanumberfalseThe exchange rate

Methods: getCode(localeCode)

Get a valid currency code based on ISO 3166-1 code.

const client = new ForexClient();
// => 'USD'
client.getCode('US');

// => 'CNH'
client.getCode('HK');

// => 'CNY'
client.getCode('RMB');
ParameterTypeOptionalDefaultDescription
localeCodestringfalse-The locale code to get currency code for

Returns: string

The corresponding currency code.

Methods: convert(baseCode, destCode, amount, date, options)

Converts an amount from one currency to another.

const client = new ForexClient();
// => {
//    code: 200,
//    message: 'OK',
//    data: 9.48
// }
client.convert('USD', 'EUR', 10);

// => {
//    code: 200,
//    message: 'OK',
//    data: 72.67
// }
client.convert('US', 'HK', 10);
ParameterTypeOptionalDefaultDescription
baseCodestringtruethis.options.baseCurrencyThe base currency code or locale code
destCodestringtrue-The destination currency code or locale code
amountnumbertrue0The amount to convert
dateDate | "latest"true"latest"The date for fetching currencies, or "latest" for the most recent
optionsRequestInittrue{}Additional request options

Returns: Promise<HttpResponse<number>>

Result Object:

KeyTypeRequiredDescription
codenumbertrueHTTP response status codes
messagestringtrueHTTP response status messages
datanumberfalseThe converted amount

🏅 Credits

exchange-api - This package would not exist without this.

🤝 Contribution

Contributions via Pull Requests or Issues are welcome.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Keywords

forex

FAQs

Package last updated on 11 Dec 2024

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