Summary
Please expose a supported, opt-in way to observe HTTP response metadata from SecureClient and AsyncSecureClient requests without changing their typed return values.
This is needed to monitor the new per-signer CLOB trading token buckets. Covered order and cancellation responses can include:
Poly-RateLimit-Remaining
Poly-RateLimit-Reset
Poly-RateLimit-Tier
Poly-RateLimit-Warning
Retry-After on HTTP 429
Documentation: https://docs.polymarket.com/api-reference/trading-rate-limits
Current behavior
The transport receives an httpx.Response, but public client methods parse and return the response body as typed models. SecureClient.create() and AsyncSecureClient.create() do not expose a public response hook or transport configuration, so applications cannot observe headers from successful requests.
The internal TransportOptions.event_hooks facility is not reachable through the public client constructors. Reaching through private client context or globally monkey-patching HTTPX would be fragile, especially in concurrent trading applications.
Issue #182 is related for rejected responses and Retry-After, but this request also covers successful responses and general response metadata observation.
Requested API
One possible design would be an optional response callback accepted by both client factories:
def observe_response(metadata: ResponseMetadata) -> None:
remaining = metadata.headers.get("Poly-RateLimit-Remaining")
client = SecureClient.create(
private_key=private_key,
wallet=wallet,
credentials=credentials,
response_hook=observe_response,
)
The exact API shape is flexible. The important properties would be:
- Supported on both synchronous and asynchronous clients.
- Invoked for successful and unsuccessful HTTP responses, before an exception discards response metadata.
- Provides at least method/path, status code, and response headers.
- Does not expose authentication request headers or request bodies by default.
- Preserves all existing typed return values and behavior when no hook is supplied.
- Applies to all transports owned by the client, or clearly identifies which service produced the response.
Exposing a public TransportOptions argument could also solve this, provided it is supported and stable.
Environment
- Package:
polymarket-client==0.2.0
- Clients:
SecureClient and AsyncSecureClient
- Use case: production monitoring of per-signer CLOB order and cancellation rate limits
Summary
Please expose a supported, opt-in way to observe HTTP response metadata from
SecureClientandAsyncSecureClientrequests without changing their typed return values.This is needed to monitor the new per-signer CLOB trading token buckets. Covered order and cancellation responses can include:
Poly-RateLimit-RemainingPoly-RateLimit-ResetPoly-RateLimit-TierPoly-RateLimit-WarningRetry-Afteron HTTP 429Documentation: https://docs.polymarket.com/api-reference/trading-rate-limits
Current behavior
The transport receives an
httpx.Response, but public client methods parse and return the response body as typed models.SecureClient.create()andAsyncSecureClient.create()do not expose a public response hook or transport configuration, so applications cannot observe headers from successful requests.The internal
TransportOptions.event_hooksfacility is not reachable through the public client constructors. Reaching through private client context or globally monkey-patching HTTPX would be fragile, especially in concurrent trading applications.Issue #182 is related for rejected responses and
Retry-After, but this request also covers successful responses and general response metadata observation.Requested API
One possible design would be an optional response callback accepted by both client factories:
The exact API shape is flexible. The important properties would be:
Exposing a public
TransportOptionsargument could also solve this, provided it is supported and stable.Environment
polymarket-client==0.2.0SecureClientandAsyncSecureClient