JavaScript / Node.js
REST signed-request helper plus a public WebSocket subscription.
REST
import crypto from 'crypto';
import axios from 'axios';
import { randomUUID } from 'crypto';
const API_KEY = 'zd_84444a6e...';
const SECRET = '073CuVWk...';
const BASE_URL = 'https://api.zetariumdex.com';
function sign(secret, queryString) {
return crypto.createHmac('sha256', secret).update(queryString).digest('hex');
}
async function signedRequest(method, path, { params = {}, body } = {}) {
const all = { ...params, timestamp: Date.now() };
const sortedKeys = Object.keys(all).sort();
const queryString = sortedKeys
.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(all[k])}`)
.join('&');
const signature = sign(SECRET, queryString);
const url = `${BASE_URL}${path}?${queryString}&signature=${signature}`;
const headers = { 'X-API-KEY': API_KEY };
if (body) headers['Content-Type'] = 'application/json';
return axios({ method, url, headers, data: body });
}
// 1. Read futures balance
const bal = await signedRequest('GET', '/v2/futures/balance');
console.log(bal.data);
// 2. Idempotent LIMIT BUY
const clientOrderId = randomUUID();
const order = await signedRequest('POST', '/v2/orders', {
body: {
symbol: 'BTCUSDT',
side: 'BUY',
type: 'LIMIT',
quantity: '0.001',
price: '30000',
clientOrderId,
},
});
console.log(order.data);WebSocket — public ticker
import WebSocket from 'ws';
const ws = new WebSocket('wss://api.zetariumdex.com/ws');
ws.on('open', () => {
ws.send(
JSON.stringify({
action: 'subscribe',
channel: 'ticker',
symbol: 'BTCUSDT',
}),
);
});
ws.on('message', (data) => {
const msg = JSON.parse(data);
if (msg.channel === 'ticker') {
console.log(`${msg.symbol} last=${msg.data.lastPrice}`);
}
});