Skip to main content

pax-api — Official Python SDK for PredictAsiaX

REST + WebSocket client for the PredictAsiaX API gateway (https://api.predictasiax.com).

Version 3.0.0 · MIT license · Python 3.8+ · Changelog

Install

pip install --upgrade pax-api

Quickstart

from pax_api import PaxClient

# Public endpoints need no key
pax = PaxClient()
print(pax.audit_status()["data"]["events"]["total"])
print(pax.get_orderbook("hadjar-f1-2026"))

# Mint a sandbox key (the api_key is shown once — store it)
key = pax.mint_sandbox_key(org_name="my-app")["data"]["api_key"]

pax = PaxClient(api_key=key)          # sent as Authorization: Bearer sk_live_...
print(pax.get_balance())
print(pax.get_positions())

Credentials

Mode Constructor Sent on the wire
API key PaxClient(api_key="sk_live_...") Authorization: Bearer sk_live_...
HMAC signing PaxClient(api_key="sk_live_...", key_id="api_...") PAX-ADDRESS, PAX-TIMESTAMP, PAX-NONCE, PAX-SIGNATURE (no key)
Session / OAuth PaxClient(bearer_token="...") Authorization: Bearer ...

HMAC signature (what the gateway verifies):

canonical = timestamp + "\n" + nonce + "\n" + METHOD + "\n" + path_with_query + "\n" + body
signature = base64(HMAC-SHA256(key = the full sk_live_ key, msg = canonical))

timestamp is Unix seconds (accepted window ±300 s), nonce is single-use, path_with_query includes /v1 and the query string. The SDK signs every attempt afresh, retries included. pax_api.auth.sign_request is exported if you need the headers yourself.

Trading

pax = PaxClient(api_key="sk_live_...", key_id="api_...")

order = pax.place_order(market_id="hadjar-f1-2026", side="yes", price="0.05", size="20")
pax.get_orders(status="open")
pax.cancel_order(order_id)
pax.cancel_all_orders(market_id="hadjar-f1-2026")

pax.place_orders_batch([
    {"market_id": "hadjar-f1-2026", "side": "yes", "price": "0.04", "size": "25"},
    {"market_id": "hadjar-f1-2026", "side": "no",  "price": "0.90", "size": "5"},
])

place_order is a limit BUY of the chosen outcome (side="yes" or "no"), price 0.01–0.99.

Fee estimate

pax.estimate_fees(size="10", price="0.55", market_id="hadjar-f1-2026", side="yes")

Audit log verification

Every platform event is hash-chained and batched into SHA-256 Merkle trees. The SDK checks everything locally:

from pax_api import PaxClient, verify_event, verify_merkle_proof, expected_proof_length

pax = PaxClient()
result = pax.verify_audit_event(1866215)
print(result["ok"], result["checks"])
# checks: event_hash (sha256(prev_event_hash + canonical)), same_event,
#         seq_in_batch, server_length_agrees, merkle (incl. proof length)

# Low level
proof = pax.audit_proof(1866215)["data"]
n = proof["batch"]["last_seq"] - proof["batch"]["first_seq"] + 1
verify_merkle_proof(proof["event_hash"], proof["batch"]["merkle_root"],
                    proof["merkle_proof"], expected_proof_length(n))

verify_merkle_proof requires expected_length: a proof with any other number of siblings is rejected, so an interior node cannot pass as a leaf. A root read from the same API proves internal consistency; for an independent check pass the anchored root (pax.audit_anchor(batch_num)) as root=.

WebSocket streams

from pax_api import PaxWSClient

ws = PaxWSClient(api_key="sk_live_...", subscribe_on_connect=["fast_tick"])
ws.on("user_orders_update", lambda evt: print("order", evt))   # your account's order events
ws.run_forever()

Before every connect and reconnect the client calls POST /v1/ws/token (scope orders:read) and sends the single-use token in AUTH; the API key itself is never sent on the socket. With an HMAC key or OAuth token, pass token_provider=lambda: pax.create_ws_token()["data"]["token"]. See examples/03_websocket.py.

Error handling

Every response error becomes a typed exception:

from pax_api import (
    PaxClient,
    PaxRateLimitError,
    PaxReadOnlyModeError,
    PaxValidationError,
    PaxWrongEnvKeyError,
    PaxError,           # base class — catch-all
)

try:
    pax.place_order(...)
except PaxRateLimitError as e:
    time.sleep(e.retry_after or 5)
except PaxValidationError as e:
    print(f"Bad request: {e.details}")
except PaxReadOnlyModeError:
    print("Trading paused by ops")
except PaxWrongEnvKeyError:
    print("Wrong environment key")
except PaxError as e:
    print(f"[{e.code}] {e.message} (request_id={e.request_id})")

Automatic retry

Built-in exponential backoff on 429, 500, 502, 504. Retry-After header respected on rate limits. Each mutating call gets one Idempotency-Key, reused by every retry of that call; place_order also fixes its client_order_id before the first attempt, so a retry can never place a second order.

pax = PaxClient(api_key=key, max_retries=5)
# max_retries=1 disables retries

Base URL

The gateway is https://api.predictasiax.com; methods add the /v1/... path themselves. A base_url ending in /v1 is accepted and normalised. Sandbox and production share the host: sandbox is a tier on the key (tier=self_serve), with per-order and per-day caps.

Applications (progressive trust)

Move from sandbox → trade-capped → trade-full by submitting an application:

res = pax.apply(track="self_serve", org="my-org", email="team@my-org.io")
print(res["data"]["application_code"])   # save this

status = pax.get_application(res["data"]["application_code"])
print(status["data"]["status"])           # submitted → in_review → approved / declined

Development

git clone https://github.com/predictasiax/pax-python-sdk
cd pax-python-sdk
pip install -e ".[dev]"
pytest                 # run all tests
ruff check src tests   # lint
mypy src               # type-check

License

MIT — see LICENSE.

Metadata

Release files for pax-api 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pax-api 3.1.0
File Size Uploaded Provenance Actions
pax_api-3.1.0.tar.gz 30.1 kB Without provenance Details for pax_api-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pax-api 3.1.0
File Interpreter ABI Platform Actions
pax_api-3.1.0-py3-none-any.whl Python 3 none any Details for pax_api-3.1.0-py3-none-any.whl

Total release size: 53.9 kB

Release files / pax_api-3.1.0.tar.gz

Download URL pax_api-3.1.0.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3ffad109101941394938a832a36b49ea1cfd0c6429bd441b5bd3d5ddd419b9e8
BLAKE2b-256 checksum
How to use checksums
5e47f5c01b3fc26612081eeedb8ed9166ea50a54e020b4ca8f70b6f8215e6713
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / pax_api-3.1.0-py3-none-any.whl

Download URL pax_api-3.1.0-py3-none-any.whl
Size 23.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc4f0350c17969c369ecf59f7d1b065a9be716e10d4c6dcd9ade8c6c46f1e6d1
BLAKE2b-256 checksum
How to use checksums
33e4012c967ace73d2a264b1d51d082e5552d0f04986c84f32a3042c33d6f855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for pax-api 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page