<?php
$apiKey = '60e251d6-1c5f-4b22-b5bc-573166dc74d7';
$apiSecret = '9F72FE6E07CBE5B3886020B436D71000';
$passphrase = 'Trading@bot123';

$baseUrl = 'https://www.okx.com';
$endpoint = '/api/v5/market/tickers?instType=SPOT';

$timestamp = time() * 1000; // Current timestamp in milliseconds

$method = 'GET';
$queryString = '';
if ($method === 'GET' && !empty($queryString)) {
    $endpoint .= '?' . $queryString;
}

$signature = hash_hmac('sha256', $timestamp . $method . $endpoint . $queryString, $apiSecret);

$headers = [
    'OK-ACCESS-KEY: ' . $apiKey,
    'OK-ACCESS-SIGN: ' . $signature,
    'OK-ACCESS-TIMESTAMP: ' . $timestamp,
    'OK-ACCESS-PASSPHRASE: ' . $passphrase,
    'Content-Type: application/json'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
curl_close($ch);


if ($response === false) {
    $error = curl_error($ch);
    $errorCode = curl_errno($ch);
    curl_close($ch);
    echo "cURL Error: $error (Error Code: $errorCode)";
} else {
    $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($httpStatusCode == 200) {
        echo $response;
    } else {
        echo "HTTP Status Code: $httpStatusCode\n";
        echo "Response: $response\n";
    }
}
?>
