ManifoldAPI#
- class autofold.api.ManifoldAPI(dev_mode=False)#
- add_liquidity(market_id, amount)#
POST /v0/market/[marketId]/add-liquidity
Adds liquidity to a specific market.
- Parameters:
market_id (str) – The ID of the market. This parameter is required.
amount (float) – The amount of liquidity to be added. This parameter is required.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Examples
add_liquidity("marketId123", 500.0)
- cancel_bet(bet_id)#
POST /v0/bet/cancel/[betId]
Cancels the limit order of a bet with the specified id.
- Parameters:
bet_id (str) – Required. The unique identifier for the bet to be cancelled.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Note
This action is irreversible.
Examples
cancel_bet("betId123")
- close_market(market_id, close_time=None)#
POST /v0/market/[marketId]/close
Closes a market on behalf of the authorized user.
- Parameters:
market_id (str) – The unique identifier for the market to be closed. This parameter is required.
close_time (int) – Optional. Milliseconds since the epoch to close the market at. If not provided, the market will be closed immediately. Cannot provide close time in the past.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Examples
close_market("marketId123") close_market("marketId123", closeTime=1672444800000)
- create_comment(contract_id, content=None, html=None, markdown=None)#
POST /v0/comment
Creates a comment in the specified market.
- Parameters:
contract_id (str) – Required. The ID of the market to comment on.
content (str or None) – Optional. The comment to post, formatted as TipTap json. :conflicted: html, markdown
html (str or None) – Optional. The comment to post, formatted as an HTML string. :conflicted: content, markdown
markdown (str or None) – Optional. The comment to post, formatted as a markdown string. :conflicted: content, html
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Note
You should provide either content, html, or markdown but not multiple at the same time. They are mutually exclusive.
Examples
create_comment("contractId123", content="some TipTap json content") create_comment("contractId123", html="<p>some HTML content</p>") create_comment("contractId123", markdown="## some markdown content")
- create_market(outcome_type, question, description=None, close_time=None, visibility=None, group_id=None, initial_prob=None, min=None, max=None, is_log_scale=None, initial_value=None, answers=None)#
POST /v0/market
Creates a new market on behalf of the authorized user.
- Parameters:
outcome_type (str) – Required. The type of outcome for the market.
question (str) – Required. The main question for the market.
description (str) – Optional. A detailed description for the market.
close_time (int) – Optional. Time when the market closes.
visibility (str) – Optional. The visibility setting for the market.
group_id (str) – Optional. The group ID associated with the market.
initial_prob (float) – Optional. The initial probability for the market outcome.
min (float) – Optional. The minimum value for a numeric market.
max (float) – Optional. The maximum value for a numeric market.
is_log_scale (bool) – Optional. Whether the market uses a logarithmic scale.
initial_value (float) – Optional. The initial value for the market.
answers (list[str]) – Optional. Possible answers for a free-response market.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Examples
create_market("binary", "Will it rain?", description="Weather prediction", closeTime=1633027200, visibility="public")
- get_bets(user_id=None, username=None, contract_id=None, contract_slug=None, limit=None, before=None)#
GET /v0/bets
Retrieves a list of bets, sorted by their creation date in descending order.
- Parameters:
user_id (str) – Optional. If provided, returns only bets created by the user with this ID.
username (str) – Optional. If provided, returns only bets created by the user with this username.
contract_id (str) – Optional. If provided, returns only bets associated with this contract ID.
contract_slug (str) – Optional. If provided, returns only bets associated with this contract slug.
limit (int) – Optional. The number of bets to return. Defaults to and maxes out at 1000.
before (str) – Optional. Specifies the ID of the bet to start the list from, effectively functioning as an offset. For instance, after requesting the 10 most recent bets, supplying the ID of the 10th bet in a new query would yield bets 11 through 20.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_comments(contract_id=None, contract_slug=None)#
GET /v0/comments
Gets a list of comments for a contract.
- Parameters:
contract_id (str) – Optional. The ID of the contract to read comments for. Either an ID or a slug must be specified.
contract_slug (str) – Optional. The slug of the contract to read comments for. Either an ID or a slug must be specified.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Note
Either contractId or contractSlug must be specified.
Examples
get_comments(contractId="someContractId") get_comments(contractSlug="someContractSlug")
- get_group_by_id(group_id)#
GET /v0/group/by-id/[id]
Gets a group by its unique ID.
- Parameters:
group_id (str) – Required. The id of the group.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_group_by_slug(group_slug)#
GET /v0/group/[slug]
Gets a group by its slug.
Note: group is singular in the URL.
- Parameters:
group_slug (str) – Required. The slug of the group.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_group_markets_by_id(group_id)#
GET /v0/group/by-id/[id]/markets
Gets a group’s markets by its unique ID.
- Parameters:
group_id (str) – Required. The id of the group.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_managrams(to_id=None, from_id=None, limit=None, before=None, after=None)#
GET /v0/managrams
Retrieves a list of managrams, ordered by their creation time in descending order.
- Parameters:
to_id (str) – Optional. Returns managrams sent to this user.
from_id (str) – Optional. Returns managrams sent from this user.
limit (int) – Optional. How many managrams to return. The maximum and the default are 100.
before (str) – Optional. Specifies the createdTime before which you want managrams.
after (str) – Optional. Specifies the createdTime after which you want managrams.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_market_by_id(market_id)#
GET /v0/market/[marketId]
Gets information about a single market by ID. Includes answers, but not bets and comments. Use /bets or /comments with a market ID to retrieve bets or comments.
- Parameters:
market_id (str) – Required. The ID of the market.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_market_by_slug(market_slug)#
GET /v0/slug/[market_slug]
Gets information about a single market by slug (the portion of the URL path after the username).
- Parameters:
market_slug (str) – Required. The slug of the market.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_market_positions(market_id, order='profit', top=None, bottom=None, user_id=None)#
Note
This API endpoint will break for markets with > 4650 positions. Setting either the top or bottom parameters is required to mitigate a 500 server error. See https://github.com/manifoldmarkets/manifold/issues/2031
GET /v0/market/[marketId]/positions
Get positions information about a single market.
- Parameters:
market_id (str) – Required. The ID of the market.
order (str) – Optional. The field to order results by. Default is ‘profit’. Options are ‘shares’ or ‘profit’.
top (int) – Optional. The number of top positions (ordered by ‘order’) to return. Default is None.
bottom (int) – Optional. The number of bottom positions (ordered by ‘order’) to return. Default is None.
userId (str) – Optional. The user ID to query by. Default is None. If provided, only the positions for this user will be returned.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_markets(limit=500, before=None)#
GET /v0/markets
Lists all markets, ordered by creation date descending.
- Parameters:
limit (int) – Optional. How many markets to return. The maximum is 1000 and the default is 500.
before (str) – Optional. The ID of the market before which the list will start.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_me()#
GET /v0/me
Returns the authenticated user.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_user_by_id(user_id)#
GET /v0/user/by-id/[id]
Gets a user by their unique ID. Many other API endpoints return this as the user_id.
- Parameters:
user_id (str) – Required. The ID of the user.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_user_by_username(username)#
GET /v0/user/[username]
Gets a user by their username. Remember that usernames may change.
- Parameters:
username (str) – Required. The username of the user.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- get_users(limit=None, before=None)#
GET /v0/users
Lists all users, ordered by creation date descending.
- Parameters:
limit (int) – Optional. How many users to return. The maximum is 1000 and the default is 500.
before (str) – Optional. The ID of the user before which the list will start. For example, if you ask for the most recent 10 users, and then perform a second query for 10 more users with before=[the id of the 10th user], you will get users 11 through 20.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- is_alive()#
Checks if all relevant threads and the executor are running.
- Returns:
True if all relevant threads and the executor are running, False otherwise.
- Return type:
bool
- make_bet(amount, contract_id, outcome, limit_prob=None, expires_at=None)#
POST /v0/bet
Places a new bet on behalf of the authorized user.
- Parameters:
amount (float) – Required. The amount to bet, in mana, before fees.
contract_id (str) – Required. The ID of the contract (market) to bet on.
outcome (str) –
Required. The outcome to bet on. The outcome type is market-specific:
For binary markets: “YES” or “NO”
For free-response markets: ID of the free response answer
For numeric markets: String representing the target bucket
limit_prob (float) –
Optional. A number between 0.01 and 0.99 inclusive representing the limit probability for your bet.
- For example, if the current market probability is 50%:
A M$10 bet on “YES” with
limitProb=0.4would not be filled until the market probability moves down to 40%.A M$100 bet on “YES” with
limitProb=0.6would fill partially or completely depending on current market conditions.
Any remaining unfilled bet will remain as an open offer for future matches.
expires_at (int) – Optional. A Unix timestamp (in milliseconds) at which the limit bet should be automatically canceled.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Examples
make_bet(100, "contractId123", "YES", limitProb=0.6)
- manage_group_market(market_id, group_id, remove=None)#
POST /v0/market/[marketId]/group
Add or remove a market to/from a group.
- Parameters:
market_id (str) – Required. The ID of the market.
group_id (str) – Required. The ID of the group. Must be an admin, moderator, or creator of the group if curated/private. Must be the market creator or trustworthy-ish if the group is public.
remove (bool) – Optional. Set to true to remove the market from the group.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Example Usage
manage_group_market("marketId123", "groupId456", remove=True)
- resolve_market(market_id, outcome, probability_int=None, resolutions=None, value=None)#
POST /v0/market/[marketId]/resolve
Resolves a market on behalf of the authorized user.
- Parameters:
market_id (str) – Required. The ID of the market.
outcome (str) –
Required. Outcome varies based on the type of market.
For binary markets: One of “YES”, “NO”, “MKT”, or “CANCEL”.
For free response or multiple choice markets: One of “MKT”, “CANCEL”, or a number indicating the answer index.
For numeric markets: One of “CANCEL”, or a number indicating the selected numeric bucket ID.
probability_int (int) – Optional. The probability to use for MKT resolution in binary markets. Also, required if value is present in numeric markets.
resolutions (list[dict]) – Optional. An array of {answer, pct} objects to use as the weights for resolving in favor of multiple free response options. Can only be set with “MKT” outcome. Note that the total weights must add to 100.
value (int) – Optional. The value that the market resolves to in numeric markets.
- Raises:
ValueError – If the total weights in resolutions do not add up to 100.
Examples
resolve_market("marketId123", "YES", probabilityInt=80) resolve_market("marketId456", "MKT", resolutions=[{"answer": "A", "pct": 40}, {"answer": "B", "pct": 60}])
- retrieve_all_data(api_call_func, max_limit=1000, **api_params)#
Iteratively retrieves all available data from an API endpoint that supports pagination via a before parameter.
- Parameters:
api_call_func (Callable) – Required. A function that makes the API call and returns a Future object.
max_limit (int) – Optional. The maximum number of items to request in a single API call. Default is 1000.
api_params (dict) – Optional. Additional parameters to pass to the API call function. Must be passed as keyword arguments.
- Returns:
A list containing all retrieved items.
- Return type:
list
Note
This function is blocking.
Example
retrieve_all_data(api_function, max_limit=200, param1="value1", param2="value2")
- search_markets(term, sort=None, filter_state=None, contract_type=None, topic_slug=None, creator_id=None, limit=None, offset=None, fuzzy=None)#
GET /v0/search-markets
Search or filter markets, similar to the browse page.
- Parameters:
term (str) – Required. The search query in question. Can be an empty string.
sort (str) – Optional. Sort order: score (default), newest, liquidity, or … (see code).
filter_state (str) – Optional. Closing state: all (default), open, closed, resolved, closing-this-month, or closing-next-month.
contract_type (str) – Optional. Type of contract: ALL (default), BINARY (yes/no), MULTIPLE_CHOICE, BOUNTY, POLL, or … (see code).
topic_slug (str) – Optional. Only include questions with the topic tag with this slug.
creator_id (str) – Optional. Only include questions created by the user with this id.
limit (int) – Optional. Number of contracts to return from 0 to 1000. Default 100.
offset (int) – Optional. Number of contracts to skip. Use with limit to paginate the results.
fuzzy (bool) – Optional. If set to any value, uses fuzzier string matching.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
POST /v0/market/[marketId]/sell
Sells some quantity of shares in a binary market.
- Parameters:
market_id (str) – The unique identifier for the binary market where shares are being sold. This parameter is required.
outcome (str) – Optional. Specifies the outcome for which shares are being sold. Can be “YES” or “NO”.
shares (float) – Optional. The amount of shares to sell for the given outcome. If not provided, all shares owned will be sold.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
Examples
sell_shares("marketId123", "YES", 10)
- send_managram(to_ids, amount, message=None)#
POST /v0/managram
Send a managram to another user.
- Parameters:
to_ids (list[str]) – Required. An array of user ids to send managrams to.
amount (int) – Required. The amount of mana (must be >= 10) to send to each user.
message (str) – Optional. A message to include with the managram.
- Returns:
A Future object representing the eventual result of the API call.
- Return type:
Future
- shutdown()#
Shutdown the ManifoldAPI.
Note
Stops all running threads.
Shuts down the thread pool _executor.
Sets all pending Futures to exceptions stating “API is shutting down”.
- Returns:
None
- Return type:
None