Skip to main content
The Polyhush Python SDK provides a simple, Pythonic interface for trading on prediction markets. This reference documents all available classes, methods, and constants.

Installation

pip install polyhush

Quick Start

from polyhush import PolyhushClient

client = PolyhushClient(api_key="your-api-key")

# Check balance
balance = client.get_balance()
print(f"Available: ${balance['available_balance']:.2f}")

# Place an order
result = client.buy(token_id="...", shares=10, price=0.55)
print(f"Order: {result['orderID']}")

Classes

PolyhushClient

Main client class for all API operations

PolyhushAPIError

Exception class for API errors

Method Categories

Account & Balance

MethodDescription
get_balance()Get USDC balance and portfolio summary

Positions

MethodDescription
get_positions()Get current positions with optional P&L

Orders

MethodDescription
buy()Place a buy order (limit or market)
sell()Place a sell order (limit or market)
cancel_orders()Cancel one or all open orders
sync_orders()Sync order status from Polymarket

Market Data

MethodDescription
get_ticker()Get current price ticker for a token

Order Type Constants

The client provides constants for order types:
client.GTC  # "GTC" - Good Till Cancelled (limit order)
client.FOK  # "FOK" - Fill Or Kill (must fully fill or cancel)
client.FAK  # "FAK" - Fill And Kill (market order)

Error Handling

All methods raise PolyhushAPIError on failure:
from polyhush import PolyhushClient, PolyhushAPIError

try:
    result = client.buy(token_id="...", shares=10, price=0.5)
except PolyhushAPIError as e:
    print(f"Error: {e.message}")
    print(f"Status: {e.status_code}")
    print(f"Details: {e.response}")

Environment Variables

VariableDescription
POLYHUSH_API_KEYDefault API key (used if not passed to constructor)
# Using environment variable
import os
os.environ['POLYHUSH_API_KEY'] = 'your-api-key'

client = PolyhushClient()  # Uses env var automatically

Type Hints

The SDK includes full type hints for IDE support:
from polyhush import PolyhushClient
from typing import Dict, List

client = PolyhushClient(api_key="...")

balance: Dict = client.get_balance()
positions: List[Dict] = client.get_positions()

Thread Safety

The PolyhushClient is not thread-safe. For multi-threaded applications, create a separate client instance per thread:
import threading

def worker():
    client = PolyhushClient()  # Each thread gets its own client
    # ... do work

threads = [threading.Thread(target=worker) for _ in range(5)]
for t in threads:
    t.start()