Polymarket_clob.ClientSourceTypestate-authenticated HTTP client for the Polymarket CLOB API.
This module provides compile-time enforcement of authentication requirements for the CLOB API. Three authentication levels are available:
Unauthed: Public endpoints only (order book, pricing, timeseries)L1: L1 wallet authentication (create/derive API keys) + public endpointsL2: L2 API key authentication (orders, trades) + L1 + public endpointsThe typestate pattern ensures that authentication-required endpoints can only be called on clients with the appropriate credentials configured.
(* Start with an unauthenticated client for public data *)
let client = Unauthed.create ~sw ~net ~rate_limiter () in
let order_book = Unauthed.get_order_book client ~token_id () in
(* Upgrade to L1 for wallet-based operations *)
let l1_client = upgrade_to_l1 client ~private_key in
(* Derive API credentials and upgrade to L2 *)
match L1.derive_api_key l1_client ~nonce:0 with
| Ok (l2_client, _resp) ->
(* Now we can create orders *)
let _ = L2.create_order l2_client ~order ~owner ~order_type () in
()
| Error e -> failwith e.errorRe-exported authentication types from common.
Re-exported cryptographic utilities from common.
Default base URL for the CLOB API: https://clob.polymarket.com
These abstract types represent the three authentication levels.
Unauthenticated client for public endpoints only.
L1-authenticated client with private key for wallet operations.
L2-authenticated client with full API access.
Functions to upgrade or downgrade authentication levels.
Upgrade an unauthenticated client to L1 by providing a private key. The address is derived from the private key automatically.
Upgrade an L1 client to L2 by providing API credentials.
Downgrade an L2 client to unauthenticated (for public endpoints only).