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/src/polymarket.common/rate_limit_presets.ml.html

Source file rate_limit_presets.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
(** Pre-configured rate limit presets for Polymarket APIs.

    Based on official documentation:
    https://docs.polymarket.com/#/api-rate-limits *)

module B = Polymarket_rate_limiter.Builder

(* {1 General Rate Limits} *)

let general ~behavior =
  [ B.global ~requests:15000 ~window_seconds:10.0 ~behavior ]

(* {1 Data API Rate Limits} *)

let data_api_host = "data-api.polymarket.com"

let data_api ~behavior =
  [
    (* Specific endpoints first *)
    B.per_endpoint ~host:data_api_host ~method_:"GET" ~path:"/trades"
      ~requests:200 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:data_api_host ~method_:"GET" ~path:"/positions"
      ~requests:150 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:data_api_host ~method_:"GET" ~path:"/closed-positions"
      ~requests:150 ~window_seconds:10.0 ~behavior;
    (* General Data API limit *)
    B.per_host ~host:data_api_host ~requests:1000 ~window_seconds:10.0 ~behavior;
  ]

(* {1 Gamma API Rate Limits} *)

let gamma_api_host = "gamma-api.polymarket.com"

let gamma_api ~behavior =
  [
    (* Specific endpoints first *)
    B.per_endpoint ~host:gamma_api_host ~method_:"GET" ~path:"/comments"
      ~requests:200 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:gamma_api_host ~method_:"GET" ~path:"/events"
      ~requests:300 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:gamma_api_host ~method_:"GET" ~path:"/markets"
      ~requests:300 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:gamma_api_host ~method_:"GET" ~path:"/tags"
      ~requests:200 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:gamma_api_host ~method_:"GET" ~path:"/search"
      ~requests:300 ~window_seconds:10.0 ~behavior;
    (* General Gamma API limit *)
    B.per_host ~host:gamma_api_host ~requests:4000 ~window_seconds:10.0
      ~behavior;
  ]

(* {1 CLOB API Rate Limits} *)

let clob_api_host = "clob.polymarket.com"

(* CLOB Trading endpoints with burst (10s) + sustained (10min) limits *)
let clob_trading ~behavior =
  let ep ~meth ~p ~burst ~sustained =
    B.(
      route () |> host clob_api_host |> method_ meth |> path p
      |> limit ~requests:burst ~window_seconds:10.0
      |> limit ~requests:sustained ~window_seconds:600.0
      |> on_limit behavior |> build)
  in
  [
    ep ~meth:"POST" ~p:"/order" ~burst:3500 ~sustained:36000;
    ep ~meth:"DELETE" ~p:"/order" ~burst:3000 ~sustained:30000;
    ep ~meth:"POST" ~p:"/orders" ~burst:1000 ~sustained:15000;
    ep ~meth:"DELETE" ~p:"/orders" ~burst:1000 ~sustained:15000;
    ep ~meth:"DELETE" ~p:"/cancel-all" ~burst:250 ~sustained:6000;
    ep ~meth:"DELETE" ~p:"/cancel-market-orders" ~burst:1000 ~sustained:1500;
  ]

(* CLOB Market Data endpoints *)
let clob_market_data ~behavior =
  [
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/book"
      ~requests:1500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/books"
      ~requests:500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/price"
      ~requests:1500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/prices"
      ~requests:500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/midprice"
      ~requests:1500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/midprices"
      ~requests:500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/prices-history"
      ~requests:1000 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/tick-size"
      ~requests:200 ~window_seconds:10.0 ~behavior;
  ]

(* CLOB Ledger endpoints *)
let clob_ledger ~behavior =
  [
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/data/orders"
      ~requests:500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/data/trades"
      ~requests:500 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/notifications"
      ~requests:125 ~window_seconds:10.0 ~behavior;
    (* General ledger endpoints: /trades, /orders, /order *)
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/trades"
      ~requests:900 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/orders"
      ~requests:900 ~window_seconds:10.0 ~behavior;
  ]

(* CLOB Balance and Auth endpoints *)
let clob_other ~behavior =
  [
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/balance-allowance"
      ~requests:200 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"POST"
      ~path:"/balance-allowance" ~requests:50 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"GET" ~path:"/api-keys"
      ~requests:100 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"POST" ~path:"/api-keys"
      ~requests:100 ~window_seconds:10.0 ~behavior;
    B.per_endpoint ~host:clob_api_host ~method_:"DELETE" ~path:"/api-keys"
      ~requests:100 ~window_seconds:10.0 ~behavior;
  ]

let clob_api ~behavior =
  (* Trading endpoints first (most specific, with burst+sustained) *)
  clob_trading ~behavior @ clob_market_data ~behavior @ clob_ledger ~behavior
  @ clob_other ~behavior
  @ [
      (* General CLOB limit last *)
      B.per_host ~host:clob_api_host ~requests:9000 ~window_seconds:10.0
        ~behavior;
    ]

(* {1 Combined Presets} *)

let all ~behavior =
  data_api ~behavior @ gamma_api ~behavior @ clob_api ~behavior
  @ general ~behavior