I want to update stock prices on my page every minute and display new prices without refreshing the page. Could you please help me how to do this.
$(function () {
var stocks = [];
var symbols = ['AAPL', 'MSFT'];
symbols.forEach(symbol => makeAjaxCall(symbol));
function makeAjaxCall(param) {
$.ajax({
type: "GET",
url: "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=" + param + "&interval=1min&apikey=8TKKZE0GET944FMW",
success: function (result) {
stocks = result;
getPrices();
}
});
}
function getPrices() {
var metaData = stocks["Meta Data"],
timeSeries = stocks["Time Series (1min)"],
symbol = metaData["2. Symbol"];
var priceList2 = '';
Object.getOwnPropertyNames(lastDate).forEach(function (val, idx, array) {
priceList += val + ': ' + lastDate[val] + '<br>';
});
document.getElementById("demo").innerHTML += '<div class="eachStock"><a href="#" data-stock="' + symbol + '">' + symbol + '</a></div><div>' + priceList + '</div>';
}
});
My html file:
<div id="demo"></div>
Thanks!