I am stuck on how to correctlly include the signitue into my get mand based off of the Binance API within Google Scripts. What it states is
SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body. Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation. The signature is not case sensitive. totalParams is defined as the query string concatenated with the request body.
What I have is:
function BinanceTrades() {
var curTime = Number(new Date().getTime()).toFixed(0)
var sKey = UtilitiesputeHmacSha256Signature('symbol=LTCBTC×tamp=' + curTime, '**mySeceretKey**');
Logger.log(sKey)
var headers = {'X-MBX-APIKEY': '**myKey**'}
var data = UrlFetchApp.fetch("=" + sKey + "&symbol=LTCBTC×tamp=" + curTime, {'headers' : headers})
Logger.log(data)
}
and the error I get is:
{"code":-1100,"msg":"Illegal characters found in parameter 'signature'; legal range is '^[A-Fa-f0-9]{64}$'."}
I am unsure of how to pute the HMAC SHA256 correctly and incorporate the totalParams.
My previous post was this.
I am stuck on how to correctlly include the signitue into my get mand based off of the Binance API within Google Scripts. What it states is
SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body. Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation. The signature is not case sensitive. totalParams is defined as the query string concatenated with the request body.
What I have is:
function BinanceTrades() {
var curTime = Number(new Date().getTime()).toFixed(0)
var sKey = Utilities.puteHmacSha256Signature('symbol=LTCBTC×tamp=' + curTime, '**mySeceretKey**');
Logger.log(sKey)
var headers = {'X-MBX-APIKEY': '**myKey**'}
var data = UrlFetchApp.fetch("https://api.binance./api/v3/allOrders?signature=" + sKey + "&symbol=LTCBTC×tamp=" + curTime, {'headers' : headers})
Logger.log(data)
}
and the error I get is:
{"code":-1100,"msg":"Illegal characters found in parameter 'signature'; legal range is '^[A-Fa-f0-9]{64}$'."}
I am unsure of how to pute the HMAC SHA256 correctly and incorporate the totalParams.
My previous post was this.
Share Improve this question edited Jul 21, 2020 at 5:01 Tanaike 202k12 gold badges121 silver badges213 bronze badges asked Jan 10, 2018 at 16:22 KayracerKayracer 1693 silver badges13 bronze badges1 Answer
Reset to default 7How about these modifications?
Modification points :
From the manual you provided
- In your case, the string which is used for the signature is
"symbol=LTCBTC×tamp=" + curTime
. - The signature is the string of the unsigned hexadecimal.
- But at Google Apps Script, the data which was encrypted by
Utilities.puteHmacSha256Signature()
is the bytes array of the signed hexadecimal.
- But at Google Apps Script, the data which was encrypted by
The modified script which reflected above points is as follows.
Modified script :
function BinanceTrades() {
var key = '**myKey**';
var secret = '**mySeceretKey**';
var curTime = Number(new Date().getTime()).toFixed(0);
var string = "symbol=LTCBTC×tamp=" + curTime;
var sKey = Utilities.puteHmacSha256Signature(string, secret);
sKey = sKey.map(function(e) {
var v = (e < 0 ? e + 256 : e).toString(16);
return v.length == 1 ? "0" + v : v;
}).join("");
var params = {
'method': 'get',
'headers': {'X-MBX-APIKEY': key},
'muteHttpExceptions': true
};
var url = "https://api.binance./api/v3/allOrders?" + string + "&signature=" + sKey;
var data = UrlFetchApp.fetch(url, params);
Logger.log(data.getContentText())
}
Note :
- About the encryption of signature, it has already confirmed that this script works fine from the manual you provided.
- I have no account for binance.. So I couldn't run this script. I'm sorry.
- When you run this script, if the error occurs, can you show me the error messages?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745351913a4623883.html
评论列表(0条)