I'm trying to have an Axios GET request to be called every 5 minutes, in my .then on the Axios GET request I parse the data and then POST it in a nested Axios request. The POST request though is being triggered before the 5-minute mark. I've tried having them as two separate setIntervals but that hasn't worked for me either. Does anyone have any suggestions and know why the POST is being triggered before the 5 minutes is up.
setInterval(() => {
let uri = 'https://prices.runescape.wiki/api/v1/osrs/5m'
axios.get(uri).then(response => {
console.log(response.data)
this.prices = response.data.data;
this.timestamp = response.data.timestamp
for(const index in this.prices){
this.fiveMinPrice = {
"id": index,
"avgHighPrice": this.prices[index].avgHighPrice,
"avgLowPrice": this.prices[index].avgLowPrice,
"highPriceVolume": this.prices[index].highPriceVolume,
"lowPriceVolume": this.prices[index].lowPriceVolume,
"timestamp": this.timestamp
}
this.fiveMinPrices.push(this.fiveMinPrice)
}
let url = '/api/5m/'
axios.post(url, this.fiveMinPrices).then(response => {
console.log(response)
}).catch(function(error){
console.log(error)
})
}).catch(function(error){
console.log(error)
})
this.fiveMinPrices = []
this.prices = []
this.fiveMinPrice = {}
this.timestamp = 0
}, 300000);