Skip to content

Instantly share code, notes, and snippets.

@learntheropes
Created June 26, 2025 03:56
Show Gist options
  • Select an option

  • Save learntheropes/7a9890a3e2c71f19e53c0a04a3df01b2 to your computer and use it in GitHub Desktop.

Select an option

Save learntheropes/7a9890a3e2c71f19e53c0a04a3df01b2 to your computer and use it in GitHub Desktop.
BTC price in multiple currencies widget for scriptable iOS app
// Bitcoin Price Widget using Yadio.io
let widget = new ListWidget();
widget.setPadding(16, 16, 16, 16);
widget.backgroundColor = new Color("#1a1a1a");
let title = widget.addText("₿ Bitcoin Price");
title.font = Font.boldSystemFont(16);
title.textColor = Color.white();
widget.addSpacer(8);
const currencies = ['PYG', 'ARS', 'EUR', 'USD'];
try {
// 1) fetch the whole JSON…
let res = await new Request("https://api.yadio.io/exrates/btc").loadJSON();
// 2) extract the nested BTC object
let rates = res.BTC || {};
for (let code of currencies) {
let price = rates[code] != null
? Number(rates[code]).toLocaleString()
: "N/A";
let line = widget.addText(`${code}: ${price}`);
line.font = Font.mediumSystemFont(14);
line.textColor = Color.white();
}
} catch (e) {
let err = widget.addText("Error fetching data");
err.font = Font.mediumSystemFont(14);
err.textColor = Color.red();
console.error(e);
}
Script.setWidget(widget);
Script.complete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment