cannot read property candlesticks of undefined

How do I fix this code?

   getCandles = (ticker, time, amount) => {
    return new Promise((resolve, reject) => {
        let candles = [];
        try {
            binance.candlesticks(ticker, time, (error, ticks, symbol) => {
                if (error) {
                    reject(error)
                }
                if (ticks.length != null || ticks.length != 0) {
                    ticks.forEach(tick => {
                        candles.push({
                            open: tick[1],
                            high: tick[2],
                            close: tick[4],
                            low: tick[3],
                            volume: tick[5],
                            time: tick[0]
                        })
                    })
                    resolve(candles);
                } else {
                    reject(null)
                }
            }, { limit: amount });
        } catch (e) {
            reject(e)
        }
    })
}

what module are you using generally the function to obtain the candles is called klines, not candlestick, possibly there is your error, I recommend that you read the documentation of the package you are using

Could you please reformat this code, and show us the error message. Even better uploading the code in a repo or as a gist can be helpful to debug :slight_smile:

I have tried posting with correct format but its not displaying as such. If you look at the raw data, its formatted correctly. I did post the code here but never got any response to help me solve this.

https://stackoverflow.com/questions/62746476/check-timeframes-causing-errors-on-binance-candlesticks

The error message is clear enough that binance is not defined here.
Either pass it into this method as parameter, or initialise it here.

how do i pass it into this method? I’ve tried everything I know how to do and keep getting error?

getCandles = (binanceInstance) =>  (ticker, time, amount) => {

// same code
}


// where you call getCandles
getCandles(binance)(ticker, time, amount)

Thank you for taking the time to try to help me fix this… Unfortunately I am still getting an error… It is now saying binanceInstance isn’t defined. If i change that to binance, then i get the candlestick error again…