From 28f7dbd0b26ef188df271c5e6ea32d8e2426e70a Mon Sep 17 00:00:00 2001 From: ibrahim yildiz Date: Thu, 26 Nov 2026 02:02:35 -0300 Subject: [PATCH] feat(python): type get_auth_nonce and login_with_signature responses Add AuthNonceResponse and AuthLoginResponse TypedDicts mirroring the TypeScript SDK, export them from the package root, and use them as the return types. Point the generator's TYPE_MAP at them so a regeneration keeps the annotations. --- sdks/python/pmxt/__init__.py | 4 ++++ sdks/python/pmxt/client.py | 6 ++++-- sdks/python/pmxt/models.py | 21 +++++++++++++++++++ .../python/scripts/generate-client-methods.js | 4 ++-- sdks/python/tests/test_public_exports.py | 14 +++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/sdks/python/pmxt/__init__.py b/sdks/python/pmxt/__init__.py index 7c792ec3..c6289855 100644 --- a/sdks/python/pmxt/__init__.py +++ b/sdks/python/pmxt/__init__.py @@ -58,6 +58,8 @@ BuiltOrder, CreateOrderParams, TxPayload, + AuthNonceResponse, + AuthLoginResponse, Position, Balance, MarketFilterCriteria, @@ -243,6 +245,8 @@ def restart_server() -> None: "BuiltOrder", "CreateOrderParams", "TxPayload", + "AuthNonceResponse", + "AuthLoginResponse", "ExecutionPriceResult", "Position", "Balance", diff --git a/sdks/python/pmxt/client.py b/sdks/python/pmxt/client.py index 96e1e56d..f83bc5ac 100644 --- a/sdks/python/pmxt/client.py +++ b/sdks/python/pmxt/client.py @@ -42,6 +42,8 @@ Order, BuiltOrder, Position, + AuthNonceResponse, + AuthLoginResponse, Balance, ExecutionPriceResult, MarketFilterCriteria, @@ -1306,7 +1308,7 @@ def load_markets(self, reload: bool = False) -> Dict[str, UnifiedMarket]: # BEGIN GENERATED METHODS - def get_auth_nonce(self, wallet_address: str) -> Dict[str, Any]: + def get_auth_nonce(self, wallet_address: str) -> AuthNonceResponse: try: args = [] args.append(wallet_address) @@ -1326,7 +1328,7 @@ def get_auth_nonce(self, wallet_address: str) -> Dict[str, Any]: except ApiException as e: raise self._parse_api_exception(e) from None - def login_with_signature(self, wallet_address: str, signature: str, nonce: str) -> Dict[str, Any]: + def login_with_signature(self, wallet_address: str, signature: str, nonce: str) -> AuthLoginResponse: try: args = [] args.append(wallet_address) diff --git a/sdks/python/pmxt/models.py b/sdks/python/pmxt/models.py index 96ad499c..c1cf3904 100644 --- a/sdks/python/pmxt/models.py +++ b/sdks/python/pmxt/models.py @@ -545,6 +545,27 @@ class TxPayload(TypedDict): value: str chainId: int + +class _AuthNonceRequired(TypedDict): + nonce: str + messageToSign: str + + +class AuthNonceResponse(_AuthNonceRequired, total=False): + """Challenge returned by ``get_auth_nonce`` for the Web3 login flow.""" + expiresAt: int + + +class _AuthLoginRequired(TypedDict): + apiKey: str + apiSecret: str + + +class AuthLoginResponse(_AuthLoginRequired, total=False): + """Credentials returned by ``login_with_signature``.""" + passphrase: str + expiresAt: int + @dataclass class Position: """A current position in a market. diff --git a/sdks/python/scripts/generate-client-methods.js b/sdks/python/scripts/generate-client-methods.js index 7688cf22..0c8e9368 100644 --- a/sdks/python/scripts/generate-client-methods.js +++ b/sdks/python/scripts/generate-client-methods.js @@ -102,8 +102,8 @@ const TYPE_MAP = { PaginatedMarketsResult: { pyType: 'PaginatedMarketsResult', converter: null, pattern: 'paginatedMarkets' }, PaginatedEventsResult: { pyType: 'PaginatedEventsResult', converter: null, pattern: 'paginatedEvents' }, - AuthNonceResponse: { pyType: 'Dict[str, Any]', converter: null, pattern: 'raw' }, - AuthLoginResponse: { pyType: 'Dict[str, Any]', converter: null, pattern: 'raw' }, + AuthNonceResponse: { pyType: 'AuthNonceResponse', converter: null, pattern: 'raw' }, + AuthLoginResponse: { pyType: 'AuthLoginResponse', converter: null, pattern: 'raw' }, }; // Parameter names that represent outcome IDs and should accept MarketOutcome. diff --git a/sdks/python/tests/test_public_exports.py b/sdks/python/tests/test_public_exports.py index 2fdb3236..b2c209bd 100644 --- a/sdks/python/tests/test_public_exports.py +++ b/sdks/python/tests/test_public_exports.py @@ -267,3 +267,17 @@ def fake_call_method(method_name, params=None): assert by_id.id == "12345" assert isinstance(by_slug, UnifiedEvent) assert by_slug.slug == "example-event" + + +def test_auth_response_types_are_public_exports_and_used_by_client(): + import pmxt + from pmxt.client import Exchange + from typing import get_type_hints + + assert pmxt.AuthNonceResponse.__required_keys__ == {"nonce", "messageToSign"} + assert pmxt.AuthNonceResponse.__optional_keys__ == {"expiresAt"} + assert pmxt.AuthLoginResponse.__required_keys__ == {"apiKey", "apiSecret"} + assert pmxt.AuthLoginResponse.__optional_keys__ == {"passphrase", "expiresAt"} + + assert get_type_hints(Exchange.get_auth_nonce)["return"] is pmxt.AuthNonceResponse + assert get_type_hints(Exchange.login_with_signature)["return"] is pmxt.AuthLoginResponse