pull down to refresh
40 sats \ 4 replies \ @bisdak 13 Oct 2024 \ on: A workaround for Google Finance broken for Bitcoin bitcoin
btw, you can use coindesk, example: https://api.coindesk.com/v1/bpi/currentprice/USD.json or replace USD with your desired currency like https://api.coindesk.com/v1/bpi/currentprice/PHP.json
Thanks for the idea! I just created one for myself!
reply
it’s a pleasure to share. actually there’s more like https://api.yadio.io/exrates or https://api.yadio.io/exrates/CAD as base currency.
reply
Updated.
function fetchBitcoinPriceCoinDesk() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); // Change "Sheet1" to your actual sheet name
var url = "https://api.coindesk.com/v1/bpi/currentprice/USD.json"; // CoinDesk API URL for Bitcoin price in USD
try {
// Fetch the API data
var response = UrlFetchApp.fetch(url);
var jsonData = JSON.parse(response.getContentText());
// Get the rate_float (Bitcoin price in USD) from the API response
var price = jsonData.bpi.USD.rate_float;
// Set the price in the target cell (e.g., B3)
sheet.getRange("B3").setValue(price);
} catch (error) {
Logger.log("Error fetching price: " + error);
sheet.getRange("B3").setValue("Error fetching price");
}
}
reply
Thanks, I'll update the sheet when I get on my laptop.
reply