Skip to content

Releases: Haut/polymarket

v0.2.0

01 Jan 20:47

Choose a tag to compare

Polymarket OCaml Client v0.2.0

Release Date: January 1, 2026
License: MIT


Overview

polymarket is a production-grade OCaml client library for the Polymarket prediction market platform. This release provides complete, type-safe bindings to all Polymarket APIs with modern structured concurrency via Eio.

opam install polymarket

Features

Complete API Coverage

API Description
Gamma Markets, events, series, search, profiles, comments (~35 endpoints)
Data Positions, trades, activity, leaderboards, analytics (~12 endpoints)
CLOB Order books, pricing, authenticated trading
RFQ Request for Quote flow for block trades
WSS Real-time WebSocket market and user channels
RTDS Crypto price feeds (Binance, Chainlink) and comment streams

Type-Safe Design

  • Validated PrimitivesAddress.t, Hash64.t, Timestamp.t, Nonneg_int.t with compile-time guarantees
  • Typestate Authentication — CLOB client enforces L1/L2 auth requirements at compile time
  • Phantom-Typed Requests — POST requests require body before execution; impossible to forget
  • Module-Based Enums — Safe string-convertible enums for all API parameters

Infrastructure

  • Built-in Rate Limiting — GCRA algorithm with official Polymarket presets per route
  • Pure-OCaml TLS — Cross-platform via tls-eio, no OpenSSL dependency
  • Structured Logging — Per-module Logs.Src for fine-grained filtering
  • Forward Compatibility — Logs warnings when API returns unexpected fields

Authentication

  • L1 (Wallet) — EIP-712 signing with secp256k1 for API key creation
  • L2 (API Key) — HMAC-SHA256 request signing for trading

Quick Start

open Polymarket

let () =
  Eio_main.run @@ fun env ->
  let http = Http.create env#net in

  (* Fetch active markets *)
  let markets = Gamma.get_markets http ~active:true ~limit:10 () in
  List.iter (fun m -> print_endline m.question) markets;

  (* Stream real-time order book updates *)
  Wss.Market_channel.connect env ~http (fun stream ->
    Wss.Market_channel.subscribe stream [ "asset_id_here" ];
    Eio.Stream.iter (fun msg -> ...) stream)

Modules

The library provides both a unified Polymarket module and granular sub-libraries:

polymarket              # Complete library
polymarket.gamma        # Gamma API only
polymarket.data         # Data API only
polymarket.clob         # CLOB API only
polymarket.rfq          # RFQ API only
polymarket.wss          # WebSocket streaming
polymarket.rtds         # Real-Time Data Socket
polymarket.http         # HTTP client
polymarket.rate_limiter # GCRA rate limiting
polymarket.common       # Primitives, auth, crypto

Requirements

  • OCaml >= 5.1
  • Dune >= 3.16

Examples

The examples/ directory includes working demos for each API:

  • gamma_api_demo.ml — Markets, events, series, search
  • data_api_demo.ml — Positions, trades, leaderboards
  • clob_api_demo.ml — Order books, pricing, trading
  • rfq_demo.ml — RFQ request/quote flow
  • wss_demo.ml — WebSocket market and user channels
  • rtds_demo.ml — Crypto prices and comment streams

Documentation


Links