I have a script which is taking data from Binance API every 30 minute interval and shows it in terminal. I would like to calculate the average for every asset which I have in array.
This is Node-Schedule package - const j = schedule.scheduleJob('* * * * *'
Small example: var array = ["ADABTC", "AEBTC", "AIONBTC"]
I want to calculate separate average for "ADABTC", for "AEBTC" and for "KAVABTC".
Full Code
const { MongoClient } = require('mongodb');
const schedule = require('node-schedule');
const fetch = require('node-fetch');
const symbols = ["ADABTC", "AEBTC", "AIONBTC", "ALGOBTC", "ARDRBTC", "ARKBTC", "ATOMTC"]
const getBTCData = async symbol => {
let data = await fetch(`https://api.binance.com/api/v3/klines?symbol=${symbol}&interval=30m&limit=1`).then(res => res.json());
const btcusdtdata = data.map(d => {
return {
Volume: parseInt(d[5]),
Timespan: 30,
}
});
console.log(btcusdtdata);
};
const sleep = ms => new Promise(res => setTimeout(res, ms));
const j = schedule.scheduleJob('* * * * *', async() => {
for (let symbol of symbols) {
await getBTCData(symbol);
await sleep(4000);
}
});
Goal: How I can calculate the average of Volume which is this part - Volume: parseInt(d[5]), for every asset if I will receive them every 30 minute?