Skip to content

Instantly share code, notes, and snippets.

@grant
Last active April 12, 2019 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grant/b0729cade5faa5bd3036fb7fa2cabc97 to your computer and use it in GitHub Desktop.
Save grant/b0729cade5faa5bd3036fb7fa2cabc97 to your computer and use it in GitHub Desktop.
BTC API – GCF + Apps Script
/**
* Get's the bitcoin price at a date.
*
* @param {string} date The date in yyyy-MM-dd format. Defaults to today.
* @return The value of BTC in USD at the date. From Coinbase's API
* @customfunction
*/
function BTC_CF(date) {
var dateString = Utilities.formatDate(new Date(date), "GMT", "yyyy-MM-dd");
var res = UrlFetchApp.fetch("https://us-central1-new-project-as-test.cloudfunctions.net/btc?date=" + dateString);
var json = JSON.parse(res.getContentText());
return json.data.amount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment