<?php

$conn= mysqli_connect("localhost","tradebot_revotech","revotech@123","tradebot_revotech");
 
 $pairs=mysqli_query($conn,"select * from tradepair_list where status='1'");
 
 $pair=array();
 while($pairz=mysqli_fetch_array($pairs))
 {
     $pair[]=$pairz['pair_name'].'USDT';
     
     
 }
 

 
// Define the API endpoint
$apiUrl = 'https://api.binance.com/api/v3/exchangeInfo';

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

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification for testing

// Execute the cURL request
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
    exit();
}

// Close the cURL session
curl_close($ch);

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

// Check if decoding was successful
if ($data === null) {
    echo 'Failed to decode JSON';
    exit();
}

// Extract symbols and filters
$symbols = $data['symbols'];

// Array to store filtered data
$filteredData = [];

// Iterate over each symbol and extract relevant details
foreach ($symbols as $symbol) {
    if (in_array($symbol['symbol'], $pair)) {
        $filteredData[] = [
            'symbol' => $symbol['symbol'],
            'filters' => $symbol['filters']
        ];
    }
}

// Encode the filtered data to JSON
$jsonData = json_encode($filteredData, JSON_PRETTY_PRINT);

// Check if encoding was successful
if ($jsonData === false) {
    echo 'Failed to encode JSON';
    exit();
}

// Save JSON to a file
file_put_contents('binance_exchange_info.json', $jsonData);

echo 'Data successfully fetched and stored in binance_exchange_info.json';
?>