MCPcopy Index your code
hub / github.com/TechieBoy/polymarket-rs-client

github.com/TechieBoy/polymarket-rs-client @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
119 symbols 232 edges 7 files 3 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Polymarket Rust Client   Latest Version Docs Badge

An async rust client for interacting with Polymarket.

[!NOTE] This code is still in active developement and alpha quality. Use at your own risk.

Why use this instead of the official client?

  1. You get to write Rust!
  2. Most calls are anywhere from 1.5x to upto 4x faster.
  3. Upto 10x less memory usage.

Some benchmarks on my machine: | | polymarket-rs-client | Official Python client | |-------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------| | Create a order with EIP-712 signature. | 266.5 ms ± 28.6 ms | 1.127 s ± 0.047 s | | Fetch and parse json(simplified markets). | 404.5 ms ± 22.9 ms | 1.366 s ± 0.048 s | | Fetch markets. Mem usage | 88,053 allocs, 81,823 frees, 15,945,966 bytes allocated | 211,898 allocs, 202,962 frees, 128,457,588 bytes allocated |

Installing

cargo add polymarket-rs-client

The client internally uses a reqwest Client, so you will also need the tokio runtime.

cargo add -F rt-multi-thread,macros tokio

For representing order amounts and sizes, the client uses the rust-decimal crate. It is recommended to install this crate as well.

cargo add rust-decimal

Usage

Create an instance of the ClobClient to interact with the CLOB API. Note that the prerequisite allowances must be set before creating and sending an order as described here.

use polymarket_rs_client::ClobClient;

use std::env;

const HOST: &str = "https://clob.polymarket.com";
const POLYGON: u64 = 137;

#[tokio::main]
async fn main() {
    let private_key = env::var("PK").unwrap();
    let nonce = None;

    let mut client = ClobClient::with_l1_headers(HOST, &private_key, POLYGON);
    let keys = client.create_or_derive_api_key(nonce).await.unwrap();
    client.set_api_creds(keys);

    let o = client.get_sampling_markets(None).await.unwrap();
    dbg!(o);
}

The ClobClient implements the same API as the official python client. All available functions are listed in the docs.

Extension points exported contracts — how you extend this code

EthSigner (Interface)
(no doc) [1 implementers]
src/eth_utils.rs

Core symbols most depended-on inside this repo

as_str
called by 21
src/data.rs
get_l2_parameters
called by 16
src/lib.rs
create_request_with_headers
called by 16
src/lib.rs
to_string
called by 15
src/data.rs
decimal_to_token_u32
called by 6
src/orders.rs
create_l2_headers
called by 5
src/headers.rs
get_contract_config
called by 5
src/config.rs
get_l1_parameters
called by 4
src/lib.rs

Shape

Method 72
Class 30
Function 11
Enum 5
Interface 1

Languages

Rust100%

Modules by API surface

src/lib.rs58 symbols
src/data.rs36 symbols
src/orders.rs15 symbols
src/utils.rs3 symbols
src/eth_utils.rs3 symbols
src/headers.rs2 symbols
src/config.rs2 symbols

For agents

$ claude mcp add polymarket-rs-client \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact