diff --git a/README.md b/README.md index afdb06c..9bcf926 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ let mut client = ClobClient::with_l1_headers( "https://clob.polymarket.com", "your_private_key", 137, + None, ); // Same API calls diff --git a/src/client.rs b/src/client.rs index daaf4b1..ea282b4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -53,6 +53,20 @@ impl Default for OrderArgs { } } +/// HTTP client configuration type +#[derive(Debug, Clone, Copy)] +pub enum ClientType { + Colocated, + Internet, + Optimized, +} + +impl Default for ClientType { + fn default() -> Self { + ClientType::Colocated + } +} + /// Main client for interacting with Polymarket API pub struct ClobClient { pub http_client: Client, @@ -183,14 +197,23 @@ impl ClobClient { } /// Create a client with L1 headers (for authentication) - pub fn with_l1_headers(host: &str, private_key: &str, chain_id: u64) -> Self { + pub fn with_l1_headers( + host: &str, + private_key: &str, + chain_id: u64, + client_type: Option, + ) -> Self { let signer = private_key .parse::() .expect("Invalid private key"); let order_builder = crate::orders::OrderBuilder::new(signer.clone(), None, None); - let http_client = create_optimized_client().unwrap_or_else(|_| Client::new()); + let http_client = match client_type.unwrap_or_default() { + ClientType::Colocated => create_colocated_client().unwrap_or_else(|_| Client::new()), + ClientType::Internet => create_internet_client().unwrap_or_else(|_| Client::new()), + ClientType::Optimized => create_optimized_client().unwrap_or_else(|_| Client::new()), + }; // Initialize infrastructure modules let dns_cache = None; // Skip DNS cache for simplicity in this constructor @@ -1749,6 +1772,7 @@ mod tests { base_url, "0x1234567890123456789012345678901234567890123456789012345678901234", 137, + None, ) } diff --git a/src/lib.rs b/src/lib.rs index ece7233..66957e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,7 @@ //! "https://clob.polymarket.com", //! "your_private_key", //! 137, +//! None, //! ); //! //! // Get API credentials diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 217b34e..0cf2625 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -54,7 +54,7 @@ impl TestConfig { let private_key = self.private_key.as_ref() .ok_or_else(|| polyfill_rs::PolyfillError::auth("No private key provided", polyfill_rs::errors::AuthErrorKind::InvalidCredentials))?; - Ok(ClobClient::with_l1_headers(&self.host, private_key, self.chain_id)) + Ok(ClobClient::with_l1_headers(&self.host, private_key, self.chain_id, None)) } /// Print test configuration (without sensitive data) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 5a078fc..bbb93dd 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -26,7 +26,7 @@ fn load_env_vars() -> (String, Option, Option, Option) { async fn test_real_api_create_derive_api_key() { let (private_key, _, _, _) = load_env_vars(); - let client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); // Test creating/deriving API key let result = client.create_or_derive_api_key(None).await; @@ -46,7 +46,7 @@ async fn test_real_api_authenticated_order_flow() { let (private_key, _, _, _) = load_env_vars(); // Initialize client with L1 headers - let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); // Step 1: Create/derive API credentials println!("Step 1: Creating/deriving API credentials..."); @@ -135,7 +135,7 @@ async fn test_real_api_authenticated_order_flow() { async fn test_real_api_get_orders() { let (private_key, _, _, _) = load_env_vars(); - let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); let api_creds = client.create_or_derive_api_key(None).await .expect("Failed to create/derive API key"); client.set_api_creds(api_creds); @@ -163,7 +163,7 @@ async fn test_real_api_get_orders() { async fn test_real_api_get_trades() { let (private_key, _, _, _) = load_env_vars(); - let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); let api_creds = client.create_or_derive_api_key(None).await .expect("Failed to create/derive API key"); client.set_api_creds(api_creds); @@ -190,7 +190,7 @@ async fn test_real_api_get_trades() { async fn test_real_api_get_balance_allowance() { let (private_key, _, _, _) = load_env_vars(); - let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); let api_creds = client.create_or_derive_api_key(None).await .expect("Failed to create/derive API key"); client.set_api_creds(api_creds); @@ -231,7 +231,7 @@ async fn test_real_api_get_balance_allowance() { async fn test_real_api_get_api_keys() { let (private_key, _, _, _) = load_env_vars(); - let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); let api_creds = client.create_or_derive_api_key(None).await .expect("Failed to create/derive API key"); client.set_api_creds(api_creds); @@ -259,7 +259,7 @@ async fn test_real_api_get_api_keys() { async fn test_real_api_get_notifications() { let (private_key, _, _, _) = load_env_vars(); - let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let mut client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); let api_creds = client.create_or_derive_api_key(None).await .expect("Failed to create/derive API key"); client.set_api_creds(api_creds); @@ -287,7 +287,7 @@ async fn test_real_api_get_notifications() { async fn test_real_api_market_data_endpoints() { let (private_key, _, _, _) = load_env_vars(); - let client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); println!("Testing market data endpoints (no auth required)..."); @@ -336,7 +336,7 @@ async fn test_real_api_market_data_endpoints() { async fn test_real_api_batch_endpoints() { let (private_key, _, _, _) = load_env_vars(); - let client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID); + let client = ClobClient::with_l1_headers(HOST, &private_key, CHAIN_ID, None); println!("Testing batch endpoints..."); diff --git a/tests/order_posting_test.rs b/tests/order_posting_test.rs index 1b29f8f..d9a233a 100644 --- a/tests/order_posting_test.rs +++ b/tests/order_posting_test.rs @@ -15,7 +15,8 @@ async fn test_post_order_authentication() { let mut client = ClobClient::with_l1_headers( "https://clob.polymarket.com", &private_key, - 137 + 137, + None ); println!("Step 1: Creating API credentials..."); diff --git a/tests/simple_auth_test.rs b/tests/simple_auth_test.rs index ea2018e..bea56bc 100644 --- a/tests/simple_auth_test.rs +++ b/tests/simple_auth_test.rs @@ -13,7 +13,8 @@ async fn test_create_api_key_simple() { let mut client = ClobClient::with_l1_headers( "https://clob.polymarket.com", &private_key, - 137 + 137, + None ); println!("Step 1: Creating/deriving API key..."); @@ -60,7 +61,8 @@ async fn test_get_api_keys() { let mut client = ClobClient::with_l1_headers( "https://clob.polymarket.com", &private_key, - 137 + 137, + None ); let creds = client.create_or_derive_api_key(None).await @@ -96,7 +98,8 @@ async fn test_get_trades() { let mut client = ClobClient::with_l1_headers( "https://clob.polymarket.com", &private_key, - 137 + 137, + None ); let creds = client.create_or_derive_api_key(None).await @@ -132,7 +135,8 @@ async fn test_get_notifications() { let mut client = ClobClient::with_l1_headers( "https://clob.polymarket.com", &private_key, - 137 + 137, + None ); let creds = client.create_or_derive_api_key(None).await