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="10")
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": "5"},
    {"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

See examples/03_websocket.py and PaxWSClient.

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.0.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.0.0
File Size Uploaded Provenance Actions
pax_api-3.0.0.tar.gz 26.2 kB Without provenance Details for pax_api-3.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 47.4 kB

Release files / pax_api-3.0.0.tar.gz

Download URL pax_api-3.0.0.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
17ffc61c8525968dfa72c08a08e9b63bd4b7342bd6bf5758c6a5293bb01fcbcd
BLAKE2b-256 checksum
How to use checksums
d1dc206ecfdac62220793cb228ac47fe4ace23313e25682a6c70bfc9f06fd3c4
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.0.0-py3-none-any.whl

Download URL pax_api-3.0.0-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38d8aaa5961549c9e9411dfb47ce07178b8d08f3a1aa290a0b698b36e4be579a
BLAKE2b-256 checksum
How to use checksums
336d019cbf4f32212a073d2773a8a3b449f8b6dc406d4f69d41b811bbb2d9025
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.0.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