Last active
April 12, 2019 18:21
-
-
Save grant/b0729cade5faa5bd3036fb7fa2cabc97 to your computer and use it in GitHub Desktop.
BTC API – GCF + Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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