Skip to main content

Installation

Install the Polyhush SDK from PyPI:
pip install polyhush

Initialize the Client

1

Get your API key

Log in to your Polyhush Dashboard and navigate to Settings to generate an API key.
2

Initialize the client

Create a new PolyhushClient instance with your API key:
from polyhush import PolyhushClient

client = PolyhushClient(api_key="your-api-key")
You can also set the POLYHUSH_API_KEY environment variable and initialize without arguments:
client = PolyhushClient()  # Uses POLYHUSH_API_KEY env var
3

Verify connection

Test your connection by fetching your balance:
balance = client.get_balance()
print(f"Balance: ${balance['balance']:.2f}")
print(f"Available: ${balance['available_balance']:.2f}")

Configuration Options

The client accepts the following parameters:
api_key
string
Your Polyhush API key. Can also be set via the POLYHUSH_API_KEY environment variable.
# Full configuration example
client = PolyhushClient(
    api_key="your-api-key"
)

Your First Trade

Let’s place your first order. First, you’ll need to find a market and get its token ID from Polymarket’s Gamma API:
import json
import requests
from polyhush import PolyhushClient

GAMMA_API_URL = "https://gamma-api.polymarket.com"

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

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

# 2. Fetch market data from Polymarket's Gamma API
#    You can search by slug or browse markets at https://polymarket.com
market_slug = "will-bitcoin-hit-100k-in-2025"  # Example market slug
response = requests.get(f"{GAMMA_API_URL}/markets/slug/{market_slug}", timeout=10)

if response.status_code != 200:
    print(f"Market not found: {market_slug}")
    exit(1)

# 3. Parse the market data to get token IDs and current prices
market = response.json()
print(f"Market: {market.get('question')}")

# Token IDs may be JSON strings or lists depending on the response
token_ids = json.loads(market.get("clobTokenIds", "[]")) if isinstance(market.get("clobTokenIds"), str) else market.get("clobTokenIds", [])
prices = json.loads(market.get("outcomePrices", "[]")) if isinstance(market.get("outcomePrices"), str) else market.get("outcomePrices", [])
outcomes = json.loads(market.get("outcomes", "[]")) if isinstance(market.get("outcomes"), str) else market.get("outcomes", [])

# Display available outcomes
for i, outcome in enumerate(outcomes):
    print(f"  {outcome}: token_id={token_ids[i][:20]}... @ ${float(prices[i]):.2f}")

# 4. Place a limit buy order on the YES outcome (index 0)
yes_token_id = token_ids[0]
yes_price = round(float(prices[0]), 2)

result = client.buy(
    token_id=yes_token_id,
    shares=10,              # Number of shares
    price=yes_price         # Price per share
)

print(f"Order ID: {result['orderID']}")
print(f"Status: {result['status']}")

# 5. Check your positions
positions = client.get_positions()
for pos in positions:
    print(f"Position: {pos['size']} shares @ ${pos['average_price']:.2f}")
You can also search for markets using the Gamma API’s search endpoint:
# Search for markets by keyword
response = requests.get(f"{GAMMA_API_URL}/markets?_limit=5&active=true&closed=false")
markets = response.json()
for m in markets:
    print(f"{m['question']}: {m['slug']}")

Next Steps

Order Types

Learn about GTC, FOK, and FAK order types

Trading Examples

See more trading examples

API Reference

Explore the full API

Error Handling

Handle errors gracefully