Private WebSocket tokens are valid for only 24 hours. You must request a new token each time you connect and continue to request them regularly to maintain connectivity.
To request a token, perform a POST request to https://indodax.com/api/private_ws/v1/generate_token with the following requirements:
- Body:
client=tapi&tapi_key=<your_tapi_key> (Content-Type: application/x-www-form-urlencoded) - Header:
Sign must contain an HMAC-SHA512 signature of the request body using your tapi_secret as the key.
The response contains connToken and channel which are required for the WebSocket connection.
// JavaScript implementation for requesting a token
const crypto = require("crypto");
function generateHMAC(requestBody, secret) {
const key = Buffer.from(secret, "utf-8");
const hmac = crypto.createHmac("sha512", key);
hmac.update(requestBody, "utf-8");
return hmac.digest("hex");
}
async function RequestToken() {
const url = "https://indodax.com/api/private_ws/v1/generate_token";
const secret = <tapi_secret>;
const key = <tapi_key>;
const requestBody = `client=tapi&tapi_key=${key}`;
const sign = generateHMAC(requestBody, secret);
const opt = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Sign": sign,
},
body: requestBody,
};
const response = await fetch(url, opt);
const responseData = await response.json();
return responseData;
}
RequestToken().then((data) => {
console.log("token:", data.return.connToken);
console.log("channel:", data.return.channel);
});