Examples
HMAC helper
import crypto from "node:crypto";
function canonicalUri(path, query = {}) {
const pairs = [];
for (const key of Object.keys(query).sort()) {
const value = query[key];
if (Array.isArray(value)) {
for (const item of value) pairs.push(`${key}=${item}`);
} else if (value !== undefined && value !== null) {
pairs.push(`${key}=${value}`);
}
}
return pairs.length === 0 ? path : `${path}?${pairs.join("&")}`;
}
function signTradingApi({ method, path, query, timestamp, nonce, rawBody, apiSecret }) {
const uri = canonicalUri(path, query);
const payload = [
method.toUpperCase(),
uri,
String(timestamp),
nonce,
rawBody ?? ""
].join("\n");
return crypto
.createHmac("sha256", apiSecret)
.update(payload, "utf8")
.digest("hex");
}Signed POST example
cURL with HMAC
Last updated

