docs: sync Polymarket documentation (2026-05-04)

This commit is contained in:
Etherdrake
2026-05-04 14:56:14 +02:00
parent a54a713360
commit 88de1ab5cd
35 changed files with 189 additions and 180 deletions
+30 -21
View File
@@ -63,12 +63,16 @@ Before making authenticated requests, you need to obtain API credentials using L
<Tab title="TypeScript">
```typescript theme={null}
import { ClobClient } from "@polymarket/clob-client-v2";
import { Wallet } from "ethers"; // v5.8.0
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const signer = createWalletClient({ account, transport: http() });
const client = new ClobClient({
host: "https://clob.polymarket.com",
chain: 137, // Polygon mainnet
signer: new Wallet(process.env.PRIVATE_KEY),
signer,
});
// Creates new credentials or derives existing ones
@@ -76,7 +80,7 @@ Before making authenticated requests, you need to obtain API credentials using L
console.log(credentials);
// {
// apiKey: "550e8400-e29b-41d4-a716-446655440000",
// key: "550e8400-e29b-41d4-a716-446655440000",
// secret: "base64EncodedSecretString",
// passphrase: "randomPassphraseString"
// }
@@ -85,17 +89,17 @@ Before making authenticated requests, you need to obtain API credentials using L
<Tab title="Python">
```python theme={null}
from py_clob_client.client import ClobClient
from py_clob_client_v2 import ClobClient
import os
client = ClobClient(
host="https://clob.polymarket.com",
chain=137, # Polygon mainnet
chain_id=137, # Polygon mainnet
key=os.getenv("PRIVATE_KEY")
)
# Creates new credentials or derives existing ones
credentials = client.create_or_derive_api_creds()
credentials = client.create_or_derive_api_key()
print(credentials)
# {
@@ -109,9 +113,9 @@ Before making authenticated requests, you need to obtain API credentials using L
<Tab title="Rust">
```rust theme={null}
use std::str::FromStr;
use polymarket_client_sdk::POLYGON;
use polymarket_client_sdk::auth::{LocalSigner, Signer};
use polymarket_client_sdk::clob::{Client, Config};
use polymarket_client_sdk_v2::POLYGON;
use polymarket_client_sdk_v2::auth::{LocalSigner, Signer};
use polymarket_client_sdk_v2::clob::{Client, Config};
let private_key = std::env::var("POLYMARKET_PRIVATE_KEY")?;
let signer = LocalSigner::from_str(&private_key)?
@@ -221,7 +225,7 @@ The `POLY_SIGNATURE` is generated by signing the following EIP-712 struct:
Reference implementations:
* [TypeScript](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/eip712.ts)
* [Python](https://github.com/Polymarket/py-clob-client-v2/blob/main/py_clob_client/signing/eip712.py)
* [Python](https://github.com/Polymarket/py-clob-client-v2/blob/main/py_clob_client_v2/signing/eip712.py)
Response:
@@ -249,20 +253,24 @@ All trading endpoints require these 5 headers:
| `POLY_API_KEY` | User's API `apiKey` value |
| `POLY_PASSPHRASE` | User's API `passphrase` value |
The `POLY_SIGNATURE` for L2 is an HMAC-SHA256 signature created using the user's API credentials `secret` value. Reference implementations can be found in the [TypeScript](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/hmac.ts) and [Python](https://github.com/Polymarket/py-clob-client-v2/blob/main/py_clob_client/signing/hmac.py) clients.
The `POLY_SIGNATURE` for L2 is an HMAC-SHA256 signature created using the user's API credentials `secret` value. Reference implementations can be found in the [TypeScript](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/hmac.ts) and [Python](https://github.com/Polymarket/py-clob-client-v2/blob/main/py_clob_client_v2/signing/hmac.py) clients.
### CLOB Client
<Tabs>
<Tab title="TypeScript">
```typescript theme={null}
import { ClobClient } from "@polymarket/clob-client-v2";
import { Wallet } from "ethers"; // v5.8.0
import { ClobClient, Side } from "@polymarket/clob-client-v2";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const signer = createWalletClient({ account, transport: http() });
const client = new ClobClient({
host: "https://clob.polymarket.com",
chain: 137,
signer: new Wallet(process.env.PRIVATE_KEY),
signer,
creds: apiCreds, // Generated from L1 auth, API credentials enable L2 methods
signatureType: 1, // signatureType explained below
funderAddress, // funder explained below
@@ -270,7 +278,7 @@ The `POLY_SIGNATURE` for L2 is an HMAC-SHA256 signature created using the user's
// Now you can trade!
const order = await client.createAndPostOrder(
{ tokenID: "123456", price: 0.65, size: 100, side: "BUY" },
{ tokenID: "123456", price: 0.65, size: 100, side: Side.BUY },
{ tickSize: "0.01", negRisk: false }
);
```
@@ -278,12 +286,13 @@ The `POLY_SIGNATURE` for L2 is an HMAC-SHA256 signature created using the user's
<Tab title="Python">
```python theme={null}
from py_clob_client.client import ClobClient
from py_clob_client_v2 import ClobClient, OrderArgs, PartialCreateOrderOptions
from py_clob_client_v2.order_builder.constants import BUY
import os
client = ClobClient(
host="https://clob.polymarket.com",
chain=137,
chain_id=137,
key=os.getenv("PRIVATE_KEY"),
creds=api_creds, # Generated from L1 auth, API credentials enable L2 methods
signature_type=1, # signatureType explained below
@@ -292,16 +301,16 @@ The `POLY_SIGNATURE` for L2 is an HMAC-SHA256 signature created using the user's
# Now you can trade!
order = client.create_and_post_order(
{"token_id": "123456", "price": 0.65, "size": 100, "side": "BUY"},
{"tick_size": "0.01", "neg_risk": False}
OrderArgs(token_id="123456", price=0.65, size=100, side=BUY),
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
)
```
</Tab>
<Tab title="Rust">
```rust theme={null}
use polymarket_client_sdk::clob::types::{Side, SignatureType};
use polymarket_client_sdk::types::dec;
use polymarket_client_sdk_v2::clob::types::{Side, SignatureType};
use polymarket_client_sdk_v2::types::dec;
let client = Client::new("https://clob.polymarket.com", Config::default())?
.authentication_builder(&signer)
+6 -6
View File
@@ -12,7 +12,7 @@ Polymarket provides official open-source clients in TypeScript, Python, and Rust
<CodeGroup>
```bash TypeScript theme={null}
npm install @polymarket/clob-client-v2 ethers@5
npm install @polymarket/clob-client-v2 viem
```
```bash Python theme={null}
@@ -20,7 +20,7 @@ Polymarket provides official open-source clients in TypeScript, Python, and Rust
```
```bash Rust theme={null}
cargo add polymarket-client-sdk
cargo add polymarket_client_sdk_v2 --features clob
```
</CodeGroup>
@@ -41,12 +41,12 @@ Polymarket provides official open-source clients in TypeScript, Python, and Rust
```
```python Python theme={null}
from py_clob_client.client import ClobClient
from py_clob_client_v2 import ClobClient
client = ClobClient(
"https://clob.polymarket.com",
key=private_key,
chain=137,
chain_id=137,
creds=api_creds,
)
@@ -54,7 +54,7 @@ Polymarket provides official open-source clients in TypeScript, Python, and Rust
```
```rust Rust theme={null}
use polymarket_client_sdk::clob::{Client, Config};
use polymarket_client_sdk_v2::clob::{Client, Config};
let client = Client::new("https://clob.polymarket.com", Config::default())?
.authentication_builder(&signer)
@@ -71,7 +71,7 @@ Polymarket provides official open-source clients in TypeScript, Python, and Rust
| ---------- | ---------------------------- | ------------------------------------------------------------------------------------------ |
| TypeScript | `@polymarket/clob-client-v2` | [github.com/Polymarket/clob-client-v2](https://github.com/Polymarket/clob-client-v2) |
| Python | `py-clob-client-v2` | [github.com/Polymarket/py-clob-client-v2](https://github.com/Polymarket/py-clob-client-v2) |
| Rust | `polymarket-client-sdk` | [github.com/Polymarket/rs-clob-client-v2](https://github.com/Polymarket/rs-clob-client-v2) |
| Rust | `polymarket_client_sdk_v2` | [github.com/Polymarket/rs-clob-client-v2](https://github.com/Polymarket/rs-clob-client-v2) |
Each repository includes working examples in the `/examples` directory.