Need help with API to get the latest time token price

I want to use api to get price information of any token, I use php, but I got error, here is my code, can someone help me to rewrite this complete code ?

<?php $token = "0xb60501346240fcde1615de56ea9fff1ac1da5673"; function bitquery ($abruf) { $data_string= json_encode($abruf); $ch = curl_init('https://graphql.bitquery.io/'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'X-API-KEY: BQYTnQhHozgTSrZSKTNpp0gxBkNDnfnj' )); $result = curl_exec($ch); return $result; } $arr=array( "query" => "query { ethereum(network: bsc) { dexTrades( options: {desc: ["block.height","tradeIndex"], limit: 1} exchangeName: {in: ["Pancake", "Pancake v2"]} baseCurrency: {is: "0x7f77cc163c5cb572aa6851557398e296bad95e5b"} ) { transaction { hash } tradeIndex smartContract { address { address } contractType currency { name } } tradeIndex block { height } baseCurrency { symbol address } quoteCurrency { symbol address } quotePrice } } } "); $chart = bitquery($arr); print_r($chart); ?>

Assuming you have already gone through Bitquery APIs With PHP

Please f5, I have updated the post again

If you’re having trouble changing the code, paste it here.

Press play. Copy curl.

Now paste the copied code here:

$arr=array( "query" => " ");

You can find my tutorial for PHP here

ok thank you very much

Hello, I have done it successfully, but it returns current price result that is not true, for example I check token of BSL, current price is 0.04, but it returned result quotePrice": 0.000125442677.
Please check again, this is how I check.

$arr=array( "query" => '{
  ethereum(network: bsc) {
    dexTrades(
      options: {desc: ["block.height","tradeIndex"], limit: 1}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      baseCurrency: {is: "0xb60501346240fcde1615de56ea9fff1ac1da5673"}
    ) {
      transaction {
        hash
      }
      tradeIndex
      smartContract {
        address {
          address
        }
        contractType
        currency {
          name
        }
      }
      tradeIndex
      block {
        height
      }
      baseCurrency {
        symbol
        address
      }
      quoteCurrency {
        symbol
        address
      }
      quotePrice
   
    }
  }
}');

where you checked the price? Also add a quote currency in the query to get the price against …

Can you give me a complete php code?
This is the token I want to test
0xb60501346240fcde1615de56ea9fff1ac1da5673
Thank you very much

The below is the PHP code for the same

function bitquery ($abruf) {
$data_string= json_encode($abruf);
$ch = curl_init('https://graphql.bitquery.io/');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'X-API-KEY: your-api-key'                                                                      
));                                                                                                                   
$result = curl_exec($ch);  
return $result;
}