The rpredictit
package provides an interface to the PredictIt public API.
In addition to providing a wrapper to retrieve market data, this package includes visualization functions for plotting historical price data and exploring available markets. The package also comes with a demo shiny application for illustrating example use cases.
rpredictit
is not affiliated with any predictive markets and is presented for informational purposes only. Always confirm with your own research before making an investment. License to use data made available via the API is for non-commercial use and PredictIt is the sole source of such data.
Once released, you may install the stable version from CRAN, or the development version using devtools:
To start off, try running a demo Shiny application included with the package by running:
Try rpredictit::all_markets()
to return a tibble containing bid and ask data for all PredictIt markets:
rpredictit::all_markets()
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
#> # A tibble: 1,028 x 20
#> id name shortName image url timeStamp status contract_id
#> <int> <chr> <chr> <chr> <chr> <dttm> <chr> <int>
#> 1 2721 Whic… Which pa… http… http… 2020-03-17 21:42:45 Open 4390
#> 2 2721 Whic… Which pa… http… http… 2020-03-17 21:42:45 Open 4389
#> 3 2721 Whic… Which pa… http… http… 2020-03-17 21:42:45 Open 4388
#> 4 2721 Whic… Which pa… http… http… 2020-03-17 21:42:45 Open 4391
#> 5 2747 Will… Will Cub… http… http… 2020-03-17 21:42:45 Open 4495
#> 6 2875 Will… Will Cuo… http… http… 2020-03-17 21:42:45 Open 5121
#> 7 2901 Will… Woman pr… http… http… 2020-03-17 21:42:45 Open 5215
#> 8 2902 Will… Will the… http… http… 2020-03-17 21:42:45 Open 5216
#> 9 2903 Will… Will the… http… http… 2020-03-17 21:42:45 Open 5217
#> 10 2992 Will… Will Zuc… http… http… 2020-03-17 21:42:45 Open 5534
#> # … with 1,018 more rows, and 12 more variables: dateEnd <chr>,
#> # contract_image <chr>, contract_name <chr>, contract_shortName <chr>,
#> # contract_status <chr>, lastTradePrice <dbl>, bestBuyYesCost <dbl>,
#> # bestBuyNoCost <dbl>, bestSellYesCost <dbl>, bestSellNoCost <dbl>,
#> # lastClosePrice <dbl>, displayOrder <int>
Alternatively, to return an interactive htmlwidget (DT::datatable) table containing HTML formatted market data, pass the returned bid/ask data to rpredictit::markets_table()
:
To plot historical prices, download a ‘csv’ file for a specific contract from PredictIt’s website and pass the file path to rpredictit::parse_historical_ohlcv()
. Then, pass in the returned contract data object to rpredictit::historical_plot()
:
If you are only interested in “Tweet count” markets, use rpredictit::tweet_markets()
to return all available “Tweet” markets:
To return data for a specific market, use rpredictit::single_market(id)
, where id
refers to the numerical code pertaining to the market of interest. You can find a market’s numerical code by consulting its URL or by first calling the all markets API (all_markets()
)
See the full documentation at https://danielkovtun.github.io/rpredictit.