The macro sets the base currency and predefined cryptocurrency IDs, constructs an API URL to fetch market data, and displays the results in an interactive HTML table.
#set($currency = $StringUtils.lowerCase($parameters["baseCurrency"]))
<div id="crypto-rates-wrapper">
<table class="aui aui-table-interactive aui-table-rowhover" style="table-layout: fixed; width: 50%;">
<thead>
<tr>
<th style="width:50%;">Cryptocurrency</th>
<th style="width:50%;">Rate ($StringUtils.upperCase($currency))</th>
</tr>
</thead>
<tbody id="crypto-rates-body">
<tr>
<td colspan="2">Loading...</td>
</tr>
</tbody>
</table>
</div>
<script>
(async () => {
const currency = "$currency";
const cryptoIDs = "bitcoin,ethereum,tether,ripple,cardano,solana,polkadot,dogecoin,tron,toncoin";
const apiUrl =
"https://api.coingecko.com/api/v3/coins/markets?vs_currency="
+ currency
+ "&ids="
+ cryptoIDs
+ "&order=market_cap_desc";
const tbody = document.getElementById("crypto-rates-body");
try {
const response = await fetch(apiUrl);
const data = await response.json();
if (!Array.isArray(data) || data.length === 0) {
tbody.innerHTML =
"<tr><td colspan='2'>Unable to retrieve cryptocurrency rates</td></tr>";
return;
}
let html = "";
data.forEach(c => {
html += "<tr>";
html += "<td>";
html += "<span style='margin-right:7px;vertical-align:sub;'>";
html += "<img src='" + c.image + "' alt='" + c.name + " logo' style='width:20px;height:20px;'>";
html += "</span>";
html += c.name;
html += "</td>";
html += "<td>" + c.current_price + "</td>";
html += "</tr>";
});
tbody.innerHTML = html;
} catch (err) {
tbody.innerHTML =
"<tr><td colspan='2'>Unable to retrieve cryptocurrency rates</td></tr>";
console.error("Crypto macro error:", err);
}
})();
</script>
Retrieve and display current exchange rates for major currencies against a specified base currency
Convert a specified amount of cryptocurrency to a fiat currency
Display the creation date of the current Confluence page
Display Confluence page edit and view restrictions to provide essential permission details, including users, groups, and inherited access
Display a custom list of recently updated content
Display a "Delete me" message only for editors while editing a page
Based on CQL, show a table with the following columns: Page Title, Author, Updated, and Status
Display and interact with an OpenAPI/Swagger specification directly in Confluence by rendering a fully featured Swagger UI from a provided JSON URL
Generate IDs in Base32 format
Retrieve and display labels from a specified space