R-language Stock API Example

It’s very easy to use our API with R language, below you can find a very simple example with explanations for R developers.

api.token <- “YOUR_API_KEY_HERE”
symbol <- “AAPL.US”
ticker.link <- paste(“http://eodhistoricaldata.com/api/eod/”, symbol, “?api_token=”, api.token, “&period=m&order=d”, sep=””)

data <- read.csv(url(ticker.link))

For testing purposes you can use this API Key: api_token=OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX. Works with AAPL.US only.

If you run this code in RStudio (or any other software for R), you will get the following output:

R output for EOD stocks data API

As you see, it’s easy to use. Usually, if you used before Yahoo Finance, then URL variable should look like this: ‘http://ichart.finance.yahoo.com/table.csv…..‘ and basically, all you need is to change the beginning of the URL to ‘http://eodhistoricaldata.com/api/table.csv‘ and then add your API Key as an additional parameter.

Please note, that it’s better to use HTTP instead of HTTPS for R language.

Leave a Reply