Expand description
Polyfill-rs: High-performance Rust client for Polymarket
§Features
- High-performance order book management with optimized data structures
- Real-time market data streaming with WebSocket support
- Trade execution simulation with slippage protection
- Comprehensive error handling with specific error types
- Rate limiting and retry logic for robust API interactions
- Ethereum integration with EIP-712 signing support
- Benchmarking tools for performance analysis
§Quick Start
use polyfill_rs::{ClobClient, OrderArgs, Side};
use rust_decimal::Decimal;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client (compatible with polymarket-rs-client)
let mut client = ClobClient::with_l1_headers(
"https://clob.polymarket.com",
"your_private_key",
137,
);
// Get API credentials
let api_creds = client.create_or_derive_api_key(None).await.unwrap();
client.set_api_creds(api_creds);
// Create and post order
let order_args = OrderArgs::new(
"token_id",
Decimal::from_str("0.75").unwrap(),
Decimal::from_str("100.0").unwrap(),
Side::BUY,
);
let result = client.create_and_post_order(&order_args).await.unwrap();
println!("Order posted: {:?}", result);
Ok(())
}§Advanced Usage
use polyfill_rs::{ClobClient, OrderBookImpl};
use rust_decimal::Decimal;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a basic client
let client = ClobClient::new("https://clob.polymarket.com");
// Get market data
let markets = client.get_sampling_markets(None).await.unwrap();
println!("Found {} markets", markets.data.len());
// Create an order book for high-performance operations
let mut book = OrderBookImpl::new("token_id".to_string(), 100); // 100 levels depth
println!("Order book created for token: {}", book.token_id);
Ok(())
}Re-exports§
pub use crate::types::ApiCredentials;pub use crate::types::ApiKeysResponse;pub use crate::types::AssetType;pub use crate::types::Balance;pub use crate::types::BalanceAllowance;pub use crate::types::BalanceAllowanceParams;pub use crate::types::BatchMidpointRequest;pub use crate::types::BatchMidpointResponse;pub use crate::types::BatchPriceRequest;pub use crate::types::BatchPriceResponse;pub use crate::types::BookParams;pub use crate::types::ClientConfig;pub use crate::types::ClientResult;pub use crate::types::FillEvent;pub use crate::types::Market;pub use crate::types::MarketSnapshot;pub use crate::types::MarketsResponse;pub use crate::types::MidpointResponse;pub use crate::types::NegRiskResponse;pub use crate::types::NotificationParams;pub use crate::types::OpenOrder;pub use crate::types::OpenOrderParams;pub use crate::types::Order;pub use crate::types::OrderBook;pub use crate::types::OrderBookSummary;pub use crate::types::OrderDelta;pub use crate::types::OrderRequest;pub use crate::types::OrderStatus;pub use crate::types::OrderSummary;pub use crate::types::OrderType;pub use crate::types::PriceResponse;pub use crate::types::Rewards;pub use crate::types::Side;pub use crate::types::SimplifiedMarket;pub use crate::types::SimplifiedMarketsResponse;pub use crate::types::SpreadResponse;pub use crate::types::StreamMessage;pub use crate::types::TickSizeResponse;pub use crate::types::Token;pub use crate::types::TokenPrice;pub use crate::types::TradeParams;pub use crate::types::WssAuth;pub use crate::types::WssChannelType;pub use crate::types::WssSubscription;pub use crate::client::ClobClient;pub use crate::client::PolyfillClient;pub use crate::client::OrderArgs;pub use crate::errors::PolyfillError;pub use crate::errors::Result;pub use crate::book::OrderBook as OrderBookImpl;pub use crate::book::OrderBookManager;pub use crate::decode::Decoder;pub use crate::fill::FillEngine;pub use crate::fill::FillResult;pub use crate::stream::MarketStream;pub use crate::stream::StreamManager;pub use crate::stream::WebSocketStream;pub use crate::utils::crypto;pub use crate::utils::math;pub use crate::utils::rate_limit;pub use crate::utils::retry;pub use crate::utils::time;pub use crate::utils::url;
Modules§
- auth
- Authentication and cryptographic utilities for Polymarket API
- book
- Order book management for Polymarket client
- buffer_
pool - Buffer pooling for reducing allocation overhead
- client
- High-performance Rust client for Polymarket
- connection_
manager - Connection management for maintaining warm HTTP connections
- decode
- Data decoding utilities for Polymarket client
- dns_
cache - DNS caching to reduce lookup latency
- errors
- Error types for the Polymarket client
- fill
- Trade execution and fill handling for Polymarket client
- http_
config - HTTP client optimization for low-latency trading
- orders
- Order creation and signing functionality
- stream
- Async streaming functionality for Polymarket client
- types
- Core types for the Polymarket client
- utils
- Utility functions for the Polymarket client