I have fight many time with graphql and my hostet server. PHP working better for me, so i wrote this PHP function:
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;
}
With this function you can now do simple calls with (example for get chart history):
$arr=array( "query" => "{\n ethereum(network: bsc){\n dexTrades(options: {limit: 1000, desc: \"timeInterval.minute\"},\n date: {since:\"2020-11-01\"}\n exchangeName: {in:[\"Pancake\",\"Pancake v2\"]},\n baseCurrency: {is: \"$token\"},\n quoteCurrency: {is: \"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c\"}){\n timeInterval {\n minute(count: 1)\n }\n baseCurrency {\n symbol\n address\n }\n baseAmount\n quoteCurrency {\n symbol\n address\n }\n quoteAmount\n trades: count\n quotePrice\n maximum_price: quotePrice(calculate: maximum)\n minimum_price: quotePrice(calculate: minimum)\n open_price: minimum(of: block get: quote_price)\n close_price: maximum(of: block get: quote_price)\n }}\n }\n ");
$chart = bitquery($arr);
Greetz,
Ben (OneClickCrypto)