total_arr={}
total=0
data={"a":1,"b":2,"c":3}
const Binance = require('node-binance-api');
const binance = new Binance().options({
APIKEY: '<key>',
APISECRET: '<secret>'
});
async function trigger(){
async function trig() {
for (keys in data){
var x= await binance.futuresMarketBuy( 'BNBUSDT', data[keys] )
var x2= await binance.futuresMarketBuy( 'BTCUSDT', x )
total_arr["buy"+keys]=x+x2;
}
}
async function trig2() {
var y =await binance.futuresMarketSell( 'BNBUSDT', data[keys] )
var y2= await binance.futuresMarketSell( 'BTCUSDT', y )
total_arr["sell"+keys]=y;
}
async function trigger(){
for (keys in data){
await trig(); /*I want to run trig() and trig2() asynchronously */
await trig2();
}
for (iterat in data) await {
total=total+data[iterat] /*AFTER trig() and trig2() have COMPLETELY run in for loop, I want
to add them up this way*/
}
console.log(total)
}
}
trigger();
I want to run trig() and trig2() asynchronously but it still runs sequentially despite using async/await. What am I doing wrong ? . Please help. I have experimented with code many times but it still runs sequentially. Please Help.