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 client;
179pub mod connection_manager;
180pub mod decode;
181pub mod errors;
182pub mod fill;
183pub mod http_config;
184pub mod orders;
185pub mod stream;
186pub mod types;
187pub mod utils;
188pub mod ws_hot_path;
189
190#[cfg(test)]
192mod benches {
193 use crate::{OrderBookManager, OrderDelta, Side};
194 use chrono::Utc;
195 use criterion::{criterion_group, criterion_main};
196 use rust_decimal::Decimal;
197 use std::str::FromStr;
198
199 #[allow(dead_code)]
200 fn order_book_benchmark(c: &mut criterion::Criterion) {
201 let book_manager = OrderBookManager::new(100);
202
203 c.bench_function("apply_order_delta", |b| {
204 b.iter(|| {
205 let delta = OrderDelta {
206 token_id: "test_token".to_string(),
207 timestamp: Utc::now(),
208 side: Side::BUY,
209 price: Decimal::from_str("0.75").unwrap(),
210 size: Decimal::from_str("100.0").unwrap(),
211 sequence: 1,
212 };
213
214 let _ = book_manager.apply_delta(delta);
215 });
216 });
217 }
218
219 criterion_group!(benches, order_book_benchmark);
220 criterion_main!(benches);
221}
222
223#[cfg(test)]
224mod tests {
225 use super::*;
226 use rust_decimal::Decimal;
227 use std::str::FromStr;
228
229 #[test]
230 fn test_client_creation() {
231 let _client = ClobClient::new("https://test.example.com");
232 }
236
237 #[test]
238 fn test_order_args_creation() {
239 let args = OrderArgs::new(
240 "test_token",
241 Decimal::from_str("0.75").unwrap(),
242 Decimal::from_str("100.0").unwrap(),
243 Side::BUY,
244 );
245
246 assert_eq!(args.token_id, "test_token");
247 assert_eq!(args.side, Side::BUY);
248 }
249
250 #[test]
251 fn test_order_args_default() {
252 let args = OrderArgs::default();
253 assert_eq!(args.token_id, "");
254 assert_eq!(args.price, Decimal::ZERO);
255 assert_eq!(args.size, Decimal::ZERO);
256 assert_eq!(args.side, Side::BUY);
257 }
258}