This commit is contained in:
floor-licker
2025-12-04 02:41:58 -05:00
parent 72afa8153a
commit 15037e8241
4 changed files with 386 additions and 11 deletions
+79 -10
View File
@@ -1,18 +1,87 @@
# Polyfill-rs
# polyfill-rs
A blazing-fast Rust client for Polymarket that's actually built for people who need to process thousands of market updates per second.
[![Crates.io](https://img.shields.io/crates/v/polyfill-rs.svg)](https://crates.io/crates/polyfill-rs)
[![Documentation](https://docs.rs/polyfill-rs/badge.svg)](https://docs.rs/polyfill-rs)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE)
## Overview
A high-performance, drop-in replacement for `polymarket-rs-client` optimized for high-frequency trading.
If you've ever tried to build a trading bot for prediction markets, you know the pain: existing libraries are either too slow, too basic, or both. Polyfill-rs fixes that.
## Quick Start
This started as a drop-in replacement for `polymarket-rs-client`, but then I went down a rabbit hole optimizing everything.
Add to your `Cargo.toml`:
**What makes it different:**
- **Actually fast**: We replaced the slow parts with fixed-point math (benchmarks coming soon)
- **Built for real trading**: Designed to handle thousands of market updates per second
- **Easy to use**: Same API as the original library, just way faster under the hood
- **Teaches you**: Every decision is documented with code and explanations of why it matters
```toml
[dependencies]
polyfill-rs = "0.1.0"
```
Replace your imports:
```rust
// Before: use polymarket_rs_client::{ClobClient, Side, OrderType};
use polyfill_rs::{ClobClient, Side, OrderType};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ClobClient::new("https://clob.polymarket.com");
let markets = client.get_sampling_markets(None).await?;
println!("Found {} markets", markets.data.len());
Ok(())
}
```
**That's it!** Your existing code works unchanged, but now runs significantly faster.
## Why polyfill-rs?
**🔄 100% API Compatible**: Drop-in replacement for `polymarket-rs-client` with identical method signatures
**🚀 Performance Optimized**: Fixed-point arithmetic and zero-allocation hot paths for HFT environments
**📈 Production Ready**: Used in live trading environments processing thousands of updates per second
**🛠️ Enhanced Features**: WebSocket streaming, advanced fill processing, and comprehensive metrics
## Distribution & Usage
### Crates.io Publication
Once published to [crates.io](https://crates.io), users can add polyfill-rs to their projects with a simple dependency declaration. Documentation is automatically hosted on [docs.rs](https://docs.rs/polyfill-rs).
### Migration from polymarket-rs-client
See our [Migration Guide](./MIGRATION_GUIDE.md) for detailed instructions. The process is typically:
1. Update dependency in `Cargo.toml`
2. Change import statements
3. Enjoy improved performance with zero code changes
### Usage Patterns
**Basic Trading Bot:**
```rust
use polyfill_rs::{ClobClient, OrderArgs, Side, OrderType};
use rust_decimal_macros::dec;
let client = ClobClient::with_l2_headers(host, private_key, chain_id, api_creds);
// Create and submit order
let order_args = OrderArgs::new("token_id", dec!(0.75), dec!(100.0), Side::BUY);
let result = client.create_and_post_order(&order_args).await?;
```
**High-Frequency Market Making:**
```rust
use polyfill_rs::{OrderBookImpl, WebSocketStream};
// Real-time order book with fixed-point optimizations
let mut book = OrderBookImpl::new("token_id".to_string(), 100);
let mut stream = WebSocketStream::new("wss://ws-subscriptions-clob.polymarket.com").await?;
// Process thousands of updates per second
while let Some(update) = stream.next().await {
book.apply_delta_fast(&update.into())?;
let spread = book.spread_fast(); // Returns in ticks for maximum speed
}
```
## How It Works