I want to get the returned data whenever fetching is done, because the correct timestamp will be there after fully fetching however the function will return the link with an empty timestamp instead of the latest timestamp of all the data.
async function pushData(url) {
let settings = { method: "Get" };
let timestamp = "";
let i = 0;
fetch(url, settings)
.then(res => res.json())
.then((json) => {
json.forEach(function (object) {
console.log(object);
i++;
});
timestamp = json[i-1].timestamp;
});
return await 'https://www.bitmex.com/api/v1/trade?count=1000&symbol=XBTUSD&startTime=' + timestamp;
}
var test = pushData('https://www.bitmex.com/api/v1/trade?count=1000&symbol=XBTUSD');
console.log(test);