Over the past few days I've been trying to engineer a piece of code that can help me access this api https://api-futures.kucoin.com and this endpoint /api/v1/transaction-history?offset=1&forward=true&maxCount=50 using hash encryption.
Reference document https://docs.kucoin.com/futures/#authentication . I've been looking at the reference document, then I have written a script that should work but is not and I just need some guidance.
function KuCoinRequest(){
// GET /api/v1/transaction-history?offset=1&forward=true&maxCount=50
var key ='xx'
var secret = 'xx'
var passphrase = 'xx'
var url = "https://api-futures.kucoin.com"; //endpoint
var timestamp = '' + Number(new Date().getTime()).toFixed(0);
var command = "GET";
var endpoint = "/api/v1/transaction-history?offset=1&forward=true&maxCount=50"
var str_to_sign = timestamp + command + endpoint;
// var signature = Utilities.computeHmacSha256(str_to_sign, secret);
// var encodedPass = Utilities.computeHmacSha256(passphrase, secret);
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, str_to_sign, secret)
var encodedPass = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, passphrase, secret);
var params = {
'method': "GET",
'headers' : {
'KC-API-SIGN': Utilities.base64Encode(signature),
'KC-API-KEY': key,
'KC-API-TIMESTAMP': timestamp,
'KC-API-PASSPHRASE': Utilities.base64Encode(encodedPass),
'KC-API-KEY-VERSION': '2',
'muteHttpExceptions': true
}
};
query = url + endpoint;
var data = UrlFetchApp.fetch(query, params);
Logger.log(data.getContentText());
// printJsonKucoin(data, endpoint);
return data;
}