'Gate.io google app script "INVALID_SIGNATURE","message":"Signature mismatch"
I am trying to do a request to Gate.io cryptocurrency market and getting this error.
{"label":"INVALID_SIGNATURE","message":"Signature mismatch"}
I have managed to find a way to correctly encrypt all the parameters(my output is the same as they presented in their documentation), however, when I add a real secret key I got this error.
Please see the screenshot:
the right-hand side is a signature from their doc, in the GAS log you see my output so these are the same however when I add real timestamp and my real secret then it doesn't work
Screenshot.
Here is the fetch request I am using:
function getDateIo() {
var key = "xxx"
var sec = "xxx"
var timestamp = Math.floor(Date.now() / 1000)
var a = {"contract":"BTC_USD","type":"limit","size":100,"price":6800,"time_in_force":"gtc"}
a = JSON.stringify(a)
var body = {"text":"t-123456","currency_pair":"ETH_BTC","type":"limit","account":"spot","side":"buy","iceberg":"0","amount":"1","price":"5.00032","time_in_force":"gtc","auto_borrow":false}
body = JSON.stringify(body)
console.log(body)
var requestPayload = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_512, "")
requestPayload = requestPayload.map(function(e) {
var v = (e < 0 ? e + 256 : e).toString(16);
return v.length == 1 ? "0" + v : v;
}).join("");
console.log(requestPayload)
var meth = 'GET'
var pat = '/api/v4/futures/orders'
var sign = meth + "\n" + pat + "\n" + "contract=BTC_USD&status=finished&limit=50" + "\n" + requestPayload + "\n" + timestamp;
console.log(sign)
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, sign, sec);
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",
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json',
'KEY': key,
'Timestamp': timestamp,
'SIGN': signature,
},
// 'body': body,
'muteHttpExceptions': true,
};
var data = UrlFetchApp.fetch("https://api.gateio.ws/api/v4/futures/orders?contract=BTC_USD&status=finished&limit=50", params);
}
Thanks for any advice
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
