Created
July 21, 2021 17:36
-
-
Save sayon-bitquery/3e3cc783792eca71ab939d3973bb0720 to your computer and use it in GitHub Desktop.
Tradingview-3.10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getBars: async(symbolInfo, resolution, periodParams, onHistoryCallback, onErrorCallback) =>{ | |
try{ | |
if (resolution==='1D') { | |
resolution = 1440; | |
} | |
const response2 = await axios.post(Bitquery.endpoint, { | |
query: ` | |
{ | |
ethereum(network: bsc) { | |
dexTrades( | |
options: {asc: "timeInterval.minute"} | |
date: {since: "2021-06-20T07:23:21.000Z", till: "${new Date().toISOString()}"} | |
exchangeAddress: {is: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73"} | |
baseCurrency: {is: "${baseCurrency}"}, | |
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) | |
} | |
} | |
} | |
`, | |
variables: { | |
"from": new Date("2021-06-20T07:23:21.000Z").toISOString(), | |
"to": new Date("2021-06-23T15:23:21.000Z").toISOString(), | |
"interval": Number(resolution), | |
"tokenAddress": symbolInfo.ticker | |
}, | |
mode: 'cors', | |
}, { | |
headers: { | |
"Content-Type": "application/json", | |
"X-API-KEY": "YOUR UNIQUE API KEY" | |
} | |
}) | |
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 | |
})) | |
if (bars.length){ | |
onHistoryCallback(bars, {noData: false}); | |
}else{ | |
onHistoryCallback(bars, {noData: true}); | |
} | |
} catch(err){ | |
console.log({err}) | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment