I am trying to use the node binance api to pull candlestick data for some cryptocurrency data for the last 24 hours. The following is my code;
export function graph(name) {
return binance.candlesticks(name + "USDT", "1h", function(error, ticks) {
let points = [];
for (let i = 1; i <= 25; i++) {
let last_tick = ticks[ticks.length - 26 + i];
let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick;
let temp = [time, Number(open), Number(high), Number(low), Number(close)];
points.push(temp);
}
console.log(points) //Prints a list of lists of numbers correctly
return points
});
}
console.log(graph("BNB")) // Prints undefined
As commented, when the data is loaded within the function into 'points' using the for loop, I can operate and print it just fine. However, whenever I actually call the function to do something it returns an undefined. When checking typeof, within the function it returns 'object' whereas outside it returns undefined again. Any guidance is appreciated.