The ManifoldReader class provides read-only access to Manifold Markets data. No API key is required.
ManifoldReader(timeout=30, retry_config=None)Parameters:
timeout(int): Request timeout in seconds (default: 30)retry_config(dict, optional): Custom retry configuration
Get a list of markets from Manifold Markets.
Parameters:
limit(int, optional): Maximum number of markets to returnbefore(str, optional): Cursor for pagination
Returns: List[Dict[str, Any]] - List of market dictionaries
Example:
reader = ManifoldReader()
# Get 10 most recent markets
markets = reader.get_markets(limit=10)
# Get markets with pagination
markets = reader.get_markets(limit=50, before="cursor_string")Get detailed information about a specific market.
Parameters:
market_id(str): The market ID
Returns: Dict[str, Any] - Market dictionary
Example:
market = reader.get_market("8PLAdy8q8u")
print(f"Question: {market['question']}")
print(f"Probability: {market.get('probability', 0):.1%}")Get market information using the market slug.
Parameters:
slug(str): The market slug (from the URL)
Returns: Dict[str, Any] - Market dictionary
Example:
market = reader.get_market_by_slug("catl-receives-license-renewal-for-y-qz65RqIZsy")Get user information.
Parameters:
user_id(str): The user ID
Returns: Dict[str, Any] - User dictionary
Example:
user = reader.get_user("user_id_here")
print(f"Username: {user['name']}")
print(f"Total deposits: {user.get('totalDeposits', 0)}Ṁ")Get markets created by a specific user.
Parameters:
user_id(str): The user IDlimit(int, optional): Maximum number of markets to return
Returns: List[Dict[str, Any]] - List of market dictionaries
Example:
user_markets = reader.get_user_markets("MikhailTal", limit=20)
print(f"User has created {len(user_markets)} markets")Get bets placed on a specific market.
Parameters:
market_id(str): The market IDlimit(int, optional): Maximum number of bets to return
Returns: List[Dict[str, Any]] - List of bet dictionaries
Search for markets by query string.
Parameters:
query(str): Search querylimit(int, optional): Maximum number of results
Returns: List[Dict[str, Any]] - List of matching markets
The ManifoldWriter class provides authenticated access for trading and market management. Requires a valid API key.
ManifoldWriter(api_key, timeout=30, retry_config=None)Parameters:
api_key(str): Manifold Markets API keytimeout(int): Request timeout in seconds (default: 30)retry_config(dict, optional): Custom retry configuration
Check if the writer is properly authenticated.
Returns: bool - True if authenticated, False otherwise
Example:
writer = ManifoldWriter(api_key="your_key")
if writer.is_authenticated():
print("Successfully authenticated")
else:
print("Authentication failed")Get information about the authenticated user.
Returns: Dict[str, Any] - User dictionary
Example:
user_info = writer.get_me()
print(f"Username: {user_info['name']}")
print(f"Balance: {user_info['balance']}Ṁ")Place a bet on a market.
Parameters:
market_id(str): Market IDoutcome(str): "YES" or "NO"amount(int): Amount in M$ (must be positive integer)probability(float, optional): Limit price (0-1) for limit orders
Returns: Dict[str, Any] - Bet result dictionary
Example:
# Market order
result = writer.place_bet("market_id", "YES", 10)
# Limit order
result = writer.place_bet("market_id", "YES", 10, probability=0.7)Place a YES limit order (convenience method).
Parameters:
market_id(str): Market IDamount(int): Amount in M$limit_prob(float): Limit probability (0.0-1.0)
Returns: Dict[str, Any] - Bet result dictionary
Place a NO limit order (convenience method).
Parameters:
market_id(str): Market IDamount(int): Amount in M$limit_prob(float): Limit probability (0.0-1.0)
Returns: Dict[str, Any] - Bet result dictionary
Cancel a pending bet.
Parameters:
bet_id(str): Bet ID to cancel
Returns: Dict[str, Any] - Cancellation result
Get details of a specific bet.
Parameters:
bet_id(str): Bet ID
Returns: Dict[str, Any] - Bet dictionary
Get current balance.
Returns: float - Balance in M$
Get total deposits.
Returns: float - Total deposits in M$
Get portfolio summary.
Returns: Dict[str, Any] - Portfolio dictionary
Get user's positions.
Parameters:
market_id(str, optional): Filter by specific market
Returns: List[Dict[str, Any]] - List of positions
Create a new market.
Parameters:
question(str): Market questionoutcome_type(str): "BINARY", "FREE_RESPONSE", or "MULTIPLE_CHOICE"**kwargs: Additional market parameters
Returns: Dict[str, Any] - Created market dictionary
Example:
market = writer.create_market(
question="Will AI achieve AGI by 2030?",
outcome_type="BINARY",
description="This market resolves YES if...",
initial_probability=0.3,
close_time=1735689600000, # Unix timestamp
tags=["AI", "AGI", "technology"]
)Close a market with a resolution.
Parameters:
market_id(str): Market IDoutcome(str): "YES", "NO", "MKT", or "CANCEL"probability(float, optional): Resolution probability for "MKT" outcome
Returns: Dict[str, Any] - Market closure result
Post a comment on a market.
Parameters:
market_id(str): Market IDtext(str): Comment textreply_to(str, optional): Comment ID to reply to
Returns: Dict[str, Any] - Comment result
Calculate the impact of a potential bet on market probability.
Parameters:
market_id(str): Market IDamount(float): Bet amountoutcome(str): "YES" or "NO"
Returns: Dict[str, Any] - Impact calculation result
Example:
impact = writer.calculate_market_impact("market_id", 100, "YES")
print(f"Current probability: {impact['current_probability']:.1%}")
print(f"New probability: {impact['new_probability']:.1%}")
print(f"Impact: {impact['estimated_impact']:.3f}")Place a bet only if its impact is below a threshold.
Parameters:
market_id(str): Market IDoutcome(str): "YES" or "NO"amount(int): Bet amountmax_impact(float): Maximum allowed impact
Returns: Dict[str, Any] - Bet result or raises ValueError
Example:
try:
result = writer.place_bet_with_impact_limit(
"market_id", "YES", 100, max_impact=0.05
)
print("Bet placed successfully")
except ValueError as e:
print(f"Bet rejected: {e}")Update user profile information.
Parameters:
**kwargs: Fields to update (e.g., "name", "bio")
Returns: Dict[str, Any] - Updated user data
Example:
updated_user = writer.update_user(
name="New Name",
bio="Updated bio"
)Raised for HTTP errors (network issues, API errors, etc.)
Raised for validation errors (invalid parameters, etc.)
Raised for API endpoints that are not available
from manifoldbot.manifold import ManifoldWriter
import requests
writer = ManifoldWriter(api_key="your_key")
try:
result = writer.place_bet("market_id", "YES", 10)
except requests.RequestException as e:
if e.response.status_code == 400:
print("Bad request - check market ID and parameters")
elif e.response.status_code == 401:
print("Authentication failed - check API key")
elif e.response.status_code == 403:
print("Insufficient permissions")
else:
print(f"API error: {e}")
except ValueError as e:
print(f"Validation error: {e}")The package includes built-in retry logic for handling rate limits and temporary API issues. By default, it will retry failed requests up to 3 times with exponential backoff.
You can customize the retry behavior:
retry_config = {
"max_retries": 5,
"backoff_factor": 2,
"retry_on": [429, 500, 502, 503, 504]
}
reader = ManifoldReader(retry_config=retry_config)
writer = ManifoldWriter(api_key="your_key", retry_config=retry_config)