I’m trying to get the price of a crypto coin using bitquery gql. I’m a total beginer.
I have a query that is working, and a node server.
My js code is in app.js and when i run node app.js
, i get: { data: { ethereum: { dexTrades: [Array] } } }
i don’t know what this means… Is my information inside of that array, or is it just not working properly? How do i go about getting just the “quotePrice” part of my query into a variable?
This is my query that works on graphql.bitquery.io/ide :
{
ethereum(network: bsc) {
dexTrades(
options: {limit: 1, asc: "timeInterval.minute"}
date: {since: "2020-11-01"}
exchangeName: {in: ["Pancake", "Pancake v2"]}
baseCurrency: {is: "0x860947ae09058cc028aaf2ac75258060c61f2dfd"}
quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
) {
timeInterval {
minute(count: 5)
}
baseCurrency {
symbol
address
}
baseAmount
quoteCurrency {
symbol
address
}
quoteAmount
trades: count
quotePrice
maximum_price: quotePrice(calculate: maximum)
minimum_price: quotePrice(calculate: minimum)
open_price: minimum(of: block, get: quote_price)
close_price: maximum(of: block, get: quote_price)
}
}
}
Here is my app.js file:
import fetch from "node-fetch";
const query = `
{
ethereum(network: bsc) {
dexTrades(
options: {limit: 1, asc: "timeInterval.minute"}
date: {since: "2020-11-01"}
exchangeName: {in: ["Pancake", "Pancake v2"]}
baseCurrency: {is: "0x860947ae09058cc028aaf2ac75258060c61f2dfd"}
quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
) {
timeInterval {
minute(count: 5)
}
baseCurrency {
symbol
address
}
baseAmount
quoteCurrency {
symbol
address
}
quoteAmount
trades: count
quotePrice
maximum_price: quotePrice(calculate: maximum)
minimum_price: quotePrice(calculate: minimum)
open_price: minimum(of: block, get: quote_price)
close_price: maximum(of: block, get: quote_price)
}
}
}
`;
const url = "https://graphql.bitquery.io/";
const opts = {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": " my bitquery api key "
},
body: JSON.stringify({
query
})
};
fetch(url, opts)
.then(res => res.json())
.then(console.log)
.catch(console.error);