pax-api 2.2.1__tar.gz → 2.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pax-api
3
- Version: 2.2.1
3
+ Version: 2.5.0
4
4
  Summary: Official Python SDK for the PredictAsiaX Trader Track API — Web3-native prediction markets
5
5
  Author-email: PredictAsiaX <support@predictasiax.com>
6
6
  License: MIT
@@ -9,7 +9,7 @@ Project-URL: Documentation, https://docs.predictasiax.com
9
9
  Project-URL: Repository, https://github.com/predictasiax/pax-python-sdk
10
10
  Project-URL: Issues, https://github.com/predictasiax/pax-python-sdk/issues
11
11
  Project-URL: Changelog, https://docs.predictasiax.com/changelog
12
- Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac,polymarket-compatible
12
+ Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -40,9 +40,9 @@ Dynamic: license-file
40
40
 
41
41
  # pax-api — Official Python SDK for PredictAsiaX
42
42
 
43
- Web3-native prediction market REST + WebSocket API client. Polymarket-compatible HMAC signing pattern.
43
+ Web3-native prediction market REST + WebSocket API client. HMAC-SHA256 signed-request auth for high-security trading bots.
44
44
 
45
- **Version 2.2.1** · MIT license · Python 3.8+
45
+ **Version 2.5.0** · MIT license · Python 3.8+
46
46
 
47
47
  - **Docs**: https://docs.predictasiax.com
48
48
  - **Verify**: https://docs.predictasiax.com/verify — public Merkle verifier over the operational ledger
@@ -85,7 +85,7 @@ Same production host either way (`api.predictasiax.com/v1`). Sandbox tier is enf
85
85
 
86
86
  ## Production trading (HMAC-signed)
87
87
 
88
- Machine-to-machine bots use HMAC signing (Polymarket-compatible 5-header pattern):
88
+ Machine-to-machine bots use HMAC-SHA256 signing (4 PAX_* headers per request):
89
89
 
90
90
  ```python
91
91
  from pax_api import PaxClient
@@ -1,8 +1,8 @@
1
1
  # pax-api — Official Python SDK for PredictAsiaX
2
2
 
3
- Web3-native prediction market REST + WebSocket API client. Polymarket-compatible HMAC signing pattern.
3
+ Web3-native prediction market REST + WebSocket API client. HMAC-SHA256 signed-request auth for high-security trading bots.
4
4
 
5
- **Version 2.2.1** · MIT license · Python 3.8+
5
+ **Version 2.5.0** · MIT license · Python 3.8+
6
6
 
7
7
  - **Docs**: https://docs.predictasiax.com
8
8
  - **Verify**: https://docs.predictasiax.com/verify — public Merkle verifier over the operational ledger
@@ -45,7 +45,7 @@ Same production host either way (`api.predictasiax.com/v1`). Sandbox tier is enf
45
45
 
46
46
  ## Production trading (HMAC-signed)
47
47
 
48
- Machine-to-machine bots use HMAC signing (Polymarket-compatible 5-header pattern):
48
+ Machine-to-machine bots use HMAC-SHA256 signing (4 PAX_* headers per request):
49
49
 
50
50
  ```python
51
51
  from pax_api import PaxClient
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pax-api"
7
- version = "2.2.1"
7
+ version = "2.5.0"
8
8
  description = "Official Python SDK for the PredictAsiaX Trader Track API — Web3-native prediction markets"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -12,7 +12,7 @@ license = { text = "MIT" }
12
12
  authors = [
13
13
  { name = "PredictAsiaX", email = "support@predictasiax.com" },
14
14
  ]
15
- keywords = ["predictasiax", "pax", "prediction-market", "trading-api", "web3", "hmac", "polymarket-compatible"]
15
+ keywords = ["predictasiax", "pax", "prediction-market", "trading-api", "web3", "hmac"]
16
16
  classifiers = [
17
17
  "Development Status :: 4 - Beta",
18
18
  "Intended Audience :: Developers",
@@ -26,7 +26,7 @@ caps), not a separate host. Same prefix, same URL — promote to production by
26
26
  upgrading the key's tier.
