PHP
Signed-request helper plus a public WebSocket subscription.
REST
<?php
// zdex.php — requires the php-curl extension
const API_KEY = 'zd_84444a6e...';
const SECRET = '073CuVWk...';
const BASE_URL = 'https://api.zetariumdex.com';
function signed_request(
string $method,
string $path,
array $params = [],
?array $body = null
): array {
$params['timestamp'] = (int)(microtime(true) * 1000);
ksort($params);
$qs = http_build_query($params);
$sig = hash_hmac('sha256', $qs, SECRET);
$url = BASE_URL . $path . "?{$qs}&signature={$sig}";
$headers = ['X-API-KEY: ' . API_KEY];
if ($body !== null) {
$headers[] = 'Content-Type: application/json';
}
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $body !== null ? json_encode($body) : null,
]);
$raw = curl_exec($ch);
curl_close($ch);
return json_decode($raw, true);
}Usage
<?php
require_once 'zdex.php';
// 1. Read futures balance
$balance = signed_request('GET', '/v2/futures/balance');
print_r($balance);
// 2. Idempotent LIMIT BUY
$clientOrderId = bin2hex(random_bytes(16));
$order = signed_request('POST', '/v2/orders', [], [
'symbol' => 'BTCUSDT',
'side' => 'BUY',
'type' => 'LIMIT',
'quantity' => '0.001',
'price' => '30000',
'clientOrderId' => $clientOrderId,
]);
print_r($order);WebSocket — public ticker
<?php
// composer require textalk/websocket
require __DIR__ . '/vendor/autoload.php';
use WebSocket\Client;
$client = new Client('wss://api.zetariumdex.com/ws');
$client->send(json_encode([
'action' => 'subscribe',
'channel' => 'ticker',
'symbol' => 'BTCUSDT',
]));
while (true) {
$msg = json_decode($client->receive(), true);
if (($msg['channel'] ?? null) === 'ticker') {
echo "{$msg['symbol']} last={$msg['data']['lastPrice']}", PHP_EOL;
}
}