
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
@kabeep/forex
Advanced tools
forexstands forForeign Exchange, and its purpose is notFXtrading.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.
npm install @kabeep/forex --save
yarn add @kabeep/forex
pnpm add @kabeep/forex
const { ForexClient } = require('@kabeep/forex');
import { ForexClient } from '@kabeep/forex';
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));
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
date | Date | "latest" | true | "latest" | The date for fetching currencies, or "latest" for the most recent |
options | RequestInit | true | {} | Additional request options |
Promise<HttpResponse<AvailableCurrency[]>>Result Object:
| Key | Type | Required | Description |
|---|---|---|---|
code | number | true | HTTP response status codes |
message | string | true | HTTP response status messages |
data | AvailableCurrency[] | false | List of available currency |
interface AvailableCurrency:
| Key | Type | Required | Description |
|---|---|---|---|
code | string | true | Code of currency |
name | string | false | Name of currency |
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');
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
code | string | true | this.options.baseCurrency | The currency code or locale code to get rates for |
date | Date | "latest" | true | "latest" | The date for fetching currencies, or "latest" for the most recent |
options | RequestInit | true | {} | Additional request options |
Promise<HttpResponse<ExchangeRate[]>>Result Object:
| Key | Type | Required | Description |
|---|---|---|---|
code | number | true | HTTP response status codes |
message | string | true | HTTP response status messages |
data | ExchangeRate[] | false | List of exchange rates |
interface ExchangeRate:
| Key | Type | Required | Description |
|---|---|---|---|
code | string | true | Code of currency |
rate | number | false | Rate of currency |
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');
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
baseCode | string | true | this.options.baseCurrency | The base currency code or locale code |
destCode | string | true | - | The destination currency code or locale code |
date | Date | "latest" | true | "latest" | The date for fetching currencies, or "latest" for the most recent |
options | RequestInit | true | {} | Additional request options |
Promise<HttpResponse<number>>Result Object:
| Key | Type | Required | Description |
|---|---|---|---|
code | number | true | HTTP response status codes |
message | string | true | HTTP response status messages |
data | number | false | The exchange rate |
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');
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
localeCode | string | false | - | The locale code to get currency code for |
stringThe corresponding currency code.
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);
| Parameter | Type | Optional | Default | Description |
|---|---|---|---|---|
baseCode | string | true | this.options.baseCurrency | The base currency code or locale code |
destCode | string | true | - | The destination currency code or locale code |
amount | number | true | 0 | The amount to convert |
date | Date | "latest" | true | "latest" | The date for fetching currencies, or "latest" for the most recent |
options | RequestInit | true | {} | Additional request options |
Promise<HttpResponse<number>>Result Object:
| Key | Type | Required | Description |
|---|---|---|---|
code | number | true | HTTP response status codes |
message | string | true | HTTP response status messages |
data | number | false | The converted amount |
exchange-api - This package would not exist without this.
Contributions via Pull Requests or Issues are welcome.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
A JavaScript foreign exchange library via fawazahmed0's API
We found that @kabeep/forex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.