Skip to main content

Python SDK

Installation

pip install poltrading-client

Quick Start

from poltrading import OutpostClient

client = OutpostClient(
base_url="https://outpost.poltrading.com",
hmac_key="your-hex-hmac-key", # Optional for read-only
)

# List markets
markets = client.list_markets()

# Get quote
quote = client.get_quote("0x0000...0001")

# Submit order
result = client.submit_order(
market_id="0x0000...0001",
payload=signed_order_bytes,
deadline=int(time.time()) + 300,
)

API Reference

OutpostClient(base_url, hmac_key=None)

Create a new client instance.

ParameterTypeRequiredDescription
base_urlstrYesOutpost endpoint URL
hmac_keystrNoHex-encoded HMAC key for feed ingestion
timeoutintNoRequest timeout in seconds (default: 30)
verify_sslboolNoVerify SSL certificates (default: True)

client.list_markets() -> list[dict]

Returns a list of active markets.

client.get_market(condition_id: str) -> dict

Returns market data for a specific condition ID.

client.get_quote(condition_id: str) -> dict

Returns quote/price data for a market.

client.submit_order(market_id: str, payload: bytes, deadline: int) -> dict

Submits a signed order. Returns the upstream response.

client.healthz() -> dict

Returns service health status.

client.sign_envelope(private_key: Ed25519PrivateKey, document: bytes) -> dict

Signs a document and returns a signed envelope.

client.ingest_market(envelope: dict) -> dict

Ingests market data (requires HMAC authentication).

HMAC Signing

import hashlib
import hmac
import os
import time

def sign_request(hmac_key: str, body: bytes) -> dict:
timestamp = str(int(time.time()))
nonce = os.urandom(16).hex()

mac = hmac.new(
bytes.fromhex(hmac_key),
f"{timestamp}.{nonce}.".encode() + body,
hashlib.sha256,
).hexdigest()

return {
"X-Outpost-Timestamp": timestamp,
"X-Outpost-Nonce": nonce,
"X-Outpost-Signature": f"v1={mac}",
}

Error Handling

from poltrading import OutpostClient, OutpostError, GeoBlockedError

try:
markets = client.list_markets()
except GeoBlockedError as e:
print(f"Access blocked in jurisdiction: {e.country}")
except OutpostError as e:
print(f"API error: {e.status_code} - {e.message}")