Stand with Ukraine 🇺🇦

Currency Exchange Rates — Confluence Cloud Macro

external-content

The macro builds an interactive table that fetches and displays exchange rates for a user-specified base currency. Major currencies (e.g., USD, EUR) are filtered from the response and presented with corresponding country flags.

Try for free

User Parameters

Base Currency

Select a base currency against which to display the rates

Template

#set($baseCurrency = $parameters.baseCurrency)

## Define the API URLs
#set($exchangeRateApiUrl = "https://open.er-api.com/v6/latest/$baseCurrency")
#set($flagApiBaseUrl = "https://flagsapi.com/")

## Fetch exchange rate data
#set($exchangeResponse = $RequestManager.get($exchangeRateApiUrl))

## Check if data fetch was successful
#if($exchangeResponse)
#set($exchangeData = $exchangeResponse.rates)

## Major currencies list (customizable)
#set($majorCurrencies = ["USD", "EUR", "GBP", "JPY", "CHF", "CAD", "AUD"])

<table class="aui aui-table-interactive aui-table-rowhover" style="width: 50%; table-layout: fixed; border: 1px solid #ddd; border-collapse: collapse;">
    <thead style="background-color: #f1f2f4;">
        <tr>
            <th style="width: 50%; border: 1px solid #ddd;">Currency</th>
            <th style="width: 50%;">Rate ($baseCurrency)</th> ## Updated header
        </tr>
    </thead>
    <tbody>
        ## Loop over the available currencies in the response and display only major currencies, excluding the base currency
        #foreach($currency in $exchangeData.keySet())
        #if($currency != $baseCurrency) ## Skip the base currency
        ## Check if the currency is in the majorCurrencies list by manual iteration
        #set($isMajorCurrency = false)
        #foreach($majorCurrency in $majorCurrencies)
        #if($currency == $majorCurrency)
        #set($isMajorCurrency = true)
        #end
        #end

        ## Display only if it's a major currency
        #if($isMajorCurrency)
        <tr>
            <td style="border: 1px solid #ddd;">
                #if($currency == "EUR")
                <span style="margin-right: 5px; vertical-align: middle;">
                    <img src="https://upload.wikimedia.org/wikipedia/commons/b/b7/Flag_of_Europe.svg" alt="EU flag" style="width: 20px; height: 15px;">
                </span>
                $currency
                #else
                <span style="margin-right: 5px; vertical-align: middle;">
                    <img src="${flagApiBaseUrl}${currency.substring(0,2)}/shiny/32.png" alt="$currency flag" style="width: 20px; height: 20px;">
                </span>
                $currency
                #end
            </td>
            <td>$MathTool.roundTo(3, $exchangeData.get($currency))</td> ## Rounding rate to 2 decimal places
        </tr>
        #end
        #end
        #end
    </tbody>
</table>

#else
<p>
    Failed to retrieve exchange rates.
</p>
#end