Request signing

You need to specify your secret key, apply SHA256 encryption to your payload and convert the result to HEX format

Nonce usage

You should pass nonce parameter in the payload of every request to this API. nonce can be a number or a string, each request must be accompanied by a unique value. Otherwise the request will fail.

We will use Unix TimeStamp as the nonce value for sending requests in this document.

Example of creating request signature NodeJS

Let's say we want to get price rate of ETH/USDT (method /price-rate)

1. Build request payload

const payload = { from: 'ETH', to: 'USDT' };

2. Add nonce parameter to the payload in order to avoid request duplication.

By using unix timestamp as nonce parameter we will meet the requirements of using number and its incrementing for every new request.

payload.nonce = Date.now(); // 1643881172430

3. Create string from payload and used it in a process of creating signature.

const stringPayload = JSON.stringify(payload); // {"from":"ETH","to":"USDT","nonce":1643881172430}

4. Create signature:

Example with crypto-js module:

const CryptoJS = require("crypto-js"); 
const sign = CryptoJS.HmacSHA256(stringPayload, __PRIVATE_KEY__).toString(CryptoJS.enc.Hex)

Example with crypto module:

const crypto = require('crypto');  
const sign = crypto.createHmac('SHA256', __PRIVATE_KEY__).update(stringPayload).digest('hex');

5. Send request with required headers:

const axios = require('axios'); // lib for HTTP requests
const response = await axios.post(__BASE_URL__ + '/price-rate', stringPayload, 
{ 
    headers: 
        {
            'x-api-public-key': __PUBLIC_KEY__, 
            'x-api-signature': sign 
        } 
});

6. Response:

console.log(response.data); // {"success":true,"response":"2751.51000000"}

Last updated