Skip to content

Instantly share code, notes, and snippets.

@GK-m8t
Created March 6, 2024 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GK-m8t/0943366a23855e1a9255541471f6449b to your computer and use it in GitHub Desktop.
Save GK-m8t/0943366a23855e1a9255541471f6449b to your computer and use it in GitHub Desktop.
bitquery_nodejs_example
const axios = require("axios");
// Define your API endpoint
const API_ENDPOINT = "https://graphql.bitquery.io/";
// Define your API key
const API_KEY = "YOUR_BITQUERY_API_KEY"; // Replace with your Bitquery API key
// Define your variables
const network = "ethereum";
const dateFrom = "2024-03-01";
const dateTill = "2024-03-01";
// Define the GraphQL query
const query = `
query MyQuery {
ethereum(network: ${network}) {
dexTrades(
date: { since: ${dateFrom}, till: ${dateTill} }
options: { limitBy: { limit: 1, each: "pair_address" }, limit: 2, desc: "final" }
) {
pair_address: smartContract {
address {
address
}
}
first_trade_price: minimum(of: block, get: price)
last_trade_price: maximum(of: block, get: price)
diff: expression(get: "last_trade_price - first_trade_price")
div: expression(get: "diff / first_trade_price")
final: expression(get: "div * 100")
baseCurrency {
symbol
address
}
quoteCurrency {
symbol
address
}
}
}
}
`;
// Make an API request to fetch query data
axios
.post(
API_ENDPOINT,
{
query: query,
},
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
},
}
)
.then((response) => {
const data = response.data.data.ethereum;
console.log(data);
return data;
})
.catch((error) => {
console.error("Error fetching data:", error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment