feat: accept custom reqwest::Client via Config#321
feat: accept custom reqwest::Client via Config#321skyc1e wants to merge 2 commits intoPolymarket:mainfrom
reqwest::Client via Config#321Conversation
The cancel_order method was sending `orderId` (camelCase) but the CLOB API expects `orderID` (capital D), matching the TypeScript and Python clients. The mock test was also using the wrong key, masking the issue.
Add an optional `http_client` field to `Config` so that callers can inject a pre-configured `reqwest::Client`. This addresses the need for fine-grained HTTP tuning (TCP_NODELAY, connection pool sizing, HTTP/2 windows, keep-alive, proxies, TLS) without expanding the library's own configuration surface. When `http_client` is `None` (the default), behavior is unchanged. Closes Polymarket#308
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 90fb110. Configure here.
| let client = match config.http_client.clone() { | ||
| Some(custom) => custom, | ||
| None => ReqwestClient::builder().default_headers(headers).build()?, | ||
| }; |
There was a problem hiding this comment.
Default headers built but unused with custom client
Low Severity
The headers HeaderMap is unconditionally constructed and populated with four entries (User-Agent, Accept, Connection, Content-Type), but when config.http_client is Some, the headers variable is never used. The header construction belongs inside the None arm of the match so it's only performed when actually needed.
Reviewed by Cursor Bugbot for commit 90fb110. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #321 +/- ##
=======================================
Coverage 85.54% 85.55%
=======================================
Files 32 32
Lines 5167 5170 +3
=======================================
+ Hits 4420 4423 +3
Misses 747 747
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Upstream merges: - Polymarket#321: accept custom reqwest::Client via Config - Polymarket#322: BuilderTradeResponse.builder Address → ApiKey - Polymarket#306: add match_time_nano to TradeResponse - Polymarket#305: preserve unknown activity side values - Polymarket#303: version bump to 0.4.5 - Dep bumps: rust_decimal 1.41, uuid 1.23 Local patches: - Reduce auth header allocations (HeaderValue::from for integers) - Reorder order_builder size validation before async fee_rate call - Skip double deserialization when tracing is disabled - subscribe_book_and_prices: single-stream book + price_change - subscribe_user/orders/trades: async for tokio::sync::RwLock - Subscription lag: escalate to error and force resubscribe - Broadcast capacity: 1024 → 16384 - excludeDepositsWithdrawals param on ActivityRequest - cancel_order: orderId → orderID Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Upstream merges: - Polymarket#321: accept custom reqwest::Client via Config - Polymarket#322: BuilderTradeResponse.builder Address → ApiKey - Polymarket#306: add match_time_nano to TradeResponse - Polymarket#305: preserve unknown activity side values - Polymarket#303: version bump to 0.4.5 - Dep bumps: rust_decimal 1.41, uuid 1.23 Local patches: - Reduce auth header allocations (HeaderValue::from for integers) - Reorder order_builder size validation before async fee_rate call - Skip double deserialization when tracing is disabled - subscribe_book_and_prices: single-stream book + price_change - subscribe_user/orders/trades: async for tokio::sync::RwLock - Subscription lag: escalate to error and force resubscribe - Broadcast capacity: 1024 → 16384 - excludeDepositsWithdrawals param on ActivityRequest - cancel_order: orderId → orderID Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>


Closes #308
Summary
Adds an optional
http_clientfield toConfigso callers can inject a pre-configuredreqwest::Client.Motivation
The internal
reqwest::Clientis built with minimal defaults, which leaves performance on the table for latency-sensitive use cases (market making, automated trading). Users currently have no way to tune TCP_NODELAY, connection pool sizing, HTTP/2 window parameters, keep-alive, proxies, or TLS settings.Rather than expose individual knobs in
Config(which would grow over time and mirrorreqwest::ClientBuilder), this PR lets callers bring their own fully-configured client.Changes
Config::http_client— newOption<reqwest::Client>field (defaultNone)Client::new— whenhttp_clientisSome, uses it directly; otherwise builds the default client as beforecustom_http_client_should_be_usedverifies the custom client path works end-to-endBackward compatibility
Fully backward compatible.
Config::default()and all existing builder calls continue to work unchanged —http_clientdefaults toNone.Usage
Note
Medium Risk
Moderate risk: changes client construction to optionally use a caller-supplied
reqwest::Clientand tweaks thecancel_orderrequest body field name, which could affect cancellation behavior if the API expects the prior key or if callers provide clients with missing default headers/timeouts.Overview
Adds HTTP client injection via config.
Confignow includes an optionalhttp_client: Option<reqwest::Client>;Client::newuses the provided client as-is or falls back to building the default client with standard headers.Adjusts cancel order request payload.
cancel_ordernow sends{ "orderID": ... }instead of{ "orderId": ... }, and tests are updated accordingly. A new test (custom_http_client_should_be_used) validates the custom-client path end-to-end.Reviewed by Cursor Bugbot for commit 90fb110. Bugbot is set up for automated code reviews on this repo. Configure here.