I am very new to this. But what I am trying to achieve eventually is the plotting of a real time graph of stock data onto a webpage.
I have the following code that takes the data from the Alpha Vantage API and returns in JSON.
var apiKey = "<key>";
var symbol = "MSFT";
var interval = "1min";
var url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol="+symbol+"&interval="+interval+"&apikey="+apiKey;
$(function() {
var $stocks = $('#stocks');
$.ajax({
type: 'GET',
url: url,
success: function(stockInfo) {
console.log('success', stockInfo);
}
});
});
When I run the code, the following is printed to the console.
{
"Meta Data": {
"1. Information": "Intraday (1min) prices and volumes",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2017-10-04 16:00:00",
"4. Interval": "1min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (1min)": {
"2017-10-04 16:00:00": {
"1. open": "74.6850",
"2. high": "74.7200",
"3. low": "74.6500",
"4. close": "74.6900",
"5. volume": "1664269"
},
"2017-10-04 15:59:00": {
"1. open": "74.6800",
"2. high": "74.7000",
"3. low": "74.6800",
"4. close": "74.6850",
"5. volume": "201999"
},
etc. etc. printing all the stock prices, An example is here:
https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo
So basically, I can see there are multiple objects here? There is the meta data followed by the stock price data. I am not sure how I access this information.
I want to be able to store the open, high, low and close price such that I can plot a candle graph with the data later. I am not sure how I can retrieve that data and save it somewhere.
Following that, I want to plot the graph in real time, so how would I keep making api calls so that I can keep getting the updated information?