package polymarket

  1. Overview
  2. Docs
OCaml client library for the Polymarket prediction market API

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.2.0.tar.gz
md5=4eb4c5d2f63ff081c9713d90be5a51b2
sha512=0e3de0c9b40683e09ab8f9f966a44784ef1b9b482c3eefef84104a7e8042c92f1d79893ee9588b24fa3d0decaed7f365509f4d1c23c66ce8328efb64e721f276

doc/polymarket.clob/Polymarket_clob/Client/index.html

Module Polymarket_clob.ClientSource

Typestate-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 endpoints
  • L2: L2 API key authentication (orders, trades) + L1 + public endpoints

The typestate pattern ensures that authentication-required endpoints can only be called on clients with the appropriate credentials configured.

Typical Usage

  (* 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.error

Re-exported authentication types from common.

Re-exported cryptographic utilities from common.

Sourceval default_base_url : string

Default base URL for the CLOB API: https://clob.polymarket.com

Client Types

These abstract types represent the three authentication levels.

Sourcetype unauthed

Unauthenticated client for public endpoints only.

Sourcetype l1

L1-authenticated client with private key for wallet operations.

Sourcetype l2

L2-authenticated client with full API access.

Sourcemodule Unauthed : sig ... end
Sourcemodule L1 : sig ... end
Sourcemodule L2 : sig ... end

State Transitions

Functions to upgrade or downgrade authentication levels.

Sourceval upgrade_to_l1 : unauthed -> private_key:Crypto.private_key -> l1

Upgrade an unauthenticated client to L1 by providing a private key. The address is derived from the private key automatically.

Sourceval upgrade_to_l2 : l1 -> credentials:Auth.credentials -> l2

Upgrade an L1 client to L2 by providing API credentials.

Sourceval l2_to_l1 : l2 -> l1

Downgrade an L2 client to L1 (loses L2 capabilities).

Sourceval l2_to_unauthed : l2 -> unauthed

Downgrade an L2 client to unauthenticated (for public endpoints only).

Sourceval l1_to_unauthed : l1 -> unauthed

Downgrade an L1 client to unauthenticated (for public endpoints only).