<?php


$base_url = 'https://api2.binance.com';

// Endpoint for server time
$endpoint = '/api/v1/time';

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $base_url . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL session
$response = curl_exec($ch);

// Check for cURL errors
if ($response === false) {
    echo 'Curl error: ' . curl_error($ch);
    curl_close($ch);
    exit;
}

// Close cURL session
curl_close($ch);

// Decode JSON response
$time_data = json_decode($response, true);


// Print server time
if (isset($time_data['serverTime'])) {
    $server_time = date('Y-m-d H:i:s', $time_data['serverTime'] / 1000); // Convert milliseconds to seconds

    $servertime=$time_data['serverTime'];
    echo 'Server Time: ' . $server_time;
} else {
    echo 'Error: Unable to retrieve server time.';
}

// Binance API credentials
$api_key = 'q2b9vk15lQfWM2KgS24ehHrGs3LAgQxPV8woQdifYzeYByVbaoaKP5naeVuuzEdW';
$api_secret ='ByCA97ZDl5kvn4grTe3IiWkPhYneAqd8aLDH6fyJLi1sYsXlDOOVvGFHWNgABLQR';

// Binance API endpoint and base URL
$base_url = 'https://api2.binance.com';
$endpoint = '/api/v3/allOrders';

// Order details
$symbol = 'ADAUSDT'; // Replace with your trading pair
$order_id = ''; // Replace with your order ID

// Generate timestamp
$timestamp = $servertime;

// Build query string
$query_string = http_build_query([
    'symbol' => $symbol,
    //'orderId' => $order_id,
    'timestamp' => $timestamp,
]);

// Create signature
$signature = hash_hmac('sha256', $query_string, $api_secret);

// Build request URL
$url = $base_url . $endpoint . '?' . $query_string . '&signature=' . $signature;

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-MBX-APIKEY: ' . $api_key,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL session
$response = curl_exec($ch);

// Check for cURL errors
if ($response === false) {
    echo 'Curl error: ' . curl_error($ch);
    curl_close($ch);
    exit;
}

// Close cURL session
curl_close($ch);

// Decode JSON response
$order_details = json_decode($response, true);

// Print order details

echo '<pre>';
print_r($order_details);
echo '</pre>';

?>