Created
December 6, 2020 09:51
-
-
Save rkmaier/983161ee3f7470287c67eaac672a5f4d to your computer and use it in GitHub Desktop.
Fetch bitstamp api using google sheets script
This file contains hidden or 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
function onOpen(e) { | |
eval(UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/jsSHA/2.3.1/sha256.js').getContentText()); | |
var key = ''; | |
var secret = ''; | |
var customer_id = ''; | |
var nonce = new Date().getTime().toString(); | |
var message = nonce + customer_id + key | |
var shaObj = new jsSHA("SHA-256", "BYTES"); | |
shaObj.setHMACKey(secret, "BYTES"); | |
shaObj.update(message); | |
var signature = shaObj.getHMAC("HEX").toString().toUpperCase(); | |
Logger.log(signature) | |
var url = "https://www.bitstamp.net/api/v2/balance/"; | |
var formData = { | |
"key": key, | |
"signature": signature, | |
"nonce": nonce | |
}; | |
var options = { | |
"method": "post", | |
"muteHttpExceptions": true, | |
"payload": formData | |
}; | |
var response = UrlFetchApp.fetch(url, options); | |
Logger.log(response); | |
var data = JSON.parse(response.getContentText()); | |
// Write data to excel sheet | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.appendRow([data.ltcusd_fee,data.usd_available]); | |
Logger.log(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment