Skip to main content

polyoxide_clob/
lib.rs

1//! # polyoxide-clob
2//!
3//! Rust client library for Polymarket CLOB (Centralized Limit Order Book) API.
4//!
5//! ## Features
6//!
7//! - Order creation, signing, and posting with EIP-712
8//! - Market data and order book retrieval
9//! - Account balance and trade history
10//! - HMAC-based L2 authentication
11//! - Type-safe API with idiomatic Rust patterns
12//!
13//! ## Example
14//!
15//! ```no_run
16//! use polyoxide_clob::{Account, Chain, ClobBuilder, CreateOrderParams, OrderKind, OrderSide};
17//!
18//! #[tokio::main]
19//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
20//!     // Load account from environment variables
21//!     let account = Account::from_env()?;
22//!
23//!     // Create CLOB client
24//!     let clob = ClobBuilder::new()
25//!         .with_account(account)
26//!         .chain(Chain::PolygonMainnet)
27//!         .build()?;
28//!
29//!     // Place an order
30//!     let params = CreateOrderParams {
31//!         token_id: "token_id".to_string(),
32//!         price: 0.52,
33//!         size: 100.0,
34//!         side: OrderSide::Buy,
35//!         order_type: OrderKind::Gtc,
36//!         post_only: false,
37//!         expiration: None,
38//!         funder: None,
39//!         signature_type: None,
40//!     };
41//!
42//!     let response = clob.place_order(&params, None).await?;
43//!     println!("Order ID: {:?}", response.order_id);
44//!
45//!     Ok(())
46//! }
47//! ```
48
49/// Doctest-only anchor that compiles every fenced `rust` example in the crate
50/// README, so broken examples fail CI. Exists only under `cfg(doctest)`, so it
51/// never appears in `cargo doc` output or normal builds.
52#[cfg(doctest)]
53#[doc = include_str!("../README.md")]
54struct ReadmeDoctests;
55
56pub mod account;
57pub mod api;
58pub mod client;
59pub mod core;
60pub mod error;
61pub mod request;
62pub mod types;
63pub mod utils;
64
65#[cfg(feature = "ws")]
66pub mod ws;
67
68pub use core::chain::{Chain, Contracts};
69
70pub use account::{Account, AccountConfig, Credentials, Signer, Wallet};
71
72#[cfg(feature = "keychain")]
73pub use account::{save_private_key_to_keychain, KEYCHAIN_SERVICE};
74pub use api::{
75    account::{
76        BalanceAllowanceResponse, BuilderTrade, ListBuilderTrades, ListBuilderTradesResponse,
77        ListClobTrades, ListTradesResponse, MakerOrder, Trade,
78    },
79    auth::{
80        ApiKeyInfo, ApiKeyResponse, BuilderApiKeyResponse, ClosedOnlyResponse,
81        ReadonlyApiKeyResponse, ValidateKeyResponse,
82    },
83    health::{Health, ServerTimeResponse},
84    markets::{
85        BatchPricesHistoryRequest, BatchPricesHistoryResponse, BookParams, CalculatePriceResponse,
86        ClobMarketDetails, ClobRewards, ClobToken, FeeDetails, LastTradePriceResponse,
87        ListMarketsResponse, LiveActivityMarket, Market, MarketByTokenResponse, MarketPrice,
88        MarketToken, MidpointResponse, OrderBook, OrderLevel, PriceHistoryPoint, PriceResponse,
89        PricesHistoryQuery, PricesHistoryResponse, SpreadResponse,
90    },
91    notifications::Notification,
92    orders::{
93        BatchCancelResponse, ListOrdersResponse, OpenOrder, OrderResponse, OrderScoringResponse,
94    },
95    rewards::{
96        Paginated, RewardEarnings, RewardMarket, RewardMarketEarning, RewardPercentages,
97        RewardTotalEarnings,
98    },
99};
100pub use client::{Clob, ClobBuilder, CreateOrderParams, SignedOrderPayload};
101pub use error::ClobError;
102pub use types::{
103    Order, OrderKind, OrderSide, ParseTickSizeError, PartialCreateOrderOptions, SignatureType,
104    SignedOrder, TickSize,
105};