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, 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).

  • 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.

make_comment(contractId: str, content: str) Response

Post a comment. [API reference](https://docs.manifold.markets/api#post-v0comment)

Parameters
  • contractId – The market id.

  • content – The comment to post, formatted as a markdown string.

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(market_id: str, outcome: Optional[str] = None, shares: Optional[int] = None) Response

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: object

An 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: object

A single bet

amount: int
challengeSlug: Optional[str]
contractId: str
createdTime: int
dpmShares: Optional[float]
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]
shares: float
userId: Optional[str]
class manifoldpy.api.BinaryMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, probability: float, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

A market with a binary resolution

final_probability() float

Get the final probability of this market

num_traders() int
probability: float
probability_at_time(timestamp: float)
probability_history() Tuple[ndarray[Any, dtype[int64]], ndarray[Any, dtype[float64]]]
start_probability() float

Get the starting probability of the market

class manifoldpy.api.BountiedMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

class manifoldpy.api.Comment(id: str, commentId: str, contractId: str, contractQuestion: str, userUsername: str, userAvatarUrl: str, userId: str, createdTime: int, userName: str, content: str, commentType: str, contractSlug: str, visibility: bool, isApi: bool, betId: Optional[str] = None, betAmount: Optional[float] = None, betOutcome: Optional[Any] = None, commenterPositionOutcome: Optional[Any] = None, replyToCommentId: Optional[str] = None, likes: Optional[int] = None, commenterPositionShares: Optional[float] = None, commenterPositionProb: Optional[float] = None, answerOutcome: Optional[str] = None, hiderId: Optional[str] = None, hidden: Optional[bool] = None, hiddenTime: Optional[int] = None, bettorName: Optional[str] = None, bettorUsername: Optional[str] = None, editedTime: Optional[int] = None, betAnswerId: Optional[str] = None, commenterPositionAnswerId: Optional[str] = None, bountyAwarded: Optional[bool] = None, betReplyAmountsByOutcome: Optional[Dict[str, int]] = None)

Bases: object

A comment on a market

answerOutcome: Optional[str]
betAmount: Optional[float]
betAnswerId: Optional[str]
betId: Optional[str]
betOutcome: Optional[Any]
betReplyAmountsByOutcome: Optional[Dict[str, int]]
bettorName: Optional[str]
bettorUsername: Optional[str]
bountyAwarded: Optional[bool]
commentId: str
commentType: str
commenterPositionAnswerId: Optional[str]
commenterPositionOutcome: Optional[Any]
commenterPositionProb: Optional[float]
commenterPositionShares: Optional[float]
content: str
contractId: str
contractQuestion: str
contractSlug: str
createdTime: int
editedTime: Optional[int]
hidden: Optional[bool]
hiddenTime: Optional[int]
hiderId: Optional[str]
id: str
isApi: bool
likes: Optional[int]
replyToCommentId: Optional[str]
userAvatarUrl: str
userId: str
userName: str
userUsername: str
visibility: bool
class manifoldpy.api.ContractMetric(contractId: str, from_dict: dict, hasNoShares: bool, hasShares: bool, hasYesShares: bool, invested: float, loan: float, maxSharesOutcome: Optional[str], payout: float, profit: float, profitPercent: float, totalShares: dict, userId: str, userUsername: str, userName: str, userAvatarUrl: str, lastBetTime: float)

Bases: object

contractId: str
from_dict: dict
classmethod from_json(json_dict: dict) ContractMetric
hasNoShares: bool
hasShares: bool
hasYesShares: bool
invested: float
lastBetTime: float
loan: float
maxSharesOutcome: Optional[str]
payout: float
profit: float
profitPercent: float
totalShares: dict
userAvatarUrl: str
userId: str
userName: str
userUsername: str
class manifoldpy.api.FreeResponseMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, answers: Optional[List[Any]] = None, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

A market with multiple possible resolutions

answers: Optional[List[Any]]
final_probability() float

Get the final probability of this market

full_history() Tuple[ndarray, ndarray]
outcome_history() Tuple[Tuple[str, ...], ndarray]
probability_history() Tuple[ndarray, ndarray]
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, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: object

A market

bets: Optional[List[Bet]]
closeTime: int
comments: Optional[List[Comment]]
createdTime: int
creatorAvatarUrl: str
creatorId: str
creatorName: str
creatorUsername: str
description: Optional[dict]
final_probability() float

Get the final probability of this market

static from_json(json: Any) Market
get_full_data() 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
lastBetTime: Optional[float]
lastCommentTime: Optional[int]
lastUpdatedTime: 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]
resolverId: Optional[str]
slug: str
start_probability() float

Get the starting probability of the market

textDescription: Optional[str]
totalLiquidity: Optional[float]
uniqueBettorCount: int
url: str
volume: float
volume24Hours: float
class manifoldpy.api.MultipleChoiceMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, answers: List[dict], *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

answers: List[dict]
class manifoldpy.api.NumericMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

