{"id":50418882,"url":"https://github.com/onsails/polyfill2-rs","last_synced_at":"2026-06-12T01:01:45.355Z","repository":{"id":353338340,"uuid":"1218494920","full_name":"onsails/polyfill2-rs","owner":"onsails","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-29T16:52:59.000Z","size":1844,"stargazers_count":10,"open_issues_count":3,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-31T07:32:28.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onsails.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-22T23:55:17.000Z","updated_at":"2026-05-25T20:35:14.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/onsails/polyfill2-rs","commit_stats":null,"previous_names":["onsails/polyfill2-rs"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/onsails/polyfill2-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fpolyfill2-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fpolyfill2-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fpolyfill2-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fpolyfill2-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onsails","download_url":"https://codeload.github.com/onsails/polyfill2-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fpolyfill2-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34224103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-31T07:30:26.380Z","updated_at":"2026-06-12T01:01:45.294Z","avatar_url":"https://github.com/onsails.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Crates.io](https://img.shields.io/crates/v/polyfill2.svg)](https://crates.io/crates/polyfill2)\n[![Documentation](https://docs.rs/polyfill2/badge.svg)](https://docs.rs/polyfill2)\n[![CI](https://github.com/onsails/polyfill2-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/onsails/polyfill2-rs/actions/workflows/ci.yml)\n[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE)\n\nA high-performance Rust client for Polymarket's **CLOB V2** API, with latency-optimized data structures and zero-allocation hot paths. This is a V2 migration fork of [`polyfill-rs`](https://github.com/floor-licker/polyfill-rs) (Julius Tranquilli), updated in April 2026 for the CLOB V2 cutover (new EIP-712 Order schema, new contract addresses, new endpoint URLs, new WebSocket message shapes).\n\n`polyfill-rs` was originally created as a performance-focused Rust alternative to `polymarket-rs-client`, aiming to beat the benchmarks quoted in that project's README while maintaining zero-allocation hot paths. This fork carries those properties forward onto V2.\n\n**On zero-alloc**: in this project, \"zero-alloc\" means zero allocations in the per-message handling loop after init/warm-up — i.e. **the hot path never touches the heap**, even though cold paths do. Order book paths that introduce new allocations by design:\n- First time seeing a token/book (HashMap insert + key clone): `src/book.rs:~788`\n- New price levels (BTreeMap node growth): `src/book.rs:~409`\n\n\n## Quick Start\n\nAdd to your `Cargo.toml`:\n\n```toml\n[dependencies]\npolyfill2 = \"0.1\"\n```\n\n```rust\nuse polyfill2::{ClobClient, Side, OrderType};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let client = ClobClient::new(\"https://clob-v2.polymarket.com\");\n    let markets = client.get_sampling_markets(None).await?;\n    println!(\"Found {} markets\", markets.data.len());\n    Ok(())\n}\n```\n\n## Performance Comparison\n\n\u003e **Note:** the numbers below were measured on upstream `polyfill-rs` against CLOB V1 (`clob.polymarket.com`) prior to the V2 migration. Computational paths (book updates, spread/mid, WS decode) are unchanged and should still hold; the networked end-to-end number has not been re-measured against V2 — [#1](https://github.com/onsails/polyfill2-rs/issues/1) tracks re-measurement.\n\n**Real-World API Performance (with network I/O)**\n\nEnd-to-end performance with Polymarket's API, including network latency, JSON parsing, and decompression:\n\n| Operation | polyfill-rs | polymarket-rs-client | Official Python Client |\n|-----------|-------------|----------------------|------------------------|\n| **Fetch Markets** | **321.6 ms ± 92.9 ms** | 409.3 ms ± 137.6 ms | 1.366 s ± 0.048 s |\n\n\n**Performance vs polymarket-rs-client:**\n- **21.4% faster** \n- **32.5% more consistent** \n- **4.2x faster** than Official Python Client\n\n**Benchmark Methodology:** All benchmarks run side-by-side on the same machine, same network, same time using 20 iterations, 100ms delay between requests, /simplified-markets endpoint. Best performance achieved with connection keep-alive enabled. See `examples/side_by_side_benchmark.rs` in commit `a63a170`: https://github.com/floor-licker/polyfill-rs/blob/a63a170/examples/side_by_side_benchmark.rs for the complete benchmark implementation.\n\n**Computational Performance (pure CPU, no I/O)**\n\n| Operation | Performance | Notes |\n|-----------|-------------|-------|\n| **Order Book Updates (1000 ops)** | 159.6 µs ± 32 µs | 6,260 updates/sec, zero-allocation |\n| **Spread/Mid Calculations** | 70 ns ± 77 ns | 14.3M ops/sec, optimized BTreeMap |\n| **JSON Parsing (480KB)** | ~2.3 ms | SIMD-accelerated parsing (1.77x faster than serde_json) |\n| **WS `book` hot path (decode + apply)** | ~0.28 µs / 2.01 µs / 7.70 µs | 1 / 16 / 64 levels-per-side, ~3.7–4.0x faster vs serde decode+apply (see `benches/ws_hot_path.rs`) |\n\nRun the WS hot-path benchmark locally with `cargo bench --bench ws_hot_path`.\n\n**Key Performance Optimizations:**\n\nThe 21.4% performance improvement comes from SIMD-accelerated JSON parsing (1.77x faster than serde_json), HTTP/2 tuning with 512KB stream windows optimized for 469KB payloads, integrated DNS caching, connection keep-alive, and buffer pooling to reduce allocation overhead.\n\n### Memory Architecture\n\nPre-allocated pools eliminate allocation latency spikes. Configurable book depth limiting prevents memory bloat. Hot data structures group frequently-accessed fields for cache line efficiency.\n\n### Architectural Principles\n\nPrice data converts to fixed-point at ingress boundaries while maintaining tick-aligned precision. The critical path uses integer arithmetic with branchless operations. Data converts back to IEEE 754 at egress for API compatibility. This enables deterministic execution with predictable instruction counts.\n\n### Measured Network Improvements\n\n| Optimization Technique | Performance Gain | Use Case |\n|------------------------|------------------|----------|\n| **Optimized HTTP client** | **11% baseline improvement** | Every API call |\n| **Connection pre-warming** | **70% faster subsequent requests** | Application startup |\n| **Request parallelization** | **200% faster batch operations** | Multi-market data fetching |\n| **Circuit breaker resilience** | **Better uptime during instability** | Production trading systems |\n\n## Credits\n\n`polyfill-rs` was originally authored by Julius Tranquilli ([floor-licker/polyfill-rs](https://github.com/floor-licker/polyfill-rs)). This V2 fork (`polyfill2`) is maintained by [onsails](https://github.com/onsails).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonsails%2Fpolyfill2-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonsails%2Fpolyfill2-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonsails%2Fpolyfill2-rs/lists"}