Skip to main content
The PolyhushClient class is the main entry point for all API operations.

Constructor

from polyhush import PolyhushClient

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

Parameters

api_key
string
Your Polyhush API key. If not provided, the client will look for the POLYHUSH_API_KEY environment variable.

Raises

  • ValueError - If no API key is provided and POLYHUSH_API_KEY environment variable is not set.

Class Attributes

Order Type Constants

client.GTC  # "GTC" - Good Till Cancelled
client.FOK  # "FOK" - Fill Or Kill
client.FAK  # "FAK" - Fill And Kill
ConstantValueDescription
GTC"GTC"Limit order that sits on the order book until filled or cancelled
FOK"FOK"Must be fully filled immediately or the entire order is cancelled
FAK"FAK"Fills what’s available immediately, cancels the rest (market order)

Methods

Account & Balance

get_balance()

Get your USDC balance and optional portfolio summary

Positions

get_positions()

Get your current positions with optional P&L details

Orders

buy()

Place a buy order

sell()

Place a sell order

cancel_orders()

Cancel orders

sync_orders()

Sync order status

Market Data

get_ticker()

Get current price ticker

Example Usage

from polyhush import PolyhushClient, PolyhushAPIError

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

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

# Place a limit order
try:
    result = client.buy(
        token_id="your-token-id",
        shares=10,
        price=0.55,
        order_type=client.GTC
    )
    print(f"Order placed: {result['orderID']}")
except PolyhushAPIError as e:
    print(f"Error: {e.message}")

# Get positions with P&L
positions = client.get_positions(detailed=True)
for pos in positions:
    print(f"{pos['market_question']}: {pos['unrealized_pnl_pct']:.1f}%")

Using Environment Variables

import os

# Set environment variable
os.environ['POLYHUSH_API_KEY'] = 'your-api-key'

# Client will use it automatically
client = PolyhushClient()
Or in your shell:
export POLYHUSH_API_KEY="your-api-key"
python your_script.py