27
27
  """
28
28
 
29
- __version__ = "2.2.1"
29
+ __version__ = "2.4.0"
30
30
 
31
31
  from pax_api.client import PaxClient # noqa: E402
32
32
  from pax_api.ws_client import PaxWSClient # noqa: E402
@@ -1,14 +1,14 @@
1
- """HMAC signing helpers — Polymarket-compatible 5-header pattern.
1
+ """HMAC signing helpers — PAX canonical 5-header signed-request protocol.
2
2
 
3
3
  Signature construction:
4
4
  message = timestamp_ms + method_upper + path + body
5
5
  signature = base64(HMAC-SHA256(secret, message))
6
6
 
7
- Headers sent:
8
- POLY_ACCESS_KEY: <key_id>
9
- POLY_TIMESTAMP: <ms epoch>
10
- POLY_PASSPHRASE: <passphrase>
11
- POLY_SIGNATURE: <base64 sig>
7
+ Headers sent (canonical PAX_* form):
8
+ PAX_ACCESS_KEY: <key_id>
9
+ PAX_TIMESTAMP: <ms epoch>
10
+ PAX_PASSPHRASE: <passphrase>
11
+ PAX_SIGNATURE: <base64 sig>
12
12
 
13
13
  Server rejects with 401 INVALID_SIGNATURE if timestamp is more than
14
14
  ±30 seconds from server clock. Sync your machine via NTP.
@@ -32,7 +32,7 @@ def sign_request(
32
32
  passphrase: str,
33
33
  timestamp_ms: Optional[int] = None,
34
34
  ) -> Dict[str, str]:
35
- """Build the 5 POLY_* headers for an HMAC-signed request.
35
+ """Build the 4 PAX_* headers for an HMAC-signed request.
36
36
 
37
37
  Args:
38
38
  method: HTTP method (GET/POST/DELETE/etc.). Case-normalized to upper.
@@ -46,7 +46,7 @@ def sign_request(
46
46
  timestamp_ms: Override timestamp for testing. Defaults to now.
47
47
 
48
48
  Returns:
49
- Dict of 5 headers to merge into the request.
49
+ Dict of 4 headers to merge into the request.
50
50
  """
51
51
  ts = str(timestamp_ms if timestamp_ms is not None else int(time.time() * 1000))
52
52
  method_u = method.upper()
