Submodules
manifoldpy.api module
API bindings
- class manifoldpy.api.APIWrapper(key: str)
Bases:
object- add_liquidity(market_id: str, amount: float) Response
Add liquidity to a market
- Parameters
market_id – The market to add liquidity to.
amount – The amount of liquidity to add.
- cancel_bet(bet_id: str) Response
Cancel a bet. [API reference](https://docs.manifold.markets/api#post-v0betcancelid)
- Parameters
bet_id – The bet id.
- create_market(outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], question: str, description: str, closeTime: int, tags: Optional[List[str]] = None, initialProb: Optional[int] = None, min: Optional[float] = None, max: Optional[float] = None, groupId: Optional[str] = None, visibility: Optional[Literal['public', 'unlisted']] = None, isLogScale: Optional[bool] = None, initialValue: Optional[float] = None, answers: Optional[List[str]] = None) Response
Create a new market [API reference](https://docs.manifold.markets/api#post-v0market)
- Parameters
outcomeType – The kind of market.
question – Short description of the market.
description – Additional details about the market.
closeTime – When the market closes (milliseconds since epoch).
tags – Any tags for the market.
initialProb – The initial probability for the market. Must be between 1 and 99. Used for BINARY markets.
min – Minimum value the market can resolve to. Used for PSEUDO_NUMERIC markets.
max – Maximum value the market can resolve to. Used for PSEUDO_NUMERIC markets.
groupId – The ID of the group the market belongs to, if any.
visibility – The visibility of the market. Must be ‘public’ or ‘unlisted’
isLogScale – If True, the scale between min and max uses exponential increments. Used for PSEUDO_NUMERIC markets.
initialValue – The initial value of the market. Used for PSEUDO_NUMERIC markets.
answers – The possible answers for the market. Used for MULTIPLE_CHOICE markets.
- property headers: Dict[str, str]
- key: str
- make_bet(amount: float, contractId: str, outcome: str, limitProb: Optional[float] = None) Response
Make a bet. [API reference](https://docs.manifold.markets/api#post-v0bet)
- Parameters
amount – The amount to bet
contractId – The market id.
outcome – The outcome to bet on. YES or NO for binary markets
limitProb – A limit probability for the bet. If spending the full amount would push the market past this probability, then only enough to push the market to this probability will be bought. Any additional funds will be left often as a bet that can later be matched by an opposing offer.
- me() Response
Return the authenticated user
- resolve_market(market_id: str, outcome: str, probabilityInt: Optional[int] = None, resolutions: Optional[List[Any]] = None, value: Optional[Any] = None) Response
Resolve an existing market. [API reference](https://docs.manifold.markets/api#post-v0marketmarketidresolve)
- Parameters
market_id – The id of the market to resolve.
outcome – The outcome to resolve with.
probabilityInt – The probability to resolve with (if outcome is MKT)
resolutions – An array of responses and weights for each response (for resolving free responses with multiple outcomes)
value – The value the market resolves to (for numeric markets)
Sell shares in a particular market
- Parameters
market_id – The market to sell shares in
outcome – The kind of shares to sell. Must be YES or NO.
- class manifoldpy.api.Answer
Bases:
objectAn answer to a free response market
- class manifoldpy.api.Bet(contractId: str, createdTime: int, shares: float, amount: int, probAfter: float, probBefore: float, id: str, outcome: str, challengeSlug: Optional[str] = None, isLiquidityProvision: Optional[bool] = None, isCancelled: Optional[bool] = None, orderAmount: Optional[float] = None, fills: Optional[float] = None, isFilled: Optional[bool] = None, limitProb: Optional[float] = None, dpmShares: Optional[float] = None, fees: Optional[dict] = None, sale: Optional[dict] = None, isSold: Optional[bool] = None, loanAmount: Optional[float] = None, isRedemption: Optional[bool] = None, isAnte: Optional[bool] = None, userId: Optional[str] = None)
Bases:
objectA single bet
- amount: int
- challengeSlug: Optional[str]
- contractId: str
- createdTime: int
- fees: Optional[dict]
- fills: Optional[float]
- id: str
- isAnte: Optional[bool]
- isCancelled: Optional[bool]
- isFilled: Optional[bool]
- isLiquidityProvision: Optional[bool]
- isRedemption: Optional[bool]
- isSold: Optional[bool]
- limitProb: Optional[float]
- loanAmount: Optional[float]
- orderAmount: Optional[float]
- outcome: str
- probAfter: float
- probBefore: float
- sale: Optional[dict]
- userId: Optional[str]
- class manifoldpy.api.BinaryMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, tags: List[str], url: str, pool: Dict[str, float], volume: float, volume7Days: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, probability: float, *, resolutionProbability: Optional[float] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, closeTime: Optional[int] = None, creatorId: Optional[str] = None, lastUpdatedTime: Optional[int] = None, creatorAvatarUrl: Optional[str] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, description: Optional[str] = None, textDescription: Optional[str] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)
Bases:
MarketA market with a binary resolution .. attribute:: probability
The current resolution probability
- type
float
- final_probability() float
Get the final probability of this market
- num_traders() int
- probability: float
- probability_at_time(timestamp: int)
- probability_history() Tuple[ndarray, ndarray]
- start_probability() float
Get the starting probability of the market
- class manifoldpy.api.Comment(id: str, contractId: str, userUsername: str, userAvatarUrl: str, userId: str, text: str, createdTime: int, userName: str, betId: Optional[str] = None, answerOutcome: Optional[str] = None)
Bases:
objectA comment on a market
- answerOutcome: Optional[str]
- betId: Optional[str]
- contractId: str
- createdTime: int
- id: str
- text: str
- userAvatarUrl: str
- userId: str
- userName: str
- userUsername: str
- class manifoldpy.api.FreeResponseMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, tags: List[str], url: str, pool: Dict[str, float], volume: float, volume7Days: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, answers: Optional[List[Any]] = None, *, resolutionProbability: Optional[float] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, closeTime: Optional[int] = None, creatorId: Optional[str] = None, lastUpdatedTime: Optional[int] = None, creatorAvatarUrl: Optional[str] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, description: Optional[str] = None, textDescription: Optional[str] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)
Bases:
MarketA market with multiple possible resolutions
- answers: Optional[List[Any]]
- final_probability() float
Get the final probability of this market
- class manifoldpy.api.Group(mostRecentActivityTime: int, aboutPostId: str, creatorId: str, mostRecentContractAddedTime: int, anyoneCanJoin: bool, name: str, totalMembers: int, createdTime: int, about: str, slug: str, id: str, totalContracts: Any, cachedLeaderboard: Dict[str, Any], pinnedItems: List[Any])
Bases:
object“A Manifold group Note that tags count as groups.
- about: str
- aboutPostId: str
- anyoneCanJoin: bool
- cachedLeaderboard: Dict[str, Any]
- createdTime: int
- creatorId: str
- id: str
- mostRecentActivityTime: int
- mostRecentContractAddedTime: int
- name: str
- pinnedItems: List[Any]
- slug: str
- totalContracts: Any
- totalMembers: int
- class manifoldpy.api.Market(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, tags: List[str], url: str, pool: Dict[str, float], volume: float, volume7Days: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, *, resolutionProbability: Optional[float] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, closeTime: Optional[int] = None, creatorId: Optional[str] = None, lastUpdatedTime: Optional[int] = None, creatorAvatarUrl: Optional[str] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, description: Optional[str] = None, textDescription: Optional[str] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)
Bases:
objectA market
- closeTime: Optional[int]
- createdTime: int
- creatorAvatarUrl: Optional[str]
- creatorId: Optional[str]
- creatorName: str
- creatorUsername: str
- description: Optional[str]
- final_probability() float
Get the final probability of this market
- get_updates() Tuple[ndarray, ndarray]
Get all updates to this market.
- Returns
The time of each update, and the probabilities after each update.
- Return type
Tuple[np.ndarray, np.ndarray]
- id: str
- isLogScale: Optional[bool]
- isResolved: bool
- lastUpdatedTime: Optional[int]
- max: Optional[int]
- mechanism: str
- min: Optional[int]
- num_traders() int
- outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC']
- p: Optional[float]
- pool: Dict[str, float]
- probability_history() Tuple[ndarray, ndarray]
- question: str
- resolution: Optional[str]
- resolutionProbability: Optional[float]
- resolutionTime: Optional[int]
- property slug: str
- start_probability() float
Get the starting probability of the market
- tags: List[str]
- textDescription: Optional[str]
- totalLiquidity: Optional[float]
- url: str
- volume: float
- volume24Hours: float
- volume7Days: float
- class manifoldpy.api.MultipleChoiceMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, tags: List[str], url: str, pool: Dict[str, float], volume: float, volume7Days: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, *, resolutionProbability: Optional[float] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, closeTime: Optional[int] = None, creatorId: Optional[str] = None, lastUpdatedTime: Optional[int] = None, creatorAvatarUrl: Optional[str] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, description: Optional[str] = None, textDescription: Optional[str] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)
Bases:
Market
- class manifoldpy.api.NumericMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, tags: List[str], url: str, pool: Dict[str, float], volume: float, volume7Days: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, *, resolutionProbability: Optional[float] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, closeTime: Optional[int] = None, creatorId: Optional[str] = None, lastUpdatedTime: Optional[int] = None, creatorAvatarUrl: Optional[str] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, description: Optional[str] = None, textDescription: Optional[str] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)
Bases:
Market
- class manifoldpy.api.PseudoNumericMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, tags: List[str], url: str, pool: Dict[str, float], volume: float, volume7Days: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, *, resolutionProbability: Optional[float] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, closeTime: Optional[int] = None, creatorId: Optional[str] = None, lastUpdatedTime: Optional[int] = None, creatorAvatarUrl: Optional[str] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, description: Optional[str] = None, textDescription: Optional[str] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)
Bases:
Market
- class manifoldpy.api.User(id: str, createdTime: int, name: str, username: str, url: str, avatarUrl: str, balance: float, totalDeposits: float, profitCached: Dict[str, Optional[float]], creatorVolumeCached: Dict[str, float], bio: Optional[str] = None, twitterHandle: Optional[str] = None, discordHandle: Optional[str] = None, bannerUrl: Optional[str] = None, website: Optional[str] = None)
Bases:
objectA manifold user
- avatarUrl: str
- balance: float
- bannerUrl: Optional[str]
- bio: Optional[str]
- createdTime: int
- creatorVolumeCached: Dict[str, float]
- discordHandle: Optional[str]
- id: str
- name: str
- profitCached: Dict[str, Optional[float]]
- totalDeposits: float
- twitterHandle: Optional[str]
- url: str
- username: str
- website: Optional[str]
- manifoldpy.api.add_liquidity(key: str, *args, **kwargs)
- manifoldpy.api.cancel_bet(key: str, *args, **kwargs)
- manifoldpy.api.create_market(key: str, *args, **kwargs)
- manifoldpy.api.get_all_bets(username: str) List[Bet]
Get all bets by a specific user. Unlike get_bets, this will get all available bets, without a limit on the number fetched. Automatically calls the bets endpoint until all data has been read. You must provide at least one of the arguments, otherwise the server will be very sad.
- Parameters
username – The user to get bets for.
- manifoldpy.api.get_all_markets() List[Market]
Get all markets. Unlike get_markets, this will get all available markets, without a limit on the number fetched. Automatically calls the markets endpoint until all data has been read.
- manifoldpy.api.get_all_users() List[User]
Get a list of all users. Repeatedly calls the users endpoint until no new users are returned.
- Returns
A list of all users.
- manifoldpy.api.get_bets(userId: Optional[str] = None, username: Optional[str] = None, marketId: Optional[str] = None, marketSlug: Optional[str] = None, limit: Optional[int] = 1000, before: Optional[str] = None) List[Bet]
Get bets, optionally associated with a user or market. Retrieves at most 1000 bets. [API reference](https://docs.manifold.markets/api#get-v0bets)
- Parameters
userId – ID of user to get bets for.
username – Username of user to get bets for.
marketId – The market to get bets for.
marketSlug – Slug of the market to get bets for
limit – Number of bets to return. Maximum 1000.
before – ID of a bet to fetch bets before.
- manifoldpy.api.get_comments(marketId: Optional[str] = None, marketSlug: Optional[str] = None) List[Comment]
Get comments, optionally for a market.
- Parameters
marketId – Id of the market to get comments for.
marketSlug – Slug of the market to get comments for.
- manifoldpy.api.get_full_market(market_id: str) Market
Get a single full market. Will include bets and comments
- Parameters
market_id – ID of the market to fetch.
- manifoldpy.api.get_full_markets(reset_cache: bool = False, cache_every: int = 500) List[Market]
Get all full markets, and cache the results.
- Parameters
reset_cache – Whether or not to overwrite the existing cache
cache_every – How frequently to cache the updated markets.
- manifoldpy.api.get_market(market_id: str) Market
Get a single market. Will not include bets or comments.
- Parameters
market_id – ID of the market to get.
- Raises
HTTPError – If the API gives a bad response. This is known to happen with markets with a very large number of bets.
- manifoldpy.api.get_markets(limit: int = 1000, before: Optional[str] = None) List[Market]
Get a list of markets (not including comments or bets). [API reference](https://docs.manifold.markets/api#get-v0markets)
- Parameters
limit – Number of markets to fetch. Max 1000.
before – ID of a market to fetch markets before.
- manifoldpy.api.get_slug(slug: str) Market
Get a market by its slug. [API reference](https://docs.manifold.markets/api#get-v0slugmarketslug)
- manifoldpy.api.get_user_by_id(user_id: str) User
Get the data for one user from their username [API reference](https://docs.manifold.markets/api#get-v0userby-idid)
- Parameters
user_id –
- manifoldpy.api.get_user_by_name(username: str) User
Get the data for one user from their username [API reference](https://docs.manifold.markets/api#get-v0userusername)
- Parameters
username –
- manifoldpy.api.get_users(limit: int = 1000, before: Optional[str] = None) List[User]
Get users up to a limit. [API reference](https://docs.manifold.markets/api#get-v0users)
- Parameters
limit – The maximum number of users to get.
before – The ID of a user to get users before.
- Returns
A list of users.
- manifoldpy.api.make_bet(key: str, *args, **kwargs)
- manifoldpy.api.me(key: str, *args, **kwargs)
- manifoldpy.api.resolve_market(key: str, *args, **kwargs)
- manifoldpy.api.use_api(f)
Automatically create an API Wrapper and use it
- manifoldpy.api.weak_structure(json: dict, cls: Type[T]) T
manifoldpy.calibration module
Tools for calculating calibration and other accuracy metrics.
- manifoldpy.calibration.bet_counts(yes_probs: ndarray, no_probs: ndarray, decimals: int) ndarray
Number of bets that have resolved YES/NO within each bin
- manifoldpy.calibration.beta_binomial_calibration(yes_probs: ndarray, no_probs: ndarray, decimals: int = 1) Tuple[ndarray, ndarray]
Calculate calibration with a beta-binomial model
- Parameters
yes_probs – The probabilities assigned to all YES outcomes
no_probs – The probabilities assigned to all NO outcomes
decimals – The
- Returns
0.95 confidence interval and means for the distributions. Intervals are centered around the median.
- manifoldpy.calibration.binary_calibration(yes_probs: ndarray, no_probs: ndarray, decimals: int = 1) ndarray
Calculate binary calibration across all passed markets
- Returns
An array containing the fraction of markets that actually resolved yes for the corresponding bucket. Buckets are constructed based on the value of decimals, and generally will be 10^decimals + 1. The `i`th element of the returned array is the fraction of markets at that confidence level that resolved true.
- manifoldpy.calibration.brier_score(yes_probs: ndarray, no_probs: ndarray) float
Calculate brier score. Brier score is 1/n * sum((outcome - prob)^2) where outcome is 0 or 1.
- manifoldpy.calibration.build_dataframe(markets: List[Market]) Tuple[DataFrame, List[Tuple[ndarray, ndarray]]]
Build a dataframe from all passed markets.
- Parameters
markets – A list of resolved markets
- Returns
The dataframe, and a list of betting histories for every market.
- Return type
Tuple[pd.DataFrame, Tuple[np.ndarray, np.ndarray]]
- manifoldpy.calibration.extract_binary_probabilities(markets: List[BinaryMarket]) Tuple[ndarray, ndarray]
Get the closing probabilities from all binary markets.
- manifoldpy.calibration.log_score(yes_probs: ndarray, no_probs: ndarray) float
Calculate log score. Log score is sum(-log(p)), where p is the probability on the actual outcome (so 1-p in the case of markets that resolve NO).
- manifoldpy.calibration.market_set_accuracy(yes_probs: ndarray, no_probs: ndarray) Dict[str, Any]
Compute common metrics for a set of markets
- Parameters
yes_probs – The probabilities of all markets that resolved YES.
no_probs – The probabilities of all markets that resolved NO.
- Returns
1% calibration, 10% calibration, beta-binomial model means, beta-binomial model 95% CI, and proper scores.
- manifoldpy.calibration.markets_by_group(df: DataFrame) Dict[str, Series]
Get a dict group -> group’s markets
- manifoldpy.calibration.perfect_calibration(decimals: int) ndarray
- manifoldpy.calibration.plot_beta_binomial(upper_lower: ndarray, means: ndarray, decimals)
- manifoldpy.calibration.plot_calibration(c_table: ndarray, bins: ndarray, path: Optional[Path] = None)
- manifoldpy.calibration.probability_at_time(histories: List[Tuple[ndarray, ndarray]], midpoints: ndarray) ndarray