I am getting undefined for the return statement in this function. Being new to the language, I searched it up and I found out that the function has to be async so that it returns a Promise.
Can someone help me understand why does everything until the console.log(qty) work normally but the return statement is executed before all of that.
Also, what would be the effiecient way to get the result of this function in a variable somewhere else. I tried the async/await and it returns the result in a Promise - which I still have to read on how to parse it.
//convert quantity to correct decimals
function binanceNormalizeQuantity(symbol, quantity) {
requestApiData('GET', 'https://api.binance.com/api/v1/exchangeInfo').then((response) => {
response = JSON.parse(response.target.responseText);
var qty;
for (var i = 0; i < response["symbols"].length; i++) {
if (response["symbols"][i]["symbol"] == symbol) {
var stepSize = Math.log10(1 / parseFloat(response["symbols"][i]["filters"][2]["stepSize"]));
qty = Math.floor(quantity * 10**stepSize)/10**stepSize;
}
}
console.log(qty);
return qty;
});
}