Skip to content

Instantly share code, notes, and snippets.

@CanKattwinkel
Created August 6, 2020 12:02
Show Gist options
  • Save CanKattwinkel/edf274031d4c46e82df43ad1a13ff825 to your computer and use it in GitHub Desktop.
Save CanKattwinkel/edf274031d4c46e82df43ad1a13ff825 to your computer and use it in GitHub Desktop.
Kucoin: Pre-Request Script for Postman
// Use this to sign postman http requests to the KuCoin API
// dont forget to set KC-API-KEY as well as KC-API-PASSPHRASE as headers and to replace the secret used below.
const timestamp = Date.now();
const body = request.body ? request.body : '';
const method = request.method;
const [, endpoint] = request.url.split('https://api.kucoin.com');
const signature = timestamp + method + endpoint + body;
const hash = CryptoJS.HmacSHA256(signature,"YOUR-SECRET");
pm.request.headers.add({
key: 'KC-API-SIGN',
value: hash.toString(CryptoJS.enc.Base64)
});
pm.request.headers.add({
key: 'KC-API-TIMESTAMP',
value: timestamp
});
@Sharabaddin
Copy link

POST https://api.kucoin.com/api/v1/accounts

{
"code": "400005",
"msg": "Invalid KC-API-SIGN"
}

@rleons
Copy link

rleons commented Mar 2, 2021

POST https://api.kucoin.com/api/v1/accounts

{
"code": "400005",
"msg": "Invalid KC-API-SIGN"
}

Replace the KC-API-SIGN value with;
CryptoJS.enc.Base64.stringify(hash)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment