I’m using vue js.
<script>
import axios from "axios";
import * as Bitquery from "./Bitquery";
export default {
name: 'App',
mounted() {
this.getCoinInfo();
this.getBar();
},
methods: {
async getBar() {
const response2 = await axios.post(Bitquery.endpoint, {
query: Bitquery.GET_COIN_BARS,
variables: {
"from": new Date("2021-06-20T07:23:21.000Z").toISOString(),
"to": new Date("2021-06-23T15:23:21.000Z").toISOString(),
},
mode: 'cors',
headers: {
"Content-Type": "application/json",
"X-API-KEY": "BQYs3889A2N8x3q6euyZWtc3JMosXy6o"
}
})
const bars = response2.data.data.ethereum.dexTrades.map(el => ({
time: new Date(el.timeInterval.minute).getTime(), // date string in api response
low: el.low,
high: el.high,
open: Number(el.open),
close: Number(el.close),
volume: el.volume
}))
console.log(bars)
},
async getCoinInfo() {
const response = await axios.post(
Bitquery.endpoint, {
query: Bitquery.GET_COIN_INFO,
variables: {
"tokenAddress": 'price'
},
mode: 'cors',
headers: {
"Content-Type": "application/json",
"X-API-KEY": "BQYs3889A2N8x3q6euyZWtc3JMosXy6o"
}
}
);
const coin = response.data.data.ethereum.dexTrades[0].baseCurrency;
if(!coin){
console.log('no coin')
}else{
const symbol = {
ticker: 'price',
name: `${coin.symbol}/USD`,
session: '24x7',
timezone: 'Etc/UTC',
minmov: 1,
pricescale: 10000000,
has_intraday: true,
intraday_multipliers: ['1', '5', '15', '30', '60'],
has_empty_bars: true,
has_weekly_and_monthly: false,
supported_resolutions: ['1','5','15','30', '60','1D', '1W', '1M'],
volume_precision: 1,
data_status: 'streaming',
}
console.log(symbol)
}
}
}
}
</script>
Bitquery.js
export const endpoint = 'https://graphql.bitquery.io';
export const GET_COIN_INFO =`
{
ethereum(network: bsc) {
dexTrades(
options: {desc: ["block.height", "transaction.index"], limit: 1}
exchangeAddress: {is: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73"}
baseCurrency: {is: "0x2170ed0880ac9a755fd29b2688956bd959f933f8"}
quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
)
{
block {
height
timestamp {
time(format: "%Y-%m-%d %H:%M:%S")
}
}
transaction {
index
}
baseCurrency {
name
symbol
decimals
}
quotePrice
}
}
}
`;
export const GET_COIN_BARS = `
{
ethereum(network: bsc) {
dexTrades(
options: {asc: "timeInterval.minute"}
date: {since: "2021-06-20T07:23:21.000Z", till: "2021-06-23T15:23:21.000Z"}
exchangeAddress: {is: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73"}
baseCurrency: {is: "0xa93e15caa52c9c2517b709b0b986a80b51b58b01"},
quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"},
tradeAmountUsd: {gt: 10}
)
{
timeInterval {
minute(count: 15, format: "%Y-%m-%dT%H:%M:%SZ")
}
volume: quoteAmount
high: quotePrice(calculate: maximum)
low: quotePrice(calculate: minimum)
open: minimum(of: block, get: quote_price)
close: maximum(of: block, get: quote_price)
}
}
}
`;
consol log