def get_markets(
topic_type: Optional[TopicType] = None,
page: int = 1,
limit: int = 20,
status: Optional[TopicStatusFilter] = None
) -> Any
from opinion_clob_sdk.model import TopicType, TopicStatusFilter
# Get all active binary markets
response = client.get_markets(
topic_type=TopicType.BINARY,
status=TopicStatusFilter.ACTIVATED,
page=1,
limit=10
)
if response.errno == 0:
markets = response.result.list
for market in markets:
print(f"{market.market_id}: {market.market_title}")
def get_market(market_id: int, use_cache: bool = True) -> Any
order_ids = ["order_123", "order_456", "order_789"]
results = client.cancel_orders_batch(order_ids)
for i, result in enumerate(results):
if result['success']:
print(f"Cancelled: {order_ids[i]}")
else:
print(f"Failed: {order_ids[i]} - {result['error']}")
{
'total_orders': int, # Total orders found matching filter
'cancelled': int, # Successfully cancelled count
'failed': int, # Failed cancellation count
'results': List[dict] # Detailed results for each order
}
# Cancel all open orders across all markets
result = client.cancel_all_orders()
print(f"Cancelled {result['cancelled']} out of {result['total_orders']} orders")
# Cancel all BUY orders in market 123
result = client.cancel_all_orders(market_id=123, side=OrderSide.BUY)
print(f"Success: {result['cancelled']}, Failed: {result['failed']}")
# Cancel all orders in market 456 (both sides)
result = client.cancel_all_orders(market_id=456)
def get_my_orders(
market_id: int = 0,
status: str = "",
limit: int = 10,
page: int = 1
) -> Any
# Get all open orders
response = client.get_my_orders(status="open", limit=50)
if response.errno == 0:
orders = response.result.list
for order in orders:
print(f"Order {order.order_id}: {order.side} @ {order.price}")
def get_order_by_id(order_id: str) -> Any
response = client.get_order_by_id(order_id="order_123")
if response.errno == 0:
order = response.result.data
print(f"Status: {order.status}")
print(f"Filled: {order.filled_amount}/{order.maker_amount}")
def get_my_balances() -> Any
response = client.get_my_balances()
if response.errno == 0:
balance_data = response.result.data
balances = balance_data.balances # List of quote token balances
for balance in balances:
print(f"Token: {balance.quote_token}")
print(f" Available: {balance.available_balance}")
print(f" Frozen: {balance.frozen_balance}")
print(f" Total: {balance.total_balance}")
def get_my_positions(
market_id: int = 0,
page: int = 1,
limit: int = 10
) -> Any
response = client.get_my_positions(limit=50)
if response.errno == 0:
positions = response.result.list
for pos in positions:
print(f"Market {pos.market_id}: {pos.market_title}")
print(f" Shares: {pos.shares_owned} ({pos.outcome_side_enum})")
print(f" Value: {pos.current_value_in_quote_token}")
print(f" P&L: {pos.unrealized_pnl} ({pos.unrealized_pnl_percent}%)")
def get_my_trades(
market_id: Optional[int] = None,
page: int = 1,
limit: int = 10
) -> Any
response = client.get_my_trades(market_id=123, limit=20)
if response.errno == 0:
trades = response.result.list
for trade in trades:
print(f"{trade.created_at}: {trade.side} {trade.shares} shares @ {trade.price}")
print(f" Amount: {trade.amount}, Fee: {trade.fee}")
print(f" Status: {trade.status_enum}")