<?php
$base = 'http://127.0.0.1:8001';
function req($method, $url, $headers = [], $body = null) {
    $raw = $body === null ? '' : json_encode($body, JSON_UNESCAPED_SLASHES);
    $opts = ['http' => ['method' => $method, 'header' => implode("\r\n", array_merge(['Accept: application/json'], $headers)), 'content' => $raw, 'ignore_errors' => true, 'timeout' => 15]];
    if ($raw !== '') $opts['http']['header'] .= "\r\nContent-Type: application/json";
    $ctx = stream_context_create($opts);
    $text = file_get_contents($url, false, $ctx);
    $status = 0;
    foreach ($http_response_header ?? [] as $h) if (preg_match('/^HTTP\/\S+\s+(\d+)/', $h, $m)) { $status = (int)$m[1]; break; }
    return [$status, json_decode($text, true), $text];
}
[$status, $login] = req('POST', $base.'/api/v1/auth/login', [], ['email'=>'ahmadshahzaib2490+3@gmail.com','password'=>'waqas123waqas']);
$token = $login['data']['token'] ?? '';
[$status, $key] = req('POST', $base.'/api/v1/api-keys', ['Authorization: Bearer '.$token], ['environment'=>'sandbox','scopes'=>['payments:read']]);
$apiKey = $key['data']['public_key'] ?? '';
$secret = $key['data']['secret'] ?? '';
$timestamp = (string) floor(microtime(true) * 1000);
$nonce = bin2hex(random_bytes(8));
$path = '/api/v1/currencies';
$canonical = "GET\n{$path}\n{$timestamp}\n{$nonce}\n".hash('sha256', '');
$sig = hash_hmac('sha256', $canonical, $secret);
[$status, $body, $text] = req('GET', $base.$path, [
    'x-api-key: '.$apiKey,
    'x-api-timestamp: '.$timestamp,
    'x-api-nonce: '.$nonce,
    'x-api-signature: v1='.$sig,
]);
echo "status={$status}\n";
echo "timestamp_digits=".strlen($timestamp)."\n";
echo substr($text, 0, 400)."\n";