Forum Discussion

Gjakova's avatar
Gjakova
Post Patron
6 years ago
Solved

How can I retrieve multiple stock at once?

Hi there,

I am using the Alpha Vantage API and I would like to retrieve stock data from like 200 companies or so. The only problem I have, is that in order to do that, I have to manually insert the link 200 times. Is there a way to automate this and how?

I looked into functions, but it seems like a maze. I can't figure out where to start and which function to use.

My script for Apple stock looks like this:

 

let
Source = Json.Document(Web.Contents("https://www.alphavantage.co/" & "query?function=TIME_SERIES_DAILY" & "&symbol=AAPL" & "&outputsize=full" & "&apikey=1234567890")),
#"Time Series (Daily)" = Source[#"Time Series (Daily)"],
#"Converted to Table" = Record.ToTable(#"Time Series (Daily)"),
#"Expanded Value" = Table.ExpandRecordColumn(#"Converted to Table", "Value", {"1. open", "2. high", "3. low", "4. close", "5. volume"}, {"1. open", "2. high", "3. low", "4. close", "5. volume"})
in
#"Expanded Value"

 

Now I want to replace &symbol=AAPL for a function, so I could retrieve multiple stock from Google, Netflix, Tesla etc. at once.

I created an Excel file with the stock names of 100 different companies. I look at this blog: https://adatis.co.uk/Loop-through-Multiple-Web-Pages-using-Power-Query/ to do the same trick, but since he is using years, I can't seem to duplicate it.
Could someone help me out please? Thanks in advance!