knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

CRAN status Codecov test coverage R build status

riingo

riingo allows you to access the Tiingo API for stock prices, cryptocurrencies, and intraday feeds from the IEX (Investors Exchange). This can serve as an alternate source of data to Yahoo Finance.

Installation

Install the stable version from CRAN with:

install.packages("riingo")

Install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("DavisVaughan/riingo")

API Token

The first thing you must do is create an account and set an API token. I recommend using the two functions below to help create your account and find the token.

riingo_browse_signup()
riingo_browse_token() # This requires that you are signed in on the site once you sign up

Once you have signed up and have an API token, I recommmend setting the token as an environment variable, RIINGO_TOKEN in an .Renviron file. The easiest way to do this is with usethis.

usethis::edit_r_environ()

# Then add a line in the environment file that looks like:
RIINGO_TOKEN = token_here

Do not put the token in quotes, and restart R after you have set it.

See the documentation ?riingo_get_token() for more information.

Basic example

library(riingo)

Let's grab some data with riingo. The default parameters attempt to get 1 year's worth of data.

riingo_prices("AAPL")

But of course you can try and get as much as is available...

riingo_prices("AAPL", start_date = "1950-01-01")

And multiple tickers work as well.

riingo_prices(c("AAPL", "IBM"), start_date = "2001-01-01", end_date = "2005-01-01", resample_frequency = "monthly")

Intraday data

You can get limited intraday data with riingo_iex_prices(). This gives you access to Tiingo's direct feed to the IEX.

riingo_iex_prices("AAPL", resample_frequency = "1min")

See the documentation for all of the restrictions.

Meta data

Meta data about each ticker is available through riingo_meta().

riingo_meta(c("AAPL", "QQQ"))

Available tickers

You can check if a ticker is supported on Tiingo with is_supported_ticker() and you can get a tibble of all supported tickers with supported_tickers()

is_supported_ticker("AAPL")

tickers <- supported_tickers()
tickers

Quote data

Another benefit of getting a feed from IEX is real time quote data. This includes TOP (top of book) bid and ask prices, along with most recent sale prices.

It is normal for some fields to return NA when outside of trading hours.

riingo_iex_quote(c("AAPL", "QQQ"))

Crypto data

Cryptocurrency data can be accessed with riingo_crypto_*() functions. By default, 1 year's worth is pulled if available. Some tickers go back much further than others.

riingo_crypto_prices(c("btcusd", "btceur"))

Intraday data is available as well. The intraday ranges are not well documented, so it is a little hard to know what you can pull. From what I have discovered, you can pull a few days at a time, with the max date of intraday data being about ~4 months back (When the date was April 5, 2018, I could pull intraday data back to December 15, 2017, but only 5000 minutes at a time).

riingo_crypto_prices("btcusd", start_date = Sys.Date() - 5, end_date = Sys.Date(), resample_frequency = "1min")

Also available are meta data with riingo_crypto_meta(), and TOP (top of book) quote data with riingo_crypto_quote().

Lastly, you can extract raw (unaggregated) data feeds from multiple exchanges by using the raw = TRUE argument in the price and quote crypto function.

Related projects



business-science/riingo documentation built on Sept. 16, 2020, 4:39 p.m.