$highestPair["volume"]["h24"] &&($pairSymbolLow == $tokenSymbolLow || $pairSymbolLow == "$".$tokenSymbolLow)){ // echo "New High" . $pair["baseToken"]["symbol"]; $highestPair =$pair; } } echo json_encode($highestPair); return $highestPair["priceUsd"]; } function sGetTokenPrice($tokenSymbol){ $apiKey = '8faf016d-9cbd-40b3-889d-a45354621601'; // Replace with the token symbol you want to fetch (e.g., BTC, ETH, ADA) // CoinMarketCap API endpoint $endpoint = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'; // Parameters for the API request $params = [ 'symbol' => $tokenSymbol, 'convert' => 'USD' ]; // Initialize cURL session $ch = curl_init(); // Set cURL options curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'X-CMC_PRO_API_KEY: ' . $apiKey, 'Accept: application/json' ]); // Execute cURL session $response = curl_exec($ch); // Check for cURL errors if(curl_errno($ch)) { echo 'Error:' . curl_error($ch); } // Close cURL session curl_close($ch); // Decode JSON response $data = json_decode($response, true); // Check if data was retrieved successfully if(isset($data['data'][$tokenSymbol]['quote']['USD']['price'])) { $priceUSD = $data['data'][$tokenSymbol]['quote']['USD']['price']; return $priceUSD; } else { return -1; } }