@@ -54,10 +54,10 @@ def sign_request(
54
54
  digest = hmac.new(secret.encode("utf-8"), message.encode("utf-8"), hashlib.sha256).digest()
55
55
  signature = base64.b64encode(digest).decode("ascii")
56
56
  return {
57
- "POLY_ACCESS_KEY": key_id,
58
- "POLY_TIMESTAMP": ts,
59
- "POLY_PASSPHRASE": passphrase,
60
- "POLY_SIGNATURE": signature,
57
+ "PAX_ACCESS_KEY": key_id,
58
+ "PAX_TIMESTAMP": ts,
59
+ "PAX_PASSPHRASE": passphrase,
60
+ "PAX_SIGNATURE": signature,
61
61
  }
62
62
 
63
63
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Auth modes (auto-detected):
4
4
  1. HMAC — pass ``api_key`` + ``secret`` + ``passphrase``. Every request
5
- signed with 5 POLY_* headers. Use for high-security trading bots.
5
+ signed with 4 PAX_* headers. Use for high-security trading bots.
6
6
  2. API Key — pass only ``api_key``. Sent via X-Api-Key header. Simple
7
7
  for read-only or low-risk M2M flows.
8
8
  3. Bearer — pass ``bearer_token``. Session-based. Browser/mobile only.
@@ -17,6 +17,8 @@ Environment:
17
17
  from __future__ import annotations
18
18
 
19
19
  import json as _json
20
+ import os
21
+ import secrets
20
22
  from typing import Any, Callable, Dict, List, Optional
21
23
 
22
24
  import requests
@@ -25,7 +27,7 @@ from pax_api.auth import sign_request
25
27
  from pax_api.errors import PaxError, build_error
26
28
  from pax_api.retry import run_with_retry
27
29
 
28
- __version__ = "2.2.1" # keep in sync with __init__.py + pyproject.toml
30
+ __version__ = "2.4.0" # keep in sync with __init__.py + pyproject.toml
29
31
 
30
32
 
31
33
  # v2: sandbox is a tier on the key, not a separate host. All env aliases
@@ -114,7 +116,8 @@ class PaxClient:
114
116
  return headers
115
117
 
116
118
  def _do_request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
117
- json_body: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
119
+ json_body: Optional[Dict[str, Any]] = None,
120
+ extra_headers: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
118
121
  url = self.base_url + path
119
122
  body = _json.dumps(json_body, separators=(",", ":"), sort_keys=False) if json_body is not None else ""
120
123
  # Reconstruct path+query for signing to match what server sees
@@ -126,6 +129,11 @@ class PaxClient:
126
129
  if qs:
127
130
  path_for_sig = f"{path}?{qs}"
128
131
  headers = self._headers_for(method, path_for_sig, body)
132
+ if extra_headers:
133
+ headers.update(extra_headers)
134
+ # Auto-inject Idempotency-Key for POST/PUT/PATCH/DELETE if not set by caller
135
+ if method.upper() in ("POST", "PUT", "PATCH", "DELETE") and "Idempotency-Key" not in headers:
136
+ headers["Idempotency-Key"] = "pax-sdk-" + secrets.token_hex(12)
129
137
 
130
138
  resp = self._session.request(
131
139
  method=method,
@@ -152,9 +160,11 @@ class PaxClient:
152
160
  return payload
153
161
 
154
162
  def _request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
155
- json_body: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
163
+ json_body: Optional[Dict[str, Any]] = None,
164
+ extra_headers: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
156
165
  return run_with_retry(
157
- lambda: self._do_request(method, path, params=params, json_body=json_body),
166
+ lambda: self._do_request(method, path, params=params, json_body=json_body,
167
+ extra_headers=extra_headers),
158
168
  max_attempts=self.max_retries,
159
169
  )
160
170
 
@@ -434,6 +444,41 @@ class PaxClient:
434
444
  """GET /v1/apply/{code} — check application review status."""
435
445
  return self._request("GET", f"/v1/apply/{application_code}")
436
446
 
447
+ # ── Revenue / settle (v2.4+) ─────────────────────────────────────────────
448
+ def settle_self(self, *, address: str, asset: str = "USDT",
449
+ network: str = "polygon", min_amount: float = 0) -> Dict[str, Any]:
450
+ """POST /v1/builders/me/settle — builder self-serve claim of accrued
451
+ execution_builder + acquisition_builder fees. Creates a withdrawal_state
452
+ row; existing pipeline delivers USDT to the provided address.
453
+ Requires api-key auth (uses the caller's user_id as builder identity).
454
+ """
455
+ return self._request("POST", "/v1/builders/me/settle",
456
+ json_body={"address": address, "asset": asset,
457
+ "network": network, "min_amount": min_amount})
458
+
459
+ def admin_settle_builder(self, user_id: str, *, address: str, asset: str = "USDT",
460
+ network: str = "polygon", min_amount: float = 0,
461
+ admin_key: Optional[str] = None) -> Dict[str, Any]:
462
+ """POST /v1/admin/builders/{user_id}/settle — admin claim of a specific
463
+ builder's earnings. Requires X-Admin-Key (pass via admin_key arg or
464
+ env ADMIN_HEALTH_TOKEN)."""
465
+ headers = {"X-Admin-Key": admin_key or os.environ.get("ADMIN_HEALTH_TOKEN", "")}
466
+ return self._request("POST", f"/v1/admin/builders/{user_id}/settle",
467
+ json_body={"address": address, "asset": asset,
468
+ "network": network, "min_amount": min_amount},
469
+ extra_headers=headers)
470
+
471
+ def admin_settle_creator(self, user_id: str, *, address: str, asset: str = "USDT",
472
+ network: str = "polygon", min_amount: float = 0,
473
+ admin_key: Optional[str] = None) -> Dict[str, Any]:
474
+ """POST /v1/admin/creators/{user_id}/settle — admin claim of a specific
475
+ market creator's FEE_MARKET_CREATOR earnings. Requires X-Admin-Key."""
476
+ headers = {"X-Admin-Key": admin_key or os.environ.get("ADMIN_HEALTH_TOKEN", "")}
477
+ return self._request("POST", f"/v1/admin/creators/{user_id}/settle",
478
+ json_body={"address": address, "asset": asset,
479
+ "network": network, "min_amount": min_amount},
480
+ extra_headers=headers)
481
+
437
482
  # ── Helpers ──────────────────────────────────────────────────────────────
438
483
  def close(self) -> None:
439
484
  self._session.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pax-api
3
- Version: 2.2.1
3
+ Version: 2.5.0
4
4
  Summary: Official Python SDK for the PredictAsiaX Trader Track API — Web3-native prediction markets
5
5
  Author-email: PredictAsiaX <support@predictasiax.com>
6
6
  License: MIT
@@ -9,7 +9,7 @@ Project-URL: Documentation, https://docs.predictasiax.com
9
9
  Project-URL: Repository, https://github.com/predictasiax/pax-python-sdk
10
10
  Project-URL: Issues, https://github.com/predictasiax/pax-python-sdk/issues
11
11
  Project-URL: Changelog, https://docs.predictasiax.com/changelog
12
- Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac,polymarket-compatible
12
+ Keywords: predictasiax,pax,prediction-market,trading-api,web3,hmac
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -40,9 +40,9 @@ Dynamic: license-file
40
40
 
41
41
  # pax-api — Official Python SDK for PredictAsiaX
42
42
 
43
- Web3-native prediction market REST + WebSocket API client. Polymarket-compatible HMAC signing pattern.
43
+ Web3-native prediction market REST + WebSocket API client. HMAC-SHA256 signed-request auth for high-security trading bots.
44
44
 
45
- **Version 2.2.1** · MIT license · Python 3.8+
45
+ **Version 2.5.0** · MIT license · Python 3.8+
46
46
 
47
47
  - **Docs**: https://docs.predictasiax.com
48
48
  - **Verify**: https://docs.predictasiax.com/verify — public Merkle verifier over the operational ledger
@@ -85,7 +85,7 @@ Same production host either way (`api.predictasiax.com/v1`). Sandbox tier is enf
85
85
 
86
86
  ## Production trading (HMAC-signed)
87
87
 
88
- Machine-to-machine bots use HMAC signing (Polymarket-compatible 5-header pattern):
88
+ Machine-to-machine bots use HMAC-SHA256 signing (4 PAX_* headers per request):
89
89
 
90
90
  ```python
91
91
  from pax_api import PaxClient
@@ -1,4 +1,4 @@
1
- """Unit tests for HMAC signing helpers — verify matches Polymarket-compatible spec."""
1
+ """Unit tests for HMAC signing helpers — verify PAX canonical 5-header protocol."""
2
2
 
3
3
  import base64
4
4
  import hashlib
@@ -21,28 +21,28 @@ def test_signature_matches_reference() -> None:
21
21
  hmac.new(secret.encode(), msg.encode(), hashlib.sha256).digest()
22
22
  ).decode()
23
23
  headers = sign_request("GET", "/v1/health", "", "sk_live_ABC", secret, "pass", timestamp_ms=ts)
24
- assert headers["POLY_ACCESS_KEY"] == "sk_live_ABC"
25
- assert headers["POLY_TIMESTAMP"] == str(ts)
26
- assert headers["POLY_PASSPHRASE"] == "pass"
27
- assert headers["POLY_SIGNATURE"] == expected
24
+ assert headers["PAX_ACCESS_KEY"] == "sk_live_ABC"
25
+ assert headers["PAX_TIMESTAMP"] == str(ts)
26
+ assert headers["PAX_PASSPHRASE"] == "pass"
27
+ assert headers["PAX_SIGNATURE"] == expected
28
28
 
29
29
 
30
30
  def test_signature_differs_when_body_changes() -> None:
31
31
  secret = "s" * 32
32
32
  h1 = sign_request("POST", "/v1/orders", '{"size":"1"}', "k", secret, "p", timestamp_ms=1)
33
33
  h2 = sign_request("POST", "/v1/orders", '{"size":"2"}', "k", secret, "p", timestamp_ms=1)
34
- assert h1["POLY_SIGNATURE"] != h2["POLY_SIGNATURE"]
34
+ assert h1["PAX_SIGNATURE"] != h2["PAX_SIGNATURE"]
35
35
 
36
36
 
37
37
  def test_signature_differs_when_timestamp_changes() -> None:
38
38
  secret = "s" * 32
39
39
  h1 = sign_request("GET", "/v1/health", "", "k", secret, "p", timestamp_ms=1)
40
40
  h2 = sign_request("GET", "/v1/health", "", "k", secret, "p", timestamp_ms=2)
41
- assert h1["POLY_SIGNATURE"] != h2["POLY_SIGNATURE"]
41
+ assert h1["PAX_SIGNATURE"] != h2["PAX_SIGNATURE"]
42
42
 
43
43
 
44
44
  def test_method_is_upcased() -> None:
45
45
  secret = "s" * 32
46
46
  h1 = sign_request("get", "/v1/health", "", "k", secret, "p", timestamp_ms=1)
47
47
  h2 = sign_request("GET", "/v1/health", "", "k", secret, "p", timestamp_ms=1)
48
- assert h1["POLY_SIGNATURE"] == h2["POLY_SIGNATURE"]
48
+ assert h1["PAX_SIGNATURE"] == h2["PAX_SIGNATURE"]
@@ -43,10 +43,10 @@ def test_hmac_headers_sent_when_secret() -> None:
43
43
  responses.add(responses.GET, f"{PROD_BASE}/v1/health", json={"ok": True}, status=200)
44
44
  c.get_health()
45
45
  req = responses.calls[0].request
46
- assert req.headers.get("POLY_ACCESS_KEY") == "sk_live_ABC"
47
- assert req.headers.get("POLY_PASSPHRASE") == "p"
48
- assert req.headers.get("POLY_TIMESTAMP")
49
- assert req.headers.get("POLY_SIGNATURE")
46
+ assert req.headers.get("PAX_ACCESS_KEY") == "sk_live_ABC"
47
+ assert req.headers.get("PAX_PASSPHRASE") == "p"
48
+ assert req.headers.get("PAX_TIMESTAMP")
49
+ assert req.headers.get("PAX_SIGNATURE")
50
50
 
51
51
 
52
52
  @responses.activate
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes