Add AsyncClobClient and examples to README.md#224
Add AsyncClobClient and examples to README.md#224BonifacioCalindoro wants to merge 16 commits intoPolymarket:mainfrom
Conversation
Updated description to indicate async support and work in progress.
…olymarket CLOB, enhancing usage examples and documentation throughout.
…e pagination handling in query parameter functions.
…uded when no other parameters are provided
Feat/async client
…d for pagination even when no other parameters are present, improving URL construction logic.
Update to latest changes
…roved readability.
Remove unnecessary blank line in GitHub Actions workflow file for imp…
…on and method calls for asynchronous handling.
Refactor AsyncRfqClient to use AsyncClobClient, updating initializati…
…the create_order method, improving responsiveness in order handling.
Update AsyncRfqClient to use asynchronous order creation by awaiting …
| url=endpoint, | ||
| headers=headers, | ||
| json=data, | ||
| ) |
There was a problem hiding this comment.
New HTTP client created for every async request
The async HTTP helper assigns the httpx.AsyncClient class itself to _http_client (line 19), then instantiates a new client for every single request (lines 42, 50). This contrasts with the sync version in helpers.py which creates a single persistent httpx.Client(http2=True) instance that's reused across all requests. The async pattern loses all connection pooling and HTTP/2 multiplexing benefits, requiring new TLS handshakes and TCP connections per API call. For users making multiple API calls, this causes significant latency overhead and resource waste.
There was a problem hiding this comment.
If you can think of a way of doing this that doesn't cause race conditions and doesn't abstract to infinity, i'm all ears
| request_args = RequestArgs(method="GET", request_path=GET_BALANCE_ALLOWANCE) | ||
| headers = create_level_2_headers(self.signer, self.creds, request_args) | ||
| if params.signature_type == -1: | ||
| params.signature_type = self.builder.sig_type |
There was a problem hiding this comment.
Missing null check before accessing params attribute
The get_balance_allowance and update_balance_allowance methods declare params: BalanceAllowanceParams = None as optional, but immediately access params.signature_type without checking if params is None first. Calling either method without the params argument will raise an AttributeError. While this mirrors existing behavior in the sync client, it's still a crash bug in the new async code.
Additional Locations (1)
There was a problem hiding this comment.
Ikr. But i wanted to keep this as similar to the sync version, so consider it a feature
Rewrote the clob client and rfq client into using httpx.AsyncClient with async/await fashion, enabling a new AsyncClobClient.
It has the same exact features as the ClobClient, it just works asynchronously.
Note
Adds first-class async support across the client and RFQ APIs.
AsyncClobClientwith feature parity toClobClient, built onhttpx.AsyncClient(py_clob_client/async_client.py) and new async HTTP helpersAsyncRfqClientwith async request/quote/accept/approve flows (py_clob_client/rfq/async_rfq_client.py)AsyncClobClientandAsyncRfqClient(py_clob_client/__init__.py,py_clob_client/rfq/__init__.py)0.34.2, addhttpx[http2]and related deps insetup.pyWritten by Cursor Bugbot for commit 8be0ebb. This will update automatically on new commits. Configure here.