Skip to main content

Client Initialization

from polyhush import PolyhushClient

client = PolyhushClient(
    api_key="your-api-key",  # Or use POLYHUSH_API_KEY env var
    base_url="https://api.polyhush.com"  # Optional, defaults to production
)
api_key
string
required
Your Polyhush API key. Can also be set via POLYHUSH_API_KEY environment variable.
base_url
string
default:"https://api.polyhush.com"
API base URL. Override for testing or staging environments.

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)

API Methods by Category

Response Format

All methods return Python dictionaries or lists. Error responses raise PolyhushAPIError.

Success Response

result = client.get_balance()
# Returns:
# {
#     "balance": 1000.00,
#     "available_balance": 850.00,
#     "reserved_balance": 150.00,
#     "currency": "USDC"
# }

Error Response

from polyhush import PolyhushAPIError

try:
    result = client.buy(token_id="invalid", shares=10, price=0.5)
except PolyhushAPIError as e:
    print(e.message)       # "Token not found"
    print(e.status_code)   # 404
    print(e.response)      # {"detail": "Token not found"}

Common Patterns

Check Balance Before Trading

balance = client.get_balance()
if balance['available_balance'] >= 100:
    client.buy(token_id=token_id, shares=10, price=0.50)

Monitor Positions

positions = client.get_position_details()
for pos in positions:
    pnl = pos['unrealized_pnl']
    pnl_pct = pos['unrealized_pnl_pct']
    print(f"{pos['market_question']}: ${pnl:.2f} ({pnl_pct:.1f}%)")

Settle Winning Positions

pending = client.get_pending_settlements()
for market in pending:
    if market['can_settle'] and market['you_won']:
        result = client.settle_position(market['market_id'], market['token_id'])
        print(f"Claimed ${result['payout']:.2f}")