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
#> Warning: `as.tbl()` was deprecated in dplyr 1.0.0.
#> ℹ Please use `tibble::as_tibble()` instead.
#> ℹ The deprecated feature was likely used in the rpredictit package.
#> Please report the issue at
#> <https://github.com/danielkovtun/rpredictit/issues>.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> # A tibble: 87 × 20
#> id name shortName image url timeStamp status contract_id
#> <int> <chr> <chr> <chr> <chr> <dttm> <chr> <int>
#> 1 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31464
#> 2 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31458
#> 3 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31459
#> 4 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31460
#> 5 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31461
#> 6 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31462
#> 7 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31788
#> 8 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31463
#> 9 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31465
#> 10 8095 Who will … NYC Mayo… http… http… 2025-03-09 23:03:21 Open 31466
#> # ℹ 77 more rows
#> # ℹ 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()
:
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/.