PredictIt¶
This module lets you get question and prediction information from PredictIt via the API (https://predictit.freshdesk.com/support/solutions/articles/12000001878)
PredictIt¶
-
class
PredictIt
[source]¶ The main class for interacting with PredictIt.
-
get_market
(id)[source]¶ Return the PredictIt market with the given id. A market’s id can be found in the url of the market.
- Parameters
id (
int
) – market id- Return type
- Returns
market
-
property
markets
¶ Generate all of the markets currently in PredictIt.
- Return type
- Returns
iterator of PredictIt markets
-
PredictItMarket¶
-
class
PredictItMarket
(predictit, data)[source]¶ A PredictIt market.
- Parameters
- Variables
api_url (str) – url of the PredictIt API for the given question
name (str) – name of the market
shortName (str) – shortened name of the market
image (str) – url of the image resource of the market
url (str) – url of the market in PredictIt
status (str) – status of the market. Closed markets aren’t included in the API, so always “Open”
timeStamp (datetime.datetime) – last time the market was updated. The API updates every minute, but timestamp can be earlier if it hasn’t been traded in
-
get_question
(id)[source]¶ Return the specified question given by the id number.
- Parameters
id (
int
) – question id- Return type
- Returns
question
-
property
questions
¶ Generate all of the questions in the market.
- Return type
- Returns
generator of questions in market
PredictItQuestion¶
-
class
PredictItQuestion
(market, data)[source]¶ A single binary question in a PredictIt market.
- Parameters
market (
PredictItMarket
) – PredictIt market instancedata (
Dict
) – Contract JSON retrieved from PredictIt API
- Variables
market (PredictItMarket) – PredictIt market instance
dateEnd (datetime.datetime) – end-date of a market, usually None
image (str) – url of the image resource for the contract
name (str) – name of the contract
shortName (str) – shortened name of the contract
status (str) – status of the contract. Closed markets aren’t included in the API, so always “Open”
lastTradePrice (float) – last price the contract was traded at
bestBuyYesCost (float) – cost to buy a single Yes share
bestBuyNoCost (float) – cost to buy a single No share
bestSellYesCost (float) – cost to sell a single Yes share
bestSellNoCost (float) – cost to sell a single No share
lastClosePrice (float) – price the contract closed at the previous day
displayOrder (int) – position of the contract in PredictIt. Defaults to 0 if sorted by lastTradePrice
-
sample_community
()[source]¶ Sample from the PredictIt community distribution (Bernoulli).
- Return type
- Returns
true/false
-
static
to_dataframe
(questions, columns=None)[source]¶ Summarize a list of questions in a dataframe
- Parameters
questions (
List
[PredictItQuestion
]) – questions to summarizecolumns – list of column names as strings
- Return type
DataFrame
- Returns
pandas dataframe summarizing the questions