1use tracing::info;
77
78pub const DEFAULT_CHAIN_ID: u64 = 137; pub const DEFAULT_BASE_URL: &str = "https://clob.polymarket.com";
81pub const DEFAULT_TIMEOUT_SECS: u64 = 30;
82pub const DEFAULT_MAX_RETRIES: u32 = 3;
83pub const DEFAULT_RATE_LIMIT_RPS: u32 = 100;
84
85pub fn init() {
87 tracing_subscriber::fmt::init();
88 info!("Polyfill-rs initialized");
89}
90
91pub use crate::types::{
93 ApiCredentials,
94 ApiKeysResponse,
96 AssetType,
97 Balance,
98 BalanceAllowance,
99 BalanceAllowanceParams,
100 BatchMidpointRequest,
101 BatchMidpointResponse,
102 BatchPriceRequest,
103 BatchPriceResponse,
104 BookParams,
105 ClientConfig,
106 ClientResult,
107 FeeRateResponse,
108 FillEvent,
109 Market,
110 MarketSnapshot,
111 MarketsResponse,
112 MidpointResponse,
113 NegRiskResponse,
114 NotificationParams,
115 OpenOrder,
116 OpenOrderParams,
117 Order,
118 OrderBook,
119 OrderBookSummary,
120 OrderDelta,
121 OrderRequest,
122 OrderStatus,
123 OrderSummary,
124 OrderType,
125 PriceResponse,
126 PricesHistoryInterval,
127 PricesHistoryResponse,
128 Rewards,
129 RfqApproveOrderResponse,
130 RfqCancelQuote,
131 RfqCancelRequest,
132 RfqCreateQuote,
133 RfqCreateQuoteResponse,
134 RfqCreateRequest,
135 RfqCreateRequestResponse,
136 RfqListResponse,
137 RfqOrderExecutionRequest,
138 RfqQuoteData,
139 RfqQuotesParams,
140 RfqRequestData,
141 RfqRequestsParams,
142 Side,
143 SimplifiedMarket,
144 SimplifiedMarketsResponse,
145 SpreadResponse,
146 StreamMessage,
147 TickSizeResponse,
148 Token,
149 TokenPrice,
150 TradeParams,
151 WssAuth,
152 WssChannelType,
153 WssSubscription,
154};
155
156pub use crate::client::{ClobClient, PolyfillClient};
158
159pub use crate::types::OrderArgs;
161
162pub use crate::errors::{PolyfillError, Result};
164
165pub use crate::book::{OrderBook as OrderBookImpl, OrderBookManager};
167pub use crate::decode::Decoder;
168pub use crate::fill::{FillEngine, FillResult};
169pub use crate::stream::{MarketStream, StreamManager, WebSocketBookApplier, WebSocketStream};
170pub use crate::ws_hot_path::{WsBookApplyStats, WsBookUpdateProcessor};
171
172pub use crate::utils::{crypto, math, rate_limit, retry, time, url};
174
175pub mod auth;
177pub mod book;
178pub mod buffer_pool;
179pub mod client;
180pub mod connection_manager;
181pub mod decode;
182pub mod dns_cache;
183pub mod errors;
184pub mod fill;
185pub mod http_config;
186pub mod orders;
187pub mod stream;
188pub mod types;
189pub mod utils;
190pub mod ws_hot_path;
191
192#[cfg(test)]
194mod benches {
195 use crate::{OrderBookManager, OrderDelta, Side};
196 use chrono::Utc;
197 use criterion::{criterion_group, criterion_main};
198 use rust_decimal::Decimal;
199 use std::str::FromStr;
200
201 #[allow(dead_code)]
202 fn order_book_benchmark(c: &mut criterion::Criterion) {
203 let book_manager = OrderBookManager::new(100);
204
205 c.bench_function("apply_order_delta", |b| {
206 b.iter(|| {
207 let delta = OrderDelta {
208 token_id: "test_token".to_string(),
209 timestamp: Utc::now(),
210 side: Side::BUY,
211 price: Decimal::from_str("0.75").unwrap(),
212 size: Decimal::from_str("100.0").unwrap(),
213 sequence: 1,
214 };
215
216 let _ = book_manager.apply_delta(delta);
217 });
218 });
219 }
220
221 criterion_group!(benches, order_book_benchmark);
222 criterion_main!(benches);
223}
224
225#[cfg(test)]
226mod tests {
227 use super::*;
228 use rust_decimal::Decimal;
229 use std::str::FromStr;
230
231 #[test]
232 fn test_client_creation() {
233 let _client = ClobClient::new("https://test.example.com");
234 }
238
239 #[test]
240 fn test_order_args_creation() {
241 let args = OrderArgs::new(
242 "test_token",
243 Decimal::from_str("0.75").unwrap(),
244 Decimal::from_str("100.0").unwrap(),
245 Side::BUY,
246 );
247
248 assert_eq!(args.token_id, "test_token");
249 assert_eq!(args.side, Side::BUY);
250 }
251
252 #[test]
253 fn test_order_args_default() {
254 let args = OrderArgs::default();
255 assert_eq!(args.token_id, "");
256 assert_eq!(args.price, Decimal::ZERO);
257 assert_eq!(args.size, Decimal::ZERO);
258 assert_eq!(args.side, Side::BUY);
259 }
260}