My code is as it follows:
const Binance = require('node-binance-api'); const binance = new Binance().options({ APIKEY: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', APISECRET: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' }); const repeating = async () => { let lastPrice = await binance.allOrders("XRPUSDT", (error, orders, symbol) => { if(error) return console.log(error.body) console.log('Looking last price for ' + symbol) console.log('Last price: ' + orders[0].price) }, {limit:1}); } repeating();`
And the console gives me:
Looking last price for XRPUSDT order
Last price: 0.53960000
I want to use the value “orders[0].price” outside the function and store it in a variable if possible for future use, like this:
let buyPrice = orders[0].price await binance.buy("XRPUSDT", buyQuantity, buyPrice, {type : 'LIMIT'}).then(resp => console.log(resp)).catch(err => console.log(err.body)), (error, response) => { if ( error ) return console.info(error); console.log("Limit Buy response: ", response); console.log("order id: " + response.orderId); }
Inside the async function of course. The think is if I try to show on console the variable “lastPrice” it shows as undefined