Title: | Interface to the 'PredictIt' API |
---|---|
Description: | Wrapper to retrieve market data, explore available markets, and plot historical price data from the 'PredictIt' public API (<https://www.predictit.org/api/marketdata/all/>). The package comes with a demo 'shiny' application for illustrating example use cases. License to use data made available via the API is for non-commercial use and 'PredictIt' is the sole source of such data. |
Authors: | Daniel Kovtun [cre, aut] |
Maintainer: | Daniel Kovtun <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-10 04:30:19 UTC |
Source: | https://github.com/danielkovtun/rpredictit |
Wrapper function to get all available 'PredictIt' markets and contract prices.
all_markets()
all_markets()
A tibble
containing bid and ask data for all
'PredictIt' markets.
markets <- all_markets() markets
markets <- all_markets() markets
Wrapper function to apply HTML formatting to 'PredictIt' market
data. Can be displayed in a shiny
app, or standalone in an
htmlwidget
(e.g. datatable
).
format_market_data(data)
format_market_data(data)
data |
'PredictIt' market data, of class |
A tibble
containing bid and ask data formatted
with HTML tags and user-friendly column names.
## Only run this example in interactive R sessions if (interactive()) { data <- all_markets() format_market_data(data) }
## Only run this example in interactive R sessions if (interactive()) { data <- all_markets() format_market_data(data) }
Function to make an interactive
dygraphs::dygraph
plot of historical
contract data.
historical_plot(contract_data)
historical_plot(contract_data)
contract_data |
Named list containing contract name and data of class
|
Interactive dygraphs::dygraph
plot
containing time series data for contract 'close' prices.
filename <- "What_will_be_the_balance_of_power_in_Congress_after_the_2020_election.csv" csv_path <- system.file("extdata", filename, package = "rpredictit") contract_data <- parse_historical_csv(csv_path) historical_plot(contract_data)
filename <- "What_will_be_the_balance_of_power_in_Congress_after_the_2020_election.csv" csv_path <- system.file("extdata", filename, package = "rpredictit") contract_data <- parse_historical_csv(csv_path) historical_plot(contract_data)
Wrapper function to return a
datatable
containing 'PredictIt' market data.
Can be displayed in a shinyApp
, RMarkdown document,
or exported via saveWidget()
.
markets_table(data)
markets_table(data)
data |
'PredictIt' market data, of class |
An interactive datatable
object
containing formatted bid and ask data for the provided market data.
data <- all_markets() markets_table(data)
data <- all_markets() markets_table(data)
Helper function to parse a 'csv' file obtained from the
'PredictIt' website, containing historical 'OHLCV' (Open, High, Low, Close,
Volume) data, into an object of class xts
.
parse_historical_csv(csv_path, filename = NA)
parse_historical_csv(csv_path, filename = NA)
csv_path |
Path to a 'csv' file containing historical 'OHLCV' data for a specific contract. Expected format is the same schema as the 'csv' file downloaded from the 'PredictIt' website. |
filename |
Optional name to give the 'csv' file when the filepath is derived from a temporary directory. |
A named list containing the following elements:
An S3 object of class xts
. Time series
containing the 'close' price data for the contract provided.
A character
representing the contract
name, derived from the input file name. If a filename
argument is
provided, the contract name will be assigned to that value.
filename <- "What_will_be_the_balance_of_power_in_Congress_after_the_2020_election.csv" csv_path <- system.file("extdata", filename, package = "rpredictit") parse_historical_csv(csv_path)
filename <- "What_will_be_the_balance_of_power_in_Congress_after_the_2020_election.csv" csv_path <- system.file("extdata", filename, package = "rpredictit") parse_historical_csv(csv_path)
Launch a rpredictit
example Shiny app that shows how to easily use
rpredictit
in an app.
Run without any arguments to see a list of
available example apps.
runExample(example)
runExample(example)
example |
The app to launch |
None. Runs a demo Shiny application. This function normally does not return; interrupt R to stop the application.
## Only run this example in interactive R sessions if (interactive()) { # List all available example apps runExample() runExample("demo") }
## Only run this example in interactive R sessions if (interactive()) { # List all available example apps runExample() runExample("demo") }
Wrapper function to get data for a specific market.
single_market(id)
single_market(id)
id |
Numerical code pertaining to the market. You can find a market's numerical code by consulting its URL or by first calling the all markets API. |
A tibble
containing bid and ask data for a
specific 'PredictIt' market.
## Only run this example in interactive R sessions if (interactive()) { markets <- all_markets() id <- markets$id[1] single_market(id) }
## Only run this example in interactive R sessions if (interactive()) { markets <- all_markets() id <- markets$id[1] single_market(id) }
Wrapper function to get all available 'PredictIt' tweet count markets and contract prices.
tweet_markets()
tweet_markets()
A tibble
containing bid and ask data for all
tweet count markets.
## Only run this example in interactive R sessions if (interactive()) { tweet_markets() }
## Only run this example in interactive R sessions if (interactive()) { tweet_markets() }