Last active
June 30, 2021 08:03
-
-
Save sayon-bitquery/6aff233e277c754857845b1f852ad7c4 to your computer and use it in GitHub Desktop.
tradingview-2: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, onHistoryCallback, onErrorCallback, first) =>{ | |
try{ | |
if (resolution==='1D') { | |
resolution = 1440; | |
} | |
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(), | |
"interval": Number(resolution), | |
"tokenAddress": symbolInfo.ticker | |
}, | |
mode: 'cors', | |
headers: { | |
"Content-Type": "application/json", | |
"X-API-KEY": "YOUR UNIQUE API" | |
} | |
}) | |
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}) | |
// onErrorCallback(err) | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment