Methods
Complete reference for all methods available in the Client class.
Overview
The Client class provides a unified interface for interacting with OPINION prediction markets. Methods are organized into these categories:
Market Data - Query markets, prices, and orderbooks
Trading Operations - Place and manage orders
User Data - Access balances, positions, and trades
Smart Contract Operations - Blockchain interactions (split, merge, redeem)
Response Format
All API methods return responses with this structure:
response = client.get_markets()
# Check success
if response.errno == 0:
# Success - access data
data = response.result.data # For single objects
# or
items = response.result.list # For arrays
else:
# Error - check error message
print(f"Error {response.errno}: {response.errmsg}")Response fields:
errno- Error code (0= success, non-zero = error)errmsg- Error message stringresult- Containsdata(single object) orlist(array of objects)
Market Data Methods
get_markets()
Get a paginated list of prediction markets.
Signature:
Parameters:
topic_type
TopicType
No
None
Filter by market type (TopicType.BINARY or TopicType.CATEGORICAL)
page
int
No
1
Page number (≥ 1)
limit
int
No
20
Items per page (1-20)
status
TopicStatusFilter
No
None
Filter by status (ACTIVATED, RESOLVED, or ALL)
Returns: API response with result.list containing market objects
Example:
Raises:
InvalidParamError- If page < 1 or limit not in range [1, 20]
get_market()
Get detailed information about a specific market.
Signature:
Parameters:
market_id
int
Yes
-
Market ID to query
use_cache
bool
No
True
Whether to use cached data if available
Returns: API response with result.data containing market details
Example:
Caching:
Cache duration controlled by
market_cache_ttl(default: 300 seconds)Set
use_cache=Falseto force fresh dataSet
market_cache_ttl=0in Client constructor to disable caching
Raises:
InvalidParamError- If market_id is missing or invalidOpenApiError- If API request fails
get_categorical_market()
Get detailed information about a categorical market (multi-outcome).
Signature:
Parameters:
market_id
int
Yes
Categorical market ID
Returns: API response with categorical market data
Example:
get_quote_tokens()
Get list of supported quote tokens (collateral currencies).
Signature:
Parameters:
use_cache
bool
No
True
Whether to use cached data
Returns: API response with result.list containing quote token objects
Example:
Caching:
Default TTL: 3600 seconds (1 hour)
Controlled by
quote_tokens_cache_ttlparameter
get_orderbook()
Get orderbook (bids and asks) for a specific token.
Signature:
Parameters:
token_id
str
Yes
Token ID (e.g., "token_yes", "token_123")
Returns: API response with orderbook data
Example:
Raises:
InvalidParamError- If token_id is missingOpenApiError- If API request fails
get_latest_price()
Get the current/latest price for a token.
Signature:
Parameters:
token_id
str
Yes
Token ID
Returns: API response with latest price data
Example:
get_price_history()
Get historical price data (candlestick/OHLCV) for a token.
Signature:
Parameters:
token_id
str
Yes
-
Token ID
interval
str
No
"1h"
Time interval: 1m, 1h, 1d, 1w, max
start_at
int
No
None
Start timestamp (Unix seconds)
end_at
int
No
None
End timestamp (Unix seconds)
Returns: API response with price history data
Example:
get_fee_rates()
Get trading fee rates for a token.
Signature:
Parameters:
token_id
str
Yes
Token ID
Returns: API response with fee rate data
Example:
Trading Operations
place_order()
Place a market or limit order.
Signature:
Parameters:
data
PlaceOrderDataInput
Yes
Order parameters (see below)
check_approval
bool
No
Whether to check and enable trading approvals first
PlaceOrderDataInput fields:
marketId
int
Yes
Market ID
tokenId
str
Yes
Token ID to trade
side
OrderSide
Yes
OrderSide.BUY or OrderSide.SELL
orderType
int
Yes
MARKET_ORDER (1) or LIMIT_ORDER (2)
price
str
Yes*
Price string (required for limit orders, "0" for market)
makerAmountInQuoteToken
int or float
No**
Amount in quote token (e.g., 100 for 100 USDT)
makerAmountInBaseToken
int or float
No**
Amount in base token (e.g., 50 for 50 YES tokens)
* Price is required for limit orders, set to "0" for market orders ** Must provide exactly ONE of makerAmountInQuoteToken or makerAmountInBaseToken
Returns: API response with order result
Examples:
Limit Buy Order (using quote token):
Market Sell Order (using base token):
Raises:
InvalidParamError- If parameters are invalid or missingOpenApiError- If API request fails or chain_id mismatch
place_orders_batch()
Place multiple orders in a single batch operation.
Signature:
Parameters:
orders
List[PlaceOrderDataInput]
Yes
A list containing the order details.
check_approval
bool
No
Determines if approvals are verified for all orders.
Returns: List of results with success, result, and error fields for each order
Example:
cancel_order()
Cancel a single order by order ID.
Signature:
Parameters:
order_id
str
Yes
Order ID to cancel
Returns: API response for cancellation
Example:
cancel_orders_batch()
Cancel multiple orders in a batch.
Signature:
Parameters:
order_ids
List[str]
Yes
List of order IDs to cancel
Returns: List of cancellation results for each order
Example:
cancel_all_orders()
Cancel all open orders, optionally filtered by market and/or side.
Signature:
Parameters:
market_id
int
No
Filter by market ID (all markets if None)
side
OrderSide
No
Filter by side (BUY/SELL, all sides if None)
Returns: Dictionary with cancellation summary:
Example:
get_my_orders()
Get user's orders with optional filters.
Signature:
Parameters:
market_id
int
No
0
Filter by market (0 = all markets)
status
str
No
""
Filter by status (e.g., "open", "filled", "cancelled")
limit
int
No
10
Items per page
page
int
No
1
Page number
Returns: API response with result.list containing orders
Example:
get_order_by_id()
Get details for a specific order by ID.
Signature:
Parameters:
order_id
str
Yes
Order ID
Returns: API response with order details
Example:
User Data Methods
get_my_balances()
Get user's token balances.
Signature:
Returns: API response with result.data.balances containing list of balance objects
Example:
get_my_positions()
Get user's open positions across markets.
Signature:
Parameters:
market_id
int
No
0
Filter by market (0 = all)
page
int
No
1
Page number
limit
int
No
10
Items per page
Returns: API response with result.list containing positions
Example:
get_my_trades()
Get user's trade history.
Signature:
Parameters:
market_id
int
No
None
Filter by market
page
int
No
1
Page number
limit
int
No
10
Items per page
Returns: API response with result.list containing trade history
Example:
Smart Contract Operations
These methods interact directly with the blockchain and require gas (BNB).
enable_trading()
Enable trading by approving quote tokens for the exchange contract. Must be called once before placing orders or doing split/merge/redeem operations.
Signature:
Returns: Tuple of (tx_hash, tx_receipt, contract_event)
Example:
Notes:
Only needs to be called once (result is cached for
enable_trading_check_intervalseconds)Automatically called by
split(),merge(),redeem()ifcheck_approval=True
split()
Convert collateral tokens (e.g., USDT) into outcome tokens (e.g., YES + NO).
Signature:
Parameters:
market_id
int
Yes
Market ID
amount
int
Yes
Amount in wei (e.g., 105000000000000000000 for 1 USDT with 18 decimals)
check_approval
bool
No
Auto-call enable_trading() if needed
Returns: Tuple of (tx_hash, tx_receipt, contract_event)
Example:
Raises:
InvalidParamError- If market_id or amount is invalidOpenApiError- If market is not in valid state or chain mismatchBlockchain errors - If insufficient balance or gas
merge()
Convert outcome tokens back into collateral tokens.
Signature:
Parameters:
market_id
int
Yes
Market ID
amount
int
Yes
Amount of outcome tokens in wei
check_approval
bool
No
Auto-call enable_trading() if needed
Returns: Tuple of (tx_hash, tx_receipt, contract_event)
Example:
redeem()
Claim winnings after a market is resolved. Redeems winning outcome tokens for collateral.
Signature:
Parameters:
market_id
int
Yes
Resolved market ID
check_approval
bool
No
Auto-call enable_trading() if needed
Returns: Tuple of (tx_hash, tx_receipt, contract_event)
Example:
Raises:
InvalidParamError- If market_id is invalidOpenApiError- If market is not resolved or chain mismatchNoPositionsToRedeem- If no winning positions to claim
Error Handling
Exceptions
The SDK defines these custom exceptions:
InvalidParamError
Invalid method parameters
OpenApiError
API communication or response errors
BalanceNotEnough
Insufficient token balance for operation
NoPositionsToRedeem
No winning positions to redeem
InsufficientGasBalance
Not enough BNB for gas fees
Example Error Handling
Last updated