Import Stock Prices from Alpha Vantage API to Airtable

In this guide, we will fetch stock prices in Airtable using the Alpha Vantage API. Alpha Vantage offers free stocks, forex and cryptocurrency data APIs. We'll use their stocks API and the Data Fetcher Airtable app to create a stock portfolio tracker in Airtable.

Install Data Fetcher

Create Output Table

  • Create a table in your base called 'Stocks'.
  • Change the name of the primary field to 'Ticker'. Add the stock tickers you want to fetch, e.g. 'IBM, as records in this table
Screenshot 2021-07-28 at 15.38.40.png

Get Alpha Vantage API Key

Import Stock Prices from Alpha Vantage API to Airtable

  • On the home screen of the Data Fetcher app, click 'Create request'.
  • On the create request screen, enter the request name 'Fetch stock prices'.
  • Based on the Alpha Vantage API documentation, the base URL for all API requests is https://www.alphavantage.co/query. Enter this URL in the URL field on the create request screen:

https://www.alphavantage.co/query

The full URL should now be:

https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=***Stocks*Ticker***&apikey=YOUR_API_KEY

  • Set the output table to the 'Stocks' table by clicking 'Use current'.
  • Set the output view to 'Grid view' by clicking 'Use current'.

Screenshot 2021-07-28 at 15.56.23.png
  • Click 'Advanced' to open the advanced settings.
  • Under 'Run on Multiple Records', click 'Use current' to set the table to 'Stocks', then click the second 'Use current' button to set the view to 'Grid view'. This means an API request will run for every record in our 'Stocks' table and update the price.
Screenshot 2021-07-28 at 15.57.34.png

Screenshot 2021-07-28 at 16.17.11.png
  • Click 'Run'. You'll see a loading message while the request runs, then the response field mapping modal will open. This is where we select which fields from the API response to keep and how they should map to the fields in the output table. Click 'Show response' on this modal to see the actual response.
  • Click 'Filter all' to deselect all fields, then select the following fields and data types:

Response Field

Data type

Use table field

Or, create field:

Global Quote.05. price

Currency

Price

Global Quote.07. latest trading day

Date

Last Updated

Screenshot 2021-07-28 at 16.00.55.png
  • Click 'Confirm'. Data Fetcher will create the new fields in the output table, then the request will run again and the prices will be imported from the Alpha Vantage API into Airtable!
Screenshot 2021-07-28 at 16.02.06.png
  • Click 'Save'.

Build a Stock Portfolio/Tracker in Airtable

  • Create a table in your base called 'Portfolio'.
  • Change the primary field to 'Id' with type 'Autonumber'.
  • Add a field called 'Stock' that is linked to the 'Stocks' table.
  • Add a field called 'Price' that is a lookup of the 'Stock' field's price.
  • Add a field called 'Shares' with type 'Number'. For each stock, enter how many of the stock you own.
  • Add a formula field called 'Value (USD)' with the formula '{Price}*Shares' and select 'Currency' formatting with the maximum precision.

Update Stock Prices Automatically

At the moment you have to update the stock prices by manually clicking the 'Run' button. Let's set them to update automatically by using Data Fetcher's scheduled requests feature.

  • On the create request screen in Data Fetcher, scroll to 'Schedule'.
  • You will need a paid account to use this feature, so click the button to upgrade your account if you haven't already. After upgrading, click the 'I've done this' button.
  • Add your Airtable API key if you haven't already.
  • Turn on 'Schedule this API request'.
  • Set how often you want the request to run.
  • Click 'Save'.

Screenshot 2021-07-28 at 16.07.36.png