Skip to main content

Currency Converter

The Currency Converter function allows you to convert monetary values between different currencies by providing exchange rates.

Function Overview

ParameterRequiredDescription
functionNameYesMust be set to "CurrencyConverter"
methodNameYesMust be set to "Convert"
fromCurrencySymbolYesSource currency symbol (e.g., "EUR", "USD")
toCurrencySymbolYesTarget currency symbol (e.g., "EUR", "USD")
dateNoThe date for which to get the exchange rate (defaults to current date)

Usage Example

// Convert from EUR to USD
// The app variable represents the brixxApi instance
let rate = app.businessBrixx({
functionName: "CurrencyConverter",
methodName: "Convert",
fromCurrencySymbol: "EUR",
toCurrencySymbol: "USD",
date: moment().subtract(7, 'days') // optional, defaults to current date if omitted
});
console.log(rate);

Return Value

The function returns the exchange rate between the specified currencies as a numeric value.

Implementation Details

The Currency Converter uses the Frankfurter API (https://api.frankfurter.app) to retrieve exchange rates. The API supports historical data by specifying a date parameter.

Error Handling

If the conversion fails, an error message will be returned. Ensure that:

  • Currency symbols are valid
  • The date is within the range supported by the API
  • Your network connection allows access to the external API endpoint