@@ -48,7 +48,7 @@ Add the crate to your `Cargo.toml`:
4848
4949``` toml
5050[dependencies ]
51- polymarket_client_sdk_v2 = " 0.4 "
51+ polymarket_client_sdk_v2 = " 0.5 "
5252```
5353
5454or
@@ -83,7 +83,7 @@ Enable features in your `Cargo.toml`:
8383
8484``` toml
8585[dependencies ]
86- polymarket_client_sdk_v2 = { version = " 0.3 " , features = [" ws" , " data" ] }
86+ polymarket_client_sdk_v2 = { version = " 0.5 " , features = [" ws" , " data" ] }
8787```
8888
8989## Re-exported Types
@@ -226,7 +226,7 @@ The **signature_type** parameter tells the system how to verify your signatures:
226226- ` signature_type=2 ` : Browser wallet proxy signatures (when using a proxy contract, not direct wallet connections)
227227- ` signature_type=3 ` : EIP-1271 smart contract wallet signatures (** V2 orders only** )
228228
229- See [ SignatureType] ( src/clob/types/mod.rs#L182 ) for more information.
229+ See [ ` SignatureType ` ] ( src/clob/types/mod.rs ) for more information.
230230
231231##### Place a market order
232232
@@ -303,38 +303,54 @@ async fn main() -> anyhow::Result<()> {
303303}
304304```
305305
306- ##### V1 and V2 Orders
306+ ##### V1 and V2 protocols
307307
308- The SDK supports both V1 (legacy) and V2 exchange contracts. ** V2 is the default.** V2 orders add ` timestamp ` ,
309- ` metadata ` , and ` builder ` fields, and remove the V1-only ` taker ` , ` nonce ` , and ` feeRateBps ` fields. The EIP-712
310- domain version is ` "2" ` for V2 orders.
308+ The SDK supports both V1 (legacy) and V2 exchange contracts. Protocol is ** auto-detected** on
309+ the first order build via ` GET /version ` and cached for the lifetime of the ` Client ` . You pick
310+ the protocol by pointing the client at the corresponding host:
311+
312+ | Protocol | Host | Collateral | EIP-712 domain version |
313+ | ----------| -----------------------------------| --------------| ------------------------|
314+ | V2 | ` https://clob-v2.polymarket.com ` | pUSD | ` "2" ` |
315+ | V1 | ` https://clob.polymarket.com ` | USDC.e | ` "1" ` |
316+
317+ V2 orders add ` timestamp ` , ` metadata ` , and ` builder ` fields. V1 orders use ` taker ` , ` nonce ` ,
318+ and ` feeRateBps ` instead. The order builder exposes both sets of fields — the ones that don't
319+ apply to the detected protocol are silently ignored at build time, so you can write one
320+ code-path that works against either server.
321+
322+ V2-specific builder fields (ignored when the server runs V1):
311323
312324``` rust,ignore
313- use alloy::primitives::B256;
314- use polymarket_client_sdk_v2::clob::types::OrderVersion;
325+ use polymarket_client_sdk_v2::types::B256;
315326
316- // V2 order (default) — with metadata and builder attribution
317327let order = client
318328 .limit_order()
319329 .token_id("<token-id>")
320330 .size(Decimal::ONE_HUNDRED)
321331 .price(dec!(0.5))
322332 .side(Side::Buy)
323- .metadata(B256::ZERO) // optional: 32 bytes of custom metadata
324- .builder_code(B256::ZERO) // optional: builder fee attribution
325- .defer_exec(false) // optional: defer execution
333+ .metadata(B256::ZERO) // 32 bytes of custom metadata
334+ .builder_code(B256::ZERO) // builder fee attribution
335+ .defer_exec(false) // defer execution
326336 .build()
327337 .await?;
338+ ```
339+
340+ V1-specific builder fields (ignored when the server runs V2):
341+
342+ ``` rust,ignore
343+ use polymarket_client_sdk_v2::types::Address;
328344
329- // V1 order (legacy) — explicitly opt in
330345let order = client
331346 .limit_order()
332- .version(OrderVersion::V1)
333347 .token_id("<token-id>")
334348 .size(Decimal::ONE_HUNDRED)
335349 .price(dec!(0.5))
336350 .side(Side::Buy)
337- .nonce(0) // V1-only field
351+ .taker(Address::ZERO) // explicit taker; default zero = public order
352+ .nonce(0) // on-chain cancel nonce; default 0
353+ .fee_rate_bps(0) // must match the market rate when set
338354 .build()
339355 .await?;
340356```
@@ -383,26 +399,31 @@ async fn main() -> anyhow::Result<()> {
383399Real-time orderbook and user event streaming. Requires the ` ws ` feature.
384400
385401``` toml
386- polymarket_client_sdk_v2 = { version = " 0.3 " , features = [" ws" ] }
402+ polymarket_client_sdk_v2 = { version = " 0.5 " , features = [" ws" ] }
387403```
388404
389405``` rust,ignore
406+ use std::str::FromStr as _;
407+
390408use futures::StreamExt as _;
391409use polymarket_client_sdk_v2::clob::ws::Client;
410+ use polymarket_client_sdk_v2::types::U256;
392411
393412#[tokio::main]
394413async fn main() -> anyhow::Result<()> {
395414 let client = Client::default();
396415
397- // Subscribe to orderbook updates for specific assets
398- let asset_ids = vec!["<asset-id>".to_owned() ];
416+ // Subscribe to orderbook updates for specific assets.
417+ let asset_ids = vec![U256::from_str( "<asset-id>")? ];
399418 let stream = client.subscribe_orderbook(asset_ids)?;
400419 let mut stream = Box::pin(stream);
401420
402421 while let Some(book_result) = stream.next().await {
403422 let book = book_result?;
404- println!("Orderbook update for {}: {} bids, {} asks",
405- book.asset_id, book.bids.len(), book.asks.len());
423+ println!(
424+ "Orderbook update for {}: {} bids, {} asks",
425+ book.asset_id, book.bids.len(), book.asks.len()
426+ );
406427 }
407428 Ok(())
408429}
0 commit comments