0

I am trying to render tradingview chart using tradingview charting library and using bitquery api for datafeed.

Chart is being displayed but there is no data on the chart.

I opened the inspect element and noticed this:

enter image description here

More specifically the part about RangeError: Invalid time value I am assuming that's what's causing the chart to not load any candlestick data?

This is the section of the code in datafeed.js:

// This method is used by the charting library to get historical data for the symbol. 
getBars: async(symbolInfo, resolution, from, to, 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(from).toISOString(),
                "to": new Date(to).toISOString(),
                "interval": Number(resolution),
                "tokenAddress": symbolInfo.ticker
            },
            
            mode: 'cors',
            headers: {
                "Content-Type": "application/json",
                "X-API-KEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            }
            
        })
        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)
    }

I am fairly new with tradingview charting library and JS, so I need suggestions to fix this.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Umer
  • 183
  • 2
  • 16
  • 1
    I can't see anything in that picture of the error message since my company blocks imgur.com domains. Perhaps you could, as described in [ask], provide the text as text, rather than as a picture of text? – Heretic Monkey Jun 29 '21 at 19:39
  • Based on the code, it could be that anywhere you are passing a string to `new Date(string)` the string is null or otherwise not in a format parseable by `Date` (see [Why does Date.parse give incorrect results?](https://stackoverflow.com/q/2587345/215552)). – Heretic Monkey Jun 29 '21 at 19:42
  • You need to log `el.timeInterval.minute` somewhere so you can see what's wrong with the input date. At the moment there is no way for someone to answer this. – loganfsmyth Jun 29 '21 at 20:07

0 Answers0