init
This commit is contained in:
40
dexscreener.php
Normal file
40
dexscreener.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// Function to get pair address for a token paired with USDC using Dexscreener API
|
||||
function getPairAddress($tokenSymbol) {
|
||||
// Dexscreener Search API URL
|
||||
$searchApiUrl = "https://api.dexscreener.com/latest/dex/search?q=" . urlencode($tokenSymbol);
|
||||
|
||||
// Initialize cURL session for the search API
|
||||
$ch = curl_init();
|
||||
|
||||
// Set the URL and other options for the cURL session
|
||||
curl_setopt($ch, CURLOPT_URL, $searchApiUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Execute the cURL session and store the result
|
||||
$searchResponse = curl_exec($ch);
|
||||
|
||||
// Check for errors in cURL execution
|
||||
if ($searchResponse === false) {
|
||||
echo 'cURL Error: ' . curl_error($ch);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Decode the JSON search response
|
||||
$searchData = json_decode($searchResponse, true);
|
||||
|
||||
$pairs = $searchData['pairs'];
|
||||
$highestPair = $pairs[0];
|
||||
foreach($pairs as $pair){
|
||||
$vol = $pair["volume"]["h24"];
|
||||
if($vol > $highestPair["volume"]["h24"]){
|
||||
$highestPair =$pair;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($highestPair);
|
||||
|
||||
// Return null if no pair found
|
||||
return null;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user