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

PredictItMarket

Returns

market

property markets

Generate all of the markets currently in PredictIt.

Return type

Generator[PredictItMarket, None, None]

Returns

iterator of PredictIt markets

refresh_markets()[source]

Refetch all of the markets from the PredictIt API.

PredictItMarket

class PredictItMarket(predictit, data)[source]

A PredictIt market.

Parameters
  • predictit (PredictIt) – PredictIt API instance

  • data (Dict) – Market JSON retrieved from PredictIt API

Variables
  • predictit (PredictIt) – PredictIT API instance

  • api_url (str) – url of the PredictIt API for the given question

  • id (int) – id of the market

  • 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

PredictItQuestion

Returns

question

property questions

Generate all of the questions in the market.

Return type

Generator[PredictItQuestion, None, None]

Returns

generator of questions in market

refresh()[source]

Refetch the market data from PredictIt, used when the question data might have changed.

PredictItQuestion

class PredictItQuestion(market, data)[source]

A single binary question in a PredictIt market.

Parameters
  • market (PredictItMarket) – PredictIt market instance

  • data (Dict) – Contract JSON retrieved from PredictIt API

Variables
  • market (PredictItMarket) – PredictIt market instance

  • id (int) – id of the contract

  • 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

refresh()[source]

Refetch the market data from PredictIt and reload the question.

sample_community()[source]

Sample from the PredictIt community distribution (Bernoulli).

Return type

bool

Returns

true/false

static to_dataframe(questions, columns=None)[source]

Summarize a list of questions in a dataframe

Parameters
  • questions (List[PredictItQuestion]) – questions to summarize

  • columns – list of column names as strings

Return type

DataFrame

Returns

pandas dataframe summarizing the questions