class manifoldpy.api.Poll(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = 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, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, value: float, probability: float, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

probability: float
value: float
class manifoldpy.api.QuadraticFundingMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

class manifoldpy.api.StonkMarket(id: str, creatorUsername: str, creatorName: str, createdTime: int, question: str, url: str, slug: str, pool: Dict[str, float], volume: float, volume24Hours: float, outcomeType: Literal['BINARY', 'FREE_RESPONSE', 'PSEUDO_NUMERIC', 'MULTIPLE_CHOICE', 'NUMERIC'], mechanism: str, isResolved: bool, lastUpdatedTime: int, closeTime: int, creatorId: str, creatorAvatarUrl: str, uniqueBettorCount: int, *, resolutionProbability: Optional[float] = None, resolverId: Optional[str] = None, p: Optional[float] = None, totalLiquidity: Optional[float] = None, resolution: Optional[str] = None, resolutionTime: Optional[int] = None, lastBetTime: Optional[float] = None, lastCommentTime: Optional[int] = None, min: Optional[int] = None, max: Optional[int] = None, isLogScale: Optional[bool] = None, textDescription: Optional[str] = None, description: Optional[dict] = None, bets: Optional[List[Bet]] = None, comments: Optional[List[Comment]] = None)

Bases: Market

Don’t ask me what they were thinking with this name

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: object

A 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: Optional[str] = None, userId: Optional[str] = None, marketId: Optional[str] = None, marketSlug: Optional[str] = None, after: int = 0, limit: int = 9223372036854775807) 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.

  • userId – The ID of the user to get bets for.

  • marketId – The ID of the market to get bets for.

  • marketSlug – The slug of the market to get bets for.

  • after – If present, will only fetch bets created after this timestamp.

  • limit – The maximum number of bets to retrieve.

  • as_json – Whether to return the raw JSON response from the API.

manifoldpy.api.get_all_markets(after: int = 0, limit: int = 9223372036854775807) 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.

Parameters
  • after – If present, will only fetch markets created after this timestamp.

  • limit – The maximum number of markets to retrieve.

manifoldpy.api.get_all_users(limit: int = 9223372036854775807) List[User]

Get a list of all users. Repeatedly calls the users endpoint until no new users are returned.

Parameters

limit – The maximum number of users to get.

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.

  • as_json – If true, return the raw json instead of a list of Bet objects.

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_group_by_id(group_id: str) Group

Get a group by its ID.

manifoldpy.api.get_group_by_slug(slug: str) Group

Get a group by its slug.

manifoldpy.api.get_group_markets(group_id: str) List[Market]

Get all markets attached to a group.

manifoldpy.api.get_groups() List[Group]

Get a list of all groups.

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.

manifoldpy.api.get_market_positions(market_id: str, order: Optional[Literal['shares', 'profit']] = None, top: Optional[int] = None, bottom: Optional[int] = None, userId: Optional[str] = None) List[ContractMetric]

Get the positions on a single market.

Parameters
  • market_id – ID of the market to get.

  • order – The ordering for results. Can be either “profit” or “shares”.

  • top – The number of top positions (ordered by order) to return.

  • bottom – The number of bottom positions (ordered by order) to return.

  • userId – The user ID to query by. Default: null. If provided, only the position for this user will be returned.

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 – The user’s 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 – The user’s 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.search_markets(terms: List[str]) List[Market]

Search markets by terms. Returns at most 100 markets. :param terms: A list of search terms. Must not contain spaces.

manifoldpy.api.sell_shares(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.api.weak_unstructure(obj: Any) Dict[str, Any]

Convert an attrs class to a dict.

manifoldpy.calibration module

Tools for calculating calibration and other accuracy metrics.

manifoldpy.calibration.best_possible_beta(actual_beta: ndarray, decimals: int) ndarray

Compute the best possible beta distribution for the given number of bets

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.kl_beta(dist_1: ndarray[Any, dtype[float64]], dist_2: ndarray[Any, dtype[float64]]) ndarray

Calculate KL(dist_1 || dist_2) for each row of dist_1 and dist_2. Formula taken from https://math.stackexchange.com/questions/257821/kullback-liebler-divergence#comment564291_257821

Parameters
  • dist_1 – An array of shape [n, 2]. Each row is [alpha, beta] for a beta distribution.

  • dist_2 – An array of shape [n, 2]. Each row is [alpha, beta] for a beta distribution.

Returns

An array of shape [n]. array[i] is the KL divergence between dist_1[i] and dist_2[i].

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: int, path: Optional[Path] = None)
manifoldpy.calibration.plot_calibration(c_table: ndarray, bins: ndarray, path: Optional[Path] = None)
manifoldpy.calibration.probability_at_fraction_completed(histories: List[Tuple[ndarray, ndarray]], fraction: float) ndarray

Find the probability of each market at the given timepoints.

Parameters
  • histories – A tuple of (timepoints, probabilities) for each market.

  • fraction – The fraction of the market’s runtime that has completed. e.g. 0.5 for halfway finished.

Returns

An array of probabilities. array[i] = probabilities[i] at midpoints[i].

manifoldpy.calibration.probability_at_time(histories: List[Tuple[ndarray, ndarray]], midpoints: ndarray) ndarray

Find the probability of each market at the given timepoints.

Parameters
  • histories – A tuple of (timepoints, probabilities) for each market.

  • midpoints – An array of timepoints for each market.

Returns

An array of probabilities. array[i] = probabilities[i] at midpoints[i].