Created
September 11, 2018 19:55
-
-
Save uneasyguy/b28623807715bfaa2b2e96e4fb66a504 to your computer and use it in GitHub Desktop.
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
function BinanceAccountInfo() { | |
Logger.clear() | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("account_info"); | |
var key = sheet.getRange(1,2).getValue() ; | |
var secret = sheet.getRange(2,2).getValue(); | |
var curTime = new Date().getTime(); | |
var timestamp = "timestamp=" + curTime; | |
var signature = Utilities.computeHmacSha256Signature(timestamp, secret); | |
signature = signature.map(function(e) { | |
var v = (e < 0 ? e + 256 : e).toString(16); | |
return v.length == 1 ? "0" + v : v; | |
}).join(""); | |
var params = { | |
'method': 'get', | |
'accept': 'application/json', | |
'headers': {'X-MBX-APIKEY': key}, | |
'muteHttpExceptions': true | |
}; | |
var url = "https://api.binance.com/api/v3/account?" + timestamp + "&signature=" + signature; | |
var data = UrlFetchApp.fetch(url, params); | |
var json = data.getContentText(); | |
Logger.log(json) | |
var data= JSON.parse(data) | |
var balances = data.balances; | |
var currency = sheet.getRange(3,2).getValue(); | |
for (var i = 0; i < balances.length; i++) { | |
if (balances[i]["asset"] == currency){ | |
var available_balance = balances[i]["free"]; | |
sheet.getRange(4,2).setValue(available_balance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also got this message all the time "Way too much request weight used; IP banned until 1628850703938"
The solution I found was to create a node.js proxy using Google Cloud Functions.
Then I put this on my AppScript: