0

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?

jww
  • 97,681
  • 90
  • 411
  • 885
  • 2
    Don't ever post your access keys in a question. I edited out your api key, although anyone with enough rep can still see it (I suggest regenerating it). – David Makogon Oct 05 '17 at 12:01

1 Answers1

-1

My reccomendation will be to input this into the console, as you have done already, and then open it in your web broswer with the inspector (Ctrl + shift + i in chrome). What this should do is allow you to see the object and all of it's components, so you can see the structure. Similarly, you can use

Object.keys(obj)

in order to see all the keys, so looping for each key may tell you what is where and from there, you can sufficiently code.

Martin
  • 231
  • 2
  • 11