This package is a simple api wrapper for the predictit.org endpoint: https://www.predictit.org/api/marketdata/all It facilititates extraction of instantaneous political market data.
Before installation, it is recommended that you ensure you have a virtual environment activated.
- Clone this repository and cd into it
- run
python setup.py
To use this module, import the Market class.
You can use:
import predictit_data
m = predictit_data.Market()
or
from predictit_data.market import Market
m = Market()
m.data
: Return all market data
m.pull_data
: Pulls latest data (generally unneccessary as other methods check for latest data)
m.get_markets_by_regex
: Returns all markets whose name
matches a regex pattern
m.get_markets_that_contain
: Returns all markets that contain a given string
m.get_data_by_id
: Returns market data for a given id
m.list_parent_markets
: Returns {id: name}
for every available parent market
m.list_sub_markets
: Returns {id: name}
for every available sub market
Market data is structured as a dictionary. See Example.
Notice that there can be a number of "sub markets" in a given "parent market".
In this example there are 4 sub markets, each with a unique id
for a given parent market, that has its own unique id
.
Each sub market has pricing data associated with it; note that no parent market will have pricing data associated with it.
This wrapper enforces an ask I received from [email protected] that the api be called no more than once every 60 seconds. (Note that Predictit only updates the api endpoint once every 60 seconds, so calling it more often than that would be wasteful anyway.)