I’ve seen a few posts on getting the balance of a particular coin, but can’t figure out how to simply get USDT balance without triggering the API limits.
The below code randomly does one of 3 things:
a) returns the right balance
b) returns empty or says there’s a illegal character returned: “<”
c) says I’ve exceeded limits and bans me for many hours <---- most common
Note that this is literally the only function I’m triggering, so there should be absolutely no reason at all to ban me. I cannot find the right endpoint to reliably return the balance.
Using Google Apps Script if that makes a difference. Any thoughts?
function getUSDTBalance(){
var key = '______;
var secret = '________';
var baseUrl= "https://api.binance.com";
//api = "/api/v3/account";
var timestamp = Number(new Date().getTime()).toFixed(0);
var string = "×tamp=" + timestamp; // Please input query parameters
var signature= Utilities.computeHmacSha256Signature(string, secret);
signature = signature.map(function (e) {
var v = (e < 0 ? e + 256 : e).toString(16);
return v.length == 1 ? "0" + v : v;
}).join("");
var query = "?" + string + "&signature=" + signature;
var params = {
'method': 'get',
'headers': { 'X-MBX-APIKEY': key },
'muteHttpExceptions': true
};
var data = UrlFetchApp.fetch(baseUrl + api + query, params);
Logger.log(JSON.parse(data));
var j = JSON.parse(data);
var bal = j.balances;
var usdtBal = 0;
for (var i = 0; i < bal.length; i++) {
if (bal[i]["asset"] == "USDT") {
usdtBal = bal[i].free;
continue;
}
}
Logger.log(usdtBal);
return(usdtBal);
}