Skip to content

perf: prewarm order metadata and reuse order hash - #114

Open
casterkay wants to merge 2 commits into
Polymarket:mainfrom
casterkay:perf/signing-fast-path
Open

perf: prewarm order metadata and reuse order hash#114
casterkay wants to merge 2 commits into
Polymarket:mainfrom
casterkay:perf/signing-fast-path

Conversation

@casterkay

@casterkay casterkay commented Aug 25, 2026

Copy link
Copy Markdown

Summary

  • add a public warm_up_order_metadata API so callers can populate order-construction metadata before latency-sensitive order creation
  • expose the EIP-712 hash already produced while signing on SignedOrderV1 and SignedOrderV2
  • preserve V1, V2 EOA/proxy/safe, and POLY_1271 signatures and keep order_hash out of submitted JSON

Why

Order creation may otherwise perform tick-size, negative-risk, fee, version, and builder-fee REST lookups on first use. Consumers that need the venue order ID also currently rebuild and hash the same typed data after signing. This gives callers public, dependency-owned APIs for both optimizations without copying private internals.

Tests

  • python -m pytest -q — 232 passed, 15 subtests passed
  • regressions prove warmed V1/V2 first orders issue zero metadata GETs
  • regressions prove each signature path encodes/hashes typed order data once and retains exact signature/hash compatibility
  • regressions prove order_hash is excluded from the order wire payload

Note

Low Risk
Performance and API surface additions on order construction; signing semantics and wire payloads are preserved with regression tests.

Overview
Adds warm_up_order_metadata(condition_id, builder_code?) so callers can prefetch CLOB market info (tick size, neg risk, fee metadata), V1 per-token fee caps, and optional builder fee rates before latency-sensitive create_order / create_market_order calls. Builder fee loading is centralized in __load_builder_fee_rate, reused by warmup and the existing lazy cache path.

Signed orders now carry an order_hash field on SignedOrderV1 and SignedOrderV2, populated from the same EIP-712 encode/sign step via _build_order_signature_and_hash (one encode_typed_data per build for EOA-style paths; POLY_1271 still hashes once for the hash). order_to_json_v1 / order_to_json_v2 do not send order_hash on the wire.

Tests cover warmup avoiding metadata GETs on first orders, stable signature/hash values, single-encode behavior, and JSON exclusion of order_hash.

Reviewed by Cursor Bugbot for commit 905aae8. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread py_clob_client_v2/client.py
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