mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-19 15:38:09 +00:00
docs
This commit is contained in:
@@ -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.
|
||||
[](https://crates.io/crates/polyfill-rs)
|
||||
[](https://docs.rs/polyfill-rs)
|
||||
[](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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user