Example: obtaining stock price history from web API

Here is an example of pulling stock market data from Alpha Vantage - a web provider of stock data.

Disclaimer: we’re not affiliated with Alpha Vantage in any way or receive any incentive from them. Just found them in the internet by looking up “free stock API”.

The example uses a free API key (configured in the connector). Feel free to use it in this example for self-educational purposes. For regular use please obtain your own API key.

The example demonstrates:

  • The “Web request” action together with the “Web location” connector.
  • Use of an API key in the “Web location” connector.
  • The advanced parameter type “Fixed list”.
  • Parsing JSON

The API returns a rather unusual JSON that looks as below:

{
    "Meta Data": {
        "1. Information": "Daily Prices (open, high, low, close) and Volumes",
        "2. Symbol": "IBM",
        "3. Last Refreshed": "2020-11-03",
        "4. Output Size": "Compact",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2020-11-03": {
            "1. open": "114.0000",
            "2. high": "115.6500",
            "3. low": "113.6300",
            "4. close": "114.1600",
            "5. volume": "4204287"
        },
        "2020-11-02": {
            "1. open": "112.6500",
            "2. high": "113.8265",
            "3. low": "112.2500",
            "4. close": "112.9100",
            "5. volume": "5311497"
        },
		...
	}
}

The JSON is unusual in that sense that it uses JSON property names as data (in this case, dates). Nevertheless, it’s still can be parsed in EasyMorph.

Note that the full history JSON is pretty large and it takes some time to parse it.

The API documentation is here: https://www.alphavantage.co/documentation/

Here is the example:
stock-history.morph (5.4 KB)