Skip to content

Add AsyncClobClient and examples to README.md#224

Open
BonifacioCalindoro wants to merge 16 commits intoPolymarket:mainfrom
BonifacioCalindoro:main
Open

Add AsyncClobClient and examples to README.md#224
BonifacioCalindoro wants to merge 16 commits intoPolymarket:mainfrom
BonifacioCalindoro:main

Conversation

@BonifacioCalindoro
Copy link

@BonifacioCalindoro BonifacioCalindoro commented Dec 26, 2025

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.

  • New AsyncClobClient with feature parity to ClobClient, built on httpx.AsyncClient (py_clob_client/async_client.py) and new async HTTP helpers
  • New AsyncRfqClient with async request/quote/accept/approve flows (py_clob_client/rfq/async_rfq_client.py)
  • Public exports updated to include AsyncClobClient and AsyncRfqClient (py_clob_client/__init__.py, py_clob_client/rfq/__init__.py)
  • README expanded with parallel sync and async examples for all major operations
  • Package/version updates: bump to 0.34.2, add httpx[http2] and related deps in setup.py
  • CI/workflows: no functional changes (formatting and ensuring PyPI publish step)

Written by Cursor Bugbot for commit 8be0ebb. This will update automatically on new commits. Configure here.

BonifacioCalindoro and others added 12 commits December 23, 2025 02:37
Updated description to indicate async support and work in progress.
This reverts commit 106bad9, reversing
changes made to d164a80.
…olymarket CLOB, enhancing usage examples and documentation throughout.
…e pagination handling in query parameter functions.
…d for pagination even when no other parameters are present, improving URL construction logic.
Remove unnecessary blank line in GitHub Actions workflow file for imp…
BonifacioCalindoro and others added 4 commits December 26, 2025 14:46
…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,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Fix in Cursor Fix in Web

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikr. But i wanted to keep this as similar to the sync version, so consider it a feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant