docs: sync Polymarket documentation (2026-05-03)
Updated 55 files with latest documentation changes
This commit is contained in:
@@ -48,44 +48,45 @@ GET https://polymarket.com/api/geoblock
|
||||
|
||||
## Blocked Countries
|
||||
|
||||
The following countries are restricted from placing orders on Polymarket. Countries marked as **close-only** can close existing positions but cannot open new ones:
|
||||
The following countries are restricted from placing orders on Polymarket. Countries marked as **close-only** can close existing positions but cannot open new ones. Countries marked as **frontend UI restricted** are blocked only on the Polymarket frontend; the API itself is not restricted:
|
||||
|
||||
| Country Code | Country Name | Status |
|
||||
| ------------ | ------------------------------------ | ---------- |
|
||||
| AU | Australia | Blocked |
|
||||
| BE | Belgium | Blocked |
|
||||
| BY | Belarus | Blocked |
|
||||
| BI | Burundi | Blocked |
|
||||
| CF | Central African Republic | Blocked |
|
||||
| CD | Congo (Kinshasa) | Blocked |
|
||||
| CU | Cuba | Blocked |
|
||||
| DE | Germany | Blocked |
|
||||
| ET | Ethiopia | Blocked |
|
||||
| FR | France | Blocked |
|
||||
| GB | United Kingdom | Blocked |
|
||||
| IR | Iran | Blocked |
|
||||
| IQ | Iraq | Blocked |
|
||||
| IT | Italy | Blocked |
|
||||
| KP | North Korea | Blocked |
|
||||
| LB | Lebanon | Blocked |
|
||||
| LY | Libya | Blocked |
|
||||
| MM | Myanmar | Blocked |
|
||||
| NI | Nicaragua | Blocked |
|
||||
| NL | Netherlands | Blocked |
|
||||
| PL | Poland | Close-only |
|
||||
| RU | Russia | Blocked |
|
||||
| SG | Singapore | Close-only |
|
||||
| SO | Somalia | Blocked |
|
||||
| SS | South Sudan | Blocked |
|
||||
| SD | Sudan | Blocked |
|
||||
| SY | Syria | Blocked |
|
||||
| TH | Thailand | Close-only |
|
||||
| TW | Taiwan | Close-only |
|
||||
| UM | United States Minor Outlying Islands | Blocked |
|
||||
| US | United States | Blocked |
|
||||
| VE | Venezuela | Blocked |
|
||||
| YE | Yemen | Blocked |
|
||||
| ZW | Zimbabwe | Blocked |
|
||||
| Country Code | Country Name | Status |
|
||||
| ------------ | ------------------------------------ | ---------------------- |
|
||||
| AU | Australia | Blocked |
|
||||
| BE | Belgium | Blocked |
|
||||
| BY | Belarus | Blocked |
|
||||
| BI | Burundi | Blocked |
|
||||
| CF | Central African Republic | Blocked |
|
||||
| CD | Congo (Kinshasa) | Blocked |
|
||||
| CU | Cuba | Blocked |
|
||||
| DE | Germany | Blocked |
|
||||
| ET | Ethiopia | Blocked |
|
||||
| FR | France | Blocked |
|
||||
| GB | United Kingdom | Blocked |
|
||||
| IR | Iran | Blocked |
|
||||
| IQ | Iraq | Blocked |
|
||||
| IT | Italy | Blocked |
|
||||
| JP | Japan | Frontend UI restricted |
|
||||
| KP | North Korea | Blocked |
|
||||
| LB | Lebanon | Blocked |
|
||||
| LY | Libya | Blocked |
|
||||
| MM | Myanmar | Blocked |
|
||||
| NI | Nicaragua | Blocked |
|
||||
| NL | Netherlands | Blocked |
|
||||
| PL | Poland | Close-only |
|
||||
| RU | Russia | Blocked |
|
||||
| SG | Singapore | Close-only |
|
||||
| SO | Somalia | Blocked |
|
||||
| SS | South Sudan | Blocked |
|
||||
| SD | Sudan | Blocked |
|
||||
| SY | Syria | Blocked |
|
||||
| TH | Thailand | Close-only |
|
||||
| TW | Taiwan | Close-only |
|
||||
| UM | United States Minor Outlying Islands | Blocked |
|
||||
| US | United States | Blocked |
|
||||
| VE | Venezuela | Blocked |
|
||||
| YE | Yemen | Blocked |
|
||||
| ZW | Zimbabwe | Blocked |
|
||||
|
||||
***
|
||||
|
||||
@@ -166,9 +167,9 @@ The geoblocking system includes:
|
||||
|
||||
<Tab title="Rust">
|
||||
```rust theme={null}
|
||||
use polymarket_client_sdk::clob::Client;
|
||||
use polymarket_client_sdk_v2::clob::{Client, Config};
|
||||
|
||||
let client = Client::default();
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?;
|
||||
let geo = client.check_geoblock().await?;
|
||||
|
||||
if geo.blocked {
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
# Get builder trades
|
||||
|
||||
> Retrieves originated trades for a given builder.
|
||||
Builders can only see their own originated trades.
|
||||
> Retrieves trades attributed to a builder code.
|
||||
|
||||
|
||||
|
||||
@@ -47,10 +46,17 @@ paths:
|
||||
- Trade
|
||||
summary: Get builder trades
|
||||
description: |
|
||||
Retrieves originated trades for a given builder.
|
||||
Builders can only see their own originated trades.
|
||||
Retrieves trades attributed to a builder code.
|
||||
operationId: getBuilderTrades
|
||||
parameters:
|
||||
- name: builder_code
|
||||
in: query
|
||||
description: Builder code to fetch attributed trades for
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
pattern: ^0x[a-fA-F0-9]{64}$
|
||||
example: '0x0000000000000000000000000000000000000000000000000000000000000001'
|
||||
- name: id
|
||||
in: query
|
||||
description: Trade ID to filter by specific trade
|
||||
@@ -58,15 +64,6 @@ paths:
|
||||
schema:
|
||||
type: string
|
||||
example: trade-123
|
||||
- name: builder
|
||||
in: query
|
||||
description: >-
|
||||
Builder identifier (automatically set from authenticated builder, or
|
||||
can be specified with admin token)
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
example: 0199bfa0-f4c1-7a98-9c2b-b29cc6d39e10
|
||||
- name: market
|
||||
in: query
|
||||
description: Market (condition ID) to filter trades
|
||||
@@ -124,7 +121,8 @@ paths:
|
||||
- id: trade-123
|
||||
tradeType: TAKER
|
||||
takerOrderHash: '0xabcdef1234567890abcdef1234567890abcdef12'
|
||||
builder: 0199bfa0-f4c1-7a98-9c2b-b29cc6d39e10
|
||||
builder: >-
|
||||
0x0000000000000000000000000000000000000000000000000000000000000001
|
||||
market: >-
|
||||
0x0000000000000000000000000000000000000000000000000000000000000001
|
||||
assetId: >-
|
||||
@@ -154,14 +152,6 @@ paths:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
example:
|
||||
error: invalid builder trade params
|
||||
'401':
|
||||
description: Unauthorized - Invalid builder API key or authentication failed
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
example:
|
||||
error: Invalid API key
|
||||
'500':
|
||||
description: Internal server error
|
||||
content:
|
||||
@@ -170,12 +160,6 @@ paths:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
example:
|
||||
error: could not fetch builder trades
|
||||
security:
|
||||
- polyApiKey: []
|
||||
polyAddress: []
|
||||
polySignature: []
|
||||
polyPassphrase: []
|
||||
polyTimestamp: []
|
||||
components:
|
||||
schemas:
|
||||
BuilderTradesResponse:
|
||||
@@ -253,8 +237,9 @@ components:
|
||||
example: '0xabcdef1234567890abcdef1234567890abcdef12'
|
||||
builder:
|
||||
type: string
|
||||
description: Builder identifier
|
||||
example: 0199bfa0-f4c1-7a98-9c2b-b29cc6d39e10
|
||||
description: Builder code attributed to the trade
|
||||
pattern: ^0x[a-fA-F0-9]{64}$
|
||||
example: '0x0000000000000000000000000000000000000000000000000000000000000001'
|
||||
market:
|
||||
type: string
|
||||
description: Market (condition ID)
|
||||
@@ -342,31 +327,5 @@ components:
|
||||
format: date-time
|
||||
description: Last update timestamp
|
||||
example: '2024-01-01T00:00:00Z'
|
||||
securitySchemes:
|
||||
polyApiKey:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: POLY_API_KEY
|
||||
description: Your API key
|
||||
polyAddress:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: POLY_ADDRESS
|
||||
description: Ethereum address associated with the API key
|
||||
polySignature:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: POLY_SIGNATURE
|
||||
description: HMAC signature of the request
|
||||
polyPassphrase:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: POLY_PASSPHRASE
|
||||
description: API key passphrase
|
||||
polyTimestamp:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: POLY_TIMESTAMP
|
||||
description: Unix timestamp of the request
|
||||
|
||||
````
|
||||
@@ -274,6 +274,14 @@ components:
|
||||
description: Error message
|
||||
Order:
|
||||
type: object
|
||||
description: >
|
||||
Order payload submitted to the CLOB API. In CLOB V2, `expiration`
|
||||
remains in
|
||||
|
||||
the POST /order wire body for GTD/order-expiry handling, but it is not
|
||||
part
|
||||
|
||||
of the EIP-712 signed order struct.
|
||||
required:
|
||||
- maker
|
||||
- signer
|
||||
@@ -319,7 +327,9 @@ components:
|
||||
example: BUY
|
||||
expiration:
|
||||
type: string
|
||||
description: Unix timestamp when the order expires
|
||||
description: >-
|
||||
Unix timestamp when the order expires. Present in the API wire body;
|
||||
not part of the CLOB V2 EIP-712 signed order struct.
|
||||
example: '1735689600'
|
||||
timestamp:
|
||||
type: string
|
||||
|
||||
@@ -297,6 +297,14 @@ components:
|
||||
description: Error message
|
||||
Order:
|
||||
type: object
|
||||
description: >
|
||||
Order payload submitted to the CLOB API. In CLOB V2, `expiration`
|
||||
remains in
|
||||
|
||||
the POST /order wire body for GTD/order-expiry handling, but it is not
|
||||
part
|
||||
|
||||
of the EIP-712 signed order struct.
|
||||
required:
|
||||
- maker
|
||||
- signer
|
||||
@@ -342,7 +350,9 @@ components:
|
||||
example: BUY
|
||||
expiration:
|
||||
type: string
|
||||
description: Unix timestamp when the order expires
|
||||
description: >-
|
||||
Unix timestamp when the order expires. Present in the API wire body;
|
||||
not part of the CLOB V2 EIP-712 signed order struct.
|
||||
example: '1735689600'
|
||||
timestamp:
|
||||
type: string
|
||||
|
||||
@@ -92,6 +92,9 @@ Pass `builderCode` on every order to attribute it to your builder profile:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="0x...",
|
||||
@@ -100,7 +103,7 @@ Pass `builderCode` on every order to attribute it to your builder profile:
|
||||
side=BUY,
|
||||
builder_code=os.environ["POLY_BUILDER_CODE"],
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -54,7 +54,7 @@ The Builder Program uses a tiered system to manage rate limits while rewarding h
|
||||
1. Go to [polymarket.com/settings?tab=builder](https://polymarket.com/settings?tab=builder)
|
||||
2. Create a builder profile
|
||||
3. Click **"+ Create New"** to generate API keys
|
||||
4. Implement [builder signing](/trading/orders/attribution) — required for Relayer access and CLOB order attribution
|
||||
4. Attach your [builder code](/trading/orders/attribution) to CLOB orders for attribution; use a Relayer API key for gasless wallet operations
|
||||
|
||||
**What's included:**
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ Once a market resolves:
|
||||
|
||||
### Redeeming Tokens
|
||||
|
||||
After resolution, call the `redeemPositions` function on the CTF contract to exchange winning tokens for pUSD. The contract burns your tokens and returns the corresponding collateral.
|
||||
After resolution, redeem through the CTF collateral adapter to exchange winning tokens for pUSD. The adapter burns your ERC1155 outcome tokens through the CTF contract, receives the released USDC.e collateral, wraps it into pUSD, and returns pUSD to your wallet.
|
||||
|
||||
```
|
||||
100 winning tokens → $100 pUSD
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -37,14 +37,14 @@ Builder attribution in V2 is handled natively through the order struct — you a
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client.clob_types import OrderArgs
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import ClobClient
|
||||
from py_clob_client_v2 import 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=creds,
|
||||
signature_type=signature_type,
|
||||
@@ -60,7 +60,7 @@ Builder attribution in V2 is handled natively through the order struct — you a
|
||||
side=BUY,
|
||||
builder_code=os.environ["POLY_BUILDER_CODE"],
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -14,9 +14,11 @@ L1 methods require the client to initialize with a signer.
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers";
|
||||
import { createWalletClient, http } from "viem";
|
||||
import { privateKeyToAccount } from "viem/accounts";
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
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",
|
||||
@@ -31,14 +33,14 @@ L1 methods require the client to initialize with a signer.
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
key=private_key # Signer required for L1 methods
|
||||
)
|
||||
|
||||
@@ -134,6 +136,13 @@ async createOrDeriveApiKey(nonce?: number): Promise<ApiKeyCreds>
|
||||
|
||||
## Order Signing
|
||||
|
||||
<Note>
|
||||
In CLOB V2, `expiration` is still accepted in order payloads for GTD/order
|
||||
expiry handling, but it is not part of the EIP-712 signed order struct. The
|
||||
signed struct uses `timestamp`, `metadata`, and `builder` instead of the V1
|
||||
`expiration`, `nonce`, `feeRateBps`, and `taker` fields.
|
||||
</Note>
|
||||
|
||||
### createOrder
|
||||
|
||||
Create and sign a limit order locally without posting it to the CLOB. Use this when you want to sign orders in advance or implement custom submission logic. Submit via [`postOrder()`](/trading/clients/l2#postorder) or [`postOrders()`](/trading/clients/l2#postorders).
|
||||
@@ -162,7 +171,8 @@ async createOrder(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="number">
|
||||
Optional expiration timestamp for the order. Optional.
|
||||
Optional expiration timestamp included in the order payload for GTD/order
|
||||
expiry handling. This is not part of the CLOB V2 EIP-712 signed order struct.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tickSize" type="TickSize">
|
||||
@@ -202,7 +212,22 @@ async createOrder(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="string">
|
||||
The expiration timestamp as a string.
|
||||
The expiration timestamp included in the order payload. This is not part of
|
||||
the CLOB V2 EIP-712 signed order struct.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="timestamp" type="string">
|
||||
Order creation timestamp in milliseconds, used for order uniqueness in CLOB
|
||||
V2.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="metadata" type="string">
|
||||
Reserved `bytes32` metadata field.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="builder" type="string">
|
||||
Builder code (`bytes32`) for attribution, or zero if no builder code is
|
||||
attached.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="signatureType" type="number">
|
||||
@@ -275,7 +300,22 @@ async createMarketOrder(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="string">
|
||||
The expiration timestamp as a string.
|
||||
The expiration timestamp included in the order payload. This is not part of
|
||||
the CLOB V2 EIP-712 signed order struct.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="timestamp" type="string">
|
||||
Order creation timestamp in milliseconds, used for order uniqueness in CLOB
|
||||
V2.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="metadata" type="string">
|
||||
Reserved `bytes32` metadata field.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="builder" type="string">
|
||||
Builder code (`bytes32`) for attribution, or zero if no builder code is
|
||||
attached.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="signatureType" type="number">
|
||||
|
||||
@@ -14,12 +14,14 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers";
|
||||
import { createWalletClient, http } from "viem";
|
||||
import { privateKeyToAccount } from "viem/accounts";
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
const apiCreds = {
|
||||
apiKey: process.env.API_KEY,
|
||||
key: process.env.API_KEY,
|
||||
secret: process.env.SECRET,
|
||||
passphrase: process.env.PASSPHRASE,
|
||||
};
|
||||
@@ -40,8 +42,8 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client.clob_types import ApiCreds
|
||||
from py_clob_client_v2 import ClobClient
|
||||
from py_clob_client_v2 import ApiCreds
|
||||
import os
|
||||
|
||||
api_creds = ApiCreds(
|
||||
@@ -52,7 +54,7 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
key=os.getenv("PRIVATE_KEY"),
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ Public methods require the client to initialize with the host URL and Polygon ch
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137
|
||||
chain_id=137
|
||||
)
|
||||
|
||||
# Ready to call public methods
|
||||
|
||||
@@ -167,9 +167,9 @@ The geoblocking system includes:
|
||||
|
||||
<Tab title="Rust">
|
||||
```rust theme={null}
|
||||
use polymarket_client_sdk::clob::Client;
|
||||
use polymarket_client_sdk_v2::clob::{Client, Config};
|
||||
|
||||
let client = Client::default();
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?;
|
||||
let geo = client.check_geoblock().await?;
|
||||
|
||||
if geo.blocked {
|
||||
|
||||
@@ -13,7 +13,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
<CardGroup cols={3}>
|
||||
<Card title="TypeScript Client" icon="github" href="https://github.com/Polymarket/clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">
|
||||
npm install @polymarket/clob-client-v2
|
||||
npm install @polymarket/clob-client-v2 viem
|
||||
</p>
|
||||
</Card>
|
||||
|
||||
@@ -22,7 +22,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
</Card>
|
||||
|
||||
<Card title="Rust Client" icon="github" href="https://github.com/Polymarket/rs-clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket-client-sdk</p>
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket\_client\_sdk\_v2 --features clob</p>
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -51,9 +51,11 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
<CodeGroup>
|
||||
```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 signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive L2 API credentials
|
||||
const tempClient = new ClobClient({ host: "https://clob.polymarket.com", chain: 137, signer });
|
||||
@@ -61,21 +63,21 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive L2 API credentials
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
```
|
||||
|
||||
```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)?
|
||||
@@ -125,7 +127,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
client = ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
key=private_key,
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
funder="0x..." # Your proxy wallet address
|
||||
@@ -133,7 +135,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::SignatureType;
|
||||
use polymarket_client_sdk_v2::clob::types::SignatureType;
|
||||
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?
|
||||
.authentication_builder(&signer)
|
||||
@@ -192,7 +194,7 @@ If you're using the REST API directly (without the SDK), you need to attach auth
|
||||
</Card>
|
||||
|
||||
<Card title="Builder Methods" icon="hammer" href="/trading/clients/builder">
|
||||
Track attributed trades and manage builder credentials.
|
||||
Track orders and trades attributed to your builder code.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ Cancel all orders for a specific market, optionally filtered to a single token.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::CancelMarketOrderRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::CancelMarketOrderRequest;
|
||||
|
||||
let request = CancelMarketOrderRequest::builder()
|
||||
.market("0xbd31dc8a...".parse()?)
|
||||
@@ -191,7 +191,7 @@ Retrieve all open orders, optionally filtered by market or token:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -203,7 +203,7 @@ Retrieve all open orders, optionally filtered by market or token:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -262,7 +262,7 @@ When an order is matched, it creates a trade. Trades progress through these stat
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
trades = client.get_trades()
|
||||
|
||||
@@ -272,7 +272,7 @@ When an order is matched, it creates a trade. Trades progress through these stat
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -356,7 +356,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
scoring = client.is_order_scoring(
|
||||
OrderScoringParams(orderId="0x...")
|
||||
|
||||
@@ -106,6 +106,9 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -113,10 +116,10 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": True, # Required for multi-outcome markets
|
||||
}
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=True, # Required for multi-outcome markets
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -232,7 +235,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -246,7 +249,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -360,7 +363,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
# All trades
|
||||
trades = client.get_trades()
|
||||
@@ -374,7 +377,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -445,7 +448,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
# Single order
|
||||
scoring = client.is_order_scoring(
|
||||
|
||||
@@ -60,8 +60,8 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
@@ -70,10 +70,7 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTC
|
||||
)
|
||||
|
||||
@@ -82,8 +79,8 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let order = client
|
||||
@@ -132,10 +129,7 @@ For more control, you can separate signing from submission. This is useful for b
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
}
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)
|
||||
)
|
||||
|
||||
# Step 2: Submit to the CLOB
|
||||
@@ -197,17 +191,14 @@ GTD orders auto-expire at a specified time. Useful for quoting around known even
|
||||
side=BUY,
|
||||
expiration=expiration,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTD
|
||||
)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use polymarket_client_sdk::clob::types::OrderType;
|
||||
use polymarket_client_sdk_v2::clob::types::OrderType;
|
||||
|
||||
let order = client
|
||||
.limit_order()
|
||||
@@ -266,32 +257,36 @@ Market orders execute immediately against resting liquidity using FOK or FAK typ
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client.clob_types import OrderType
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import MarketOrderArgs, OrderType, PartialCreateOrderOptions
|
||||
|
||||
# FOK BUY: spend exactly $100 or cancel entirely
|
||||
buy_order = client.create_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100, # dollar amount
|
||||
price=0.50, # worst-price limit (slippage protection)
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100, # dollar amount
|
||||
price=0.50, # worst-price limit (slippage protection)
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
client.post_order(buy_order, OrderType.FOK)
|
||||
|
||||
# FOK SELL: sell exactly 200 shares or cancel entirely
|
||||
sell_order = client.create_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=SELL,
|
||||
amount=200, # number of shares
|
||||
price=0.45, # worst-price limit (slippage protection)
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=SELL,
|
||||
amount=200, # number of shares
|
||||
price=0.45, # worst-price limit (slippage protection)
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
client.post_order(sell_order, OrderType.FOK)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::{Amount, OrderType, Side};
|
||||
use polymarket_client_sdk_v2::clob::types::{Amount, OrderType, Side};
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
|
||||
@@ -347,12 +342,17 @@ For convenience, `createAndPostMarketOrder` handles creation, signing, and submi
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import MarketOrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100,
|
||||
price=0.50,
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100,
|
||||
price=0.50,
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.FOK,
|
||||
)
|
||||
```
|
||||
@@ -446,26 +446,26 @@ Place up to **15 orders** in a single request:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType, PostOrdersArgs
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PostOrdersV2Args, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
|
||||
response = client.post_orders([
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.48,
|
||||
size=500,
|
||||
side=BUY,
|
||||
token_id="TOKEN_ID",
|
||||
), options={"tick_size": "0.01", "neg_risk": False}),
|
||||
), options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)),
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.52,
|
||||
size=500,
|
||||
side=SELL,
|
||||
token_id="TOKEN_ID",
|
||||
), options={"tick_size": "0.01", "neg_risk": False}),
|
||||
), options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)),
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
])
|
||||
|
||||
@@ -60,8 +60,8 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
@@ -70,10 +70,7 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTC
|
||||
)
|
||||
|
||||
@@ -82,8 +79,8 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let order = client
|
||||
@@ -132,10 +129,7 @@ For more control, you can separate signing from submission. This is useful for b
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
}
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)
|
||||
)
|
||||
|
||||
# Step 2: Submit to the CLOB
|
||||
@@ -197,17 +191,14 @@ GTD orders auto-expire at a specified time. Useful for quoting around known even
|
||||
side=BUY,
|
||||
expiration=expiration,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTD
|
||||
)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use polymarket_client_sdk::clob::types::OrderType;
|
||||
use polymarket_client_sdk_v2::clob::types::OrderType;
|
||||
|
||||
let order = client
|
||||
.limit_order()
|
||||
@@ -266,32 +257,36 @@ Market orders execute immediately against resting liquidity using FOK or FAK typ
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client.clob_types import OrderType
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import MarketOrderArgs, OrderType, PartialCreateOrderOptions
|
||||
|
||||
# FOK BUY: spend exactly $100 or cancel entirely
|
||||
buy_order = client.create_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100, # dollar amount
|
||||
price=0.50, # worst-price limit (slippage protection)
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100, # dollar amount
|
||||
price=0.50, # worst-price limit (slippage protection)
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
client.post_order(buy_order, OrderType.FOK)
|
||||
|
||||
# FOK SELL: sell exactly 200 shares or cancel entirely
|
||||
sell_order = client.create_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=SELL,
|
||||
amount=200, # number of shares
|
||||
price=0.45, # worst-price limit (slippage protection)
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=SELL,
|
||||
amount=200, # number of shares
|
||||
price=0.45, # worst-price limit (slippage protection)
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
client.post_order(sell_order, OrderType.FOK)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::{Amount, OrderType, Side};
|
||||
use polymarket_client_sdk_v2::clob::types::{Amount, OrderType, Side};
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
|
||||
@@ -347,12 +342,17 @@ For convenience, `createAndPostMarketOrder` handles creation, signing, and submi
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import MarketOrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100,
|
||||
price=0.50,
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100,
|
||||
price=0.50,
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.FOK,
|
||||
)
|
||||
```
|
||||
@@ -446,26 +446,26 @@ Place up to **15 orders** in a single request:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType, PostOrdersArgs
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PostOrdersV2Args, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
|
||||
response = client.post_orders([
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.48,
|
||||
size=500,
|
||||
side=BUY,
|
||||
token_id="TOKEN_ID",
|
||||
), options={"tick_size": "0.01", "neg_risk": False}),
|
||||
), options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)),
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.52,
|
||||
size=500,
|
||||
side=SELL,
|
||||
token_id="TOKEN_ID",
|
||||
), options={"tick_size": "0.01", "neg_risk": False}),
|
||||
), options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)),
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
])
|
||||
|
||||
@@ -106,6 +106,9 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -113,10 +116,10 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": True, # Required for multi-outcome markets
|
||||
}
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=True, # Required for multi-outcome markets
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -232,7 +235,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -246,7 +249,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -360,7 +363,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
# All trades
|
||||
trades = client.get_trades()
|
||||
@@ -374,7 +377,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -445,7 +448,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
# Single order
|
||||
scoring = client.is_order_scoring(
|
||||
|
||||
@@ -106,6 +106,9 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -113,10 +116,10 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": True, # Required for multi-outcome markets
|
||||
}
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=True, # Required for multi-outcome markets
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -232,7 +235,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -246,7 +249,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -360,7 +363,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
# All trades
|
||||
trades = client.get_trades()
|
||||
@@ -374,7 +377,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -445,7 +448,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
# Single order
|
||||
scoring = client.is_order_scoring(
|
||||
|
||||
@@ -106,6 +106,9 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -113,10 +116,10 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": True, # Required for multi-outcome markets
|
||||
}
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=True, # Required for multi-outcome markets
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -232,7 +235,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -246,7 +249,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -360,7 +363,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
# All trades
|
||||
trades = client.get_trades()
|
||||
@@ -374,7 +377,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -445,7 +448,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
# Single order
|
||||
scoring = client.is_order_scoring(
|
||||
|
||||
@@ -106,6 +106,9 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -113,10 +116,10 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": True, # Required for multi-outcome markets
|
||||
}
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=True, # Required for multi-outcome markets
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -232,7 +235,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -246,7 +249,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -360,7 +363,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
# All trades
|
||||
trades = client.get_trades()
|
||||
@@ -374,7 +377,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -445,7 +448,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
# Single order
|
||||
scoring = client.is_order_scoring(
|
||||
|
||||
@@ -12,7 +12,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<Step title="Install the SDK">
|
||||
<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 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```bash Rust theme={null}
|
||||
cargo add polymarket-client-sdk --features clob
|
||||
cargo add polymarket_client_sdk_v2 --features clob
|
||||
```
|
||||
</CodeGroup>
|
||||
</Step>
|
||||
@@ -31,11 +31,13 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<CodeGroup>
|
||||
```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 HOST = "https://clob.polymarket.com";
|
||||
const CHAIN_ID = 137; // Polygon mainnet
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive API credentials
|
||||
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
|
||||
@@ -48,12 +50,12 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType: 0, // EOA
|
||||
funderAddress: signer.address,
|
||||
funderAddress: account.address,
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
host = "https://clob.polymarket.com"
|
||||
@@ -61,14 +63,14 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive API credentials
|
||||
temp_client = ClobClient(host, key=private_key, chain=chain)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient(host, key=private_key, chain_id=chain)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
|
||||
# Initialize trading client
|
||||
client = ClobClient(
|
||||
host,
|
||||
key=private_key,
|
||||
chain=chain,
|
||||
chain_id=chain,
|
||||
creds=api_creds,
|
||||
signature_type=0, # EOA
|
||||
funder="YOUR_WALLET_ADDRESS"
|
||||
@@ -77,9 +79,9 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
|
||||
```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)?
|
||||
@@ -132,8 +134,8 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
@@ -142,10 +144,10 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False, # Set to True for multi-outcome markets
|
||||
},
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=False, # Set to True for multi-outcome markets
|
||||
),
|
||||
order_type=OrderType.GTC
|
||||
)
|
||||
|
||||
@@ -154,8 +156,8 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "YOUR_TOKEN_ID".parse()?;
|
||||
|
||||
@@ -212,7 +214,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::{OrdersRequest, TradesRequest};
|
||||
use polymarket_client_sdk_v2::clob::types::request::{OrdersRequest, TradesRequest};
|
||||
|
||||
// View all open orders
|
||||
let open_orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -134,4 +134,4 @@ components:
|
||||
type: number
|
||||
format: float
|
||||
|
||||
````
|
||||
````
|
||||
@@ -13,7 +13,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
<CardGroup cols={3}>
|
||||
<Card title="TypeScript Client" icon="github" href="https://github.com/Polymarket/clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">
|
||||
npm install @polymarket/clob-client-v2
|
||||
npm install @polymarket/clob-client-v2 viem
|
||||
</p>
|
||||
</Card>
|
||||
|
||||
@@ -22,7 +22,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
</Card>
|
||||
|
||||
<Card title="Rust Client" icon="github" href="https://github.com/Polymarket/rs-clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket-client-sdk</p>
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket\_client\_sdk\_v2 --features clob</p>
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -51,9 +51,11 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
<CodeGroup>
|
||||
```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 signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive L2 API credentials
|
||||
const tempClient = new ClobClient({ host: "https://clob.polymarket.com", chain: 137, signer });
|
||||
@@ -61,21 +63,21 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive L2 API credentials
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
```
|
||||
|
||||
```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)?
|
||||
@@ -125,7 +127,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
client = ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
key=private_key,
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
funder="0x..." # Your proxy wallet address
|
||||
@@ -133,7 +135,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::SignatureType;
|
||||
use polymarket_client_sdk_v2::clob::types::SignatureType;
|
||||
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?
|
||||
.authentication_builder(&signer)
|
||||
@@ -192,7 +194,7 @@ If you're using the REST API directly (without the SDK), you need to attach auth
|
||||
</Card>
|
||||
|
||||
<Card title="Builder Methods" icon="hammer" href="/trading/clients/builder">
|
||||
Track attributed trades and manage builder credentials.
|
||||
Track orders and trades attributed to your builder code.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
<CardGroup cols={3}>
|
||||
<Card title="TypeScript Client" icon="github" href="https://github.com/Polymarket/clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">
|
||||
npm install @polymarket/clob-client-v2
|
||||
npm install @polymarket/clob-client-v2 viem
|
||||
</p>
|
||||
</Card>
|
||||
|
||||
@@ -22,7 +22,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
</Card>
|
||||
|
||||
<Card title="Rust Client" icon="github" href="https://github.com/Polymarket/rs-clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket-client-sdk</p>
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket\_client\_sdk\_v2 --features clob</p>
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -51,9 +51,11 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
<CodeGroup>
|
||||
```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 signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive L2 API credentials
|
||||
const tempClient = new ClobClient({ host: "https://clob.polymarket.com", chain: 137, signer });
|
||||
@@ -61,21 +63,21 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive L2 API credentials
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
```
|
||||
|
||||
```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)?
|
||||
@@ -125,7 +127,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
client = ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
key=private_key,
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
funder="0x..." # Your proxy wallet address
|
||||
@@ -133,7 +135,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::SignatureType;
|
||||
use polymarket_client_sdk_v2::clob::types::SignatureType;
|
||||
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?
|
||||
.authentication_builder(&signer)
|
||||
@@ -192,7 +194,7 @@ If you're using the REST API directly (without the SDK), you need to attach auth
|
||||
</Card>
|
||||
|
||||
<Card title="Builder Methods" icon="hammer" href="/trading/clients/builder">
|
||||
Track attributed trades and manage builder credentials.
|
||||
Track orders and trades attributed to your builder code.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
|
||||
@@ -20,11 +20,19 @@ Before merging, you need:
|
||||
2. **Condition ID** of the market
|
||||
3. **Sufficient gas** for the transaction
|
||||
|
||||
<Note>
|
||||
Polymarket uses thin collateral adapter contracts for pUSD-native CTF actions.
|
||||
Approve the adapter once, then route split, merge, and redeem actions through
|
||||
it. For merge flows, the adapter calls the underlying CTF contract, receives
|
||||
the released USDC.e collateral, wraps it into pUSD, and returns pUSD to your
|
||||
wallet automatically.
|
||||
</Note>
|
||||
|
||||
## How It Works
|
||||
|
||||
1. You call `mergePositions()` with the amount and market details
|
||||
1. You call the adapter's merge flow with the amount and market details
|
||||
2. One unit of each position in a full set is burned in return for 1 collateral unit
|
||||
3. The CTF contract releases pUSD back to your wallet
|
||||
3. The adapter converts the released collateral into pUSD and returns pUSD to your wallet
|
||||
|
||||
The operation is atomic — if you don't have enough of both tokens, the transaction reverts.
|
||||
|
||||
|
||||
@@ -41,6 +41,14 @@ Before redeeming:
|
||||
2. **Hold winning tokens** — only the winning outcome can be redeemed
|
||||
3. **Know the condition ID** — required for the redemption call
|
||||
|
||||
<Note>
|
||||
Polymarket uses thin collateral adapter contracts for pUSD-native CTF actions.
|
||||
Approve the adapter once, then route split, merge, and redeem actions through
|
||||
it. On redeem, the adapter burns the ERC1155 outcome tokens through the CTF
|
||||
contract, receives USDC.e collateral, wraps it into pUSD, and returns pUSD to
|
||||
your wallet automatically.
|
||||
</Note>
|
||||
|
||||
## Function Parameters
|
||||
|
||||
<ResponseField name="collateralToken" type="IERC20">
|
||||
@@ -74,11 +82,11 @@ The CTF uses a **payout vector** to determine redemption values:
|
||||
| Yes wins | `[1, 0]` | Yes = $1, No = $0 |
|
||||
| No wins | `[0, 1]` | Yes = $0, No = $1 |
|
||||
|
||||
When you call `redeemPositions()`:
|
||||
When you redeem through the adapter:
|
||||
|
||||
* Your token balance is multiplied by the payout
|
||||
* Winning tokens are burned
|
||||
* pUSD is transferred to your wallet
|
||||
* The released collateral is wrapped into pUSD and transferred to your wallet
|
||||
* Losing tokens are burned as well, but produce a \$0 payout
|
||||
|
||||
## Next Steps
|
||||
|
||||
@@ -17,9 +17,16 @@ $100 pUSD → 100 Yes tokens + 100 No tokens
|
||||
Before splitting, ensure you have:
|
||||
|
||||
1. **pUSD balance** on Polygon
|
||||
2. **pUSD approval** for the CTF contract to spend your tokens
|
||||
2. **pUSD approval** for the CTF collateral adapter to spend your tokens
|
||||
3. **Condition ID** of the market — the condition must already be prepared on the CTF contract (via `prepareCondition`)
|
||||
|
||||
<Note>
|
||||
Polymarket uses thin collateral adapter contracts for pUSD-native CTF actions.
|
||||
Approve the adapter once, then route split, merge, and redeem actions through
|
||||
it. The adapter handles the CTF collateral plumbing so user-facing flows stay
|
||||
in pUSD.
|
||||
</Note>
|
||||
|
||||
<Note>
|
||||
If the partition is trivial, invalid, or refers to more slots than the
|
||||
condition is prepared with, the transaction will revert.
|
||||
@@ -27,9 +34,9 @@ Before splitting, ensure you have:
|
||||
|
||||
## How It Works
|
||||
|
||||
1. You approve the CTF contract to spend your pUSD
|
||||
2. You call `splitPosition()` with the amount and market details
|
||||
3. The CTF contract transfers pUSD from your wallet and mints both outcome tokens
|
||||
1. You approve the CTF collateral adapter to spend your pUSD
|
||||
2. You call the adapter's split flow with the amount and market details
|
||||
3. The adapter calls the underlying CTF contract and mints both outcome tokens
|
||||
|
||||
The operation is atomic — if any step fails, the entire transaction reverts.
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ The Builder Program uses a tiered system to manage rate limits while rewarding h
|
||||
1. Go to [polymarket.com/settings?tab=builder](https://polymarket.com/settings?tab=builder)
|
||||
2. Create a builder profile
|
||||
3. Click **"+ Create New"** to generate API keys
|
||||
4. Implement [builder signing](/trading/orders/attribution) — required for Relayer access and CLOB order attribution
|
||||
4. Attach your [builder code](/trading/orders/attribution) to CLOB orders for attribution; use a Relayer API key for gasless wallet operations
|
||||
|
||||
**What's included:**
|
||||
|
||||
|
||||
@@ -57,13 +57,13 @@ Pass `builderCode` in the order struct on every order you submit. The SDK serial
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import ClobClient
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
key=private_key,
|
||||
creds=api_creds,
|
||||
signature_type=2,
|
||||
@@ -78,7 +78,7 @@ Pass `builderCode` in the order struct on every order you submit. The SDK serial
|
||||
side=BUY,
|
||||
builder_code="0xabc123...", # your builder code from polymarket.com/settings?tab=builder
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTC,
|
||||
)
|
||||
```
|
||||
|
||||
@@ -182,20 +182,20 @@ Before you can start market making, you need to complete these one-time setup st
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
credentials = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
credentials = temp_client.create_or_derive_api_key()
|
||||
```
|
||||
|
||||
```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)?
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -89,7 +89,7 @@ Once a market resolves:
|
||||
|
||||
### Redeeming Tokens
|
||||
|
||||
After resolution, call the `redeemPositions` function on the CTF contract to exchange winning tokens for pUSD. The contract burns your tokens and returns the corresponding collateral.
|
||||
After resolution, redeem through the CTF collateral adapter to exchange winning tokens for pUSD. The adapter burns your ERC1155 outcome tokens through the CTF contract, receives the released USDC.e collateral, wraps it into pUSD, and returns pUSD to your wallet.
|
||||
|
||||
```
|
||||
100 winning tokens → $100 pUSD
|
||||
|
||||
@@ -182,20 +182,20 @@ Before you can start market making, you need to complete these one-time setup st
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
credentials = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
credentials = temp_client.create_or_derive_api_key()
|
||||
```
|
||||
|
||||
```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)?
|
||||
|
||||
@@ -97,9 +97,9 @@ Split converts pUSD into equal amounts of YES and NO tokens — creating the inv
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::ctf::Client as CtfClient;
|
||||
use polymarket_client_sdk::ctf::types::SplitPositionRequest;
|
||||
use polymarket_client_sdk::types::{U256, address};
|
||||
use polymarket_client_sdk_v2::ctf::Client as CtfClient;
|
||||
use polymarket_client_sdk_v2::ctf::types::SplitPositionRequest;
|
||||
use polymarket_client_sdk_v2::types::{U256, address};
|
||||
|
||||
let ctf_client = CtfClient::new(provider, 137)?;
|
||||
|
||||
@@ -181,7 +181,7 @@ Merge converts equal amounts of YES and NO tokens back into pUSD — useful for
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::ctf::types::MergePositionsRequest;
|
||||
use polymarket_client_sdk_v2::ctf::types::MergePositionsRequest;
|
||||
|
||||
// Merge 500 YES + 500 NO back to 500 pUSD
|
||||
let request = MergePositionsRequest::builder()
|
||||
@@ -282,7 +282,7 @@ Once a market resolves, redeem winning tokens for pUSD. Each winning token is wo
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::ctf::types::RedeemPositionsRequest;
|
||||
use polymarket_client_sdk_v2::ctf::types::RedeemPositionsRequest;
|
||||
|
||||
let request = RedeemPositionsRequest::builder()
|
||||
.collateral_token(address!("0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB"))
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
> Fetch the complete documentation index at: https://docs.polymarket.com/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Maker rebates
|
||||
# Maker Rebates Program
|
||||
|
||||
***
|
||||
|
||||
title: "Maker Rebates Program"
|
||||
description: "Earn daily USDC rebates by providing liquidity on Polymarket"
|
||||
---------------------------------------------------------------------------
|
||||
> Earn daily USDC rebates by providing liquidity on Polymarket
|
||||
|
||||
Polymarket charges taker fees across multiple market categories. Fees are determined by the protocol at match time and fund a **Maker Rebates** program that pays daily USDC rebates to liquidity providers.
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ The core market making workflow is posting a bid and ask around your fair value.
|
||||
side: Side.BUY,
|
||||
price: 0.48,
|
||||
size: 1000,
|
||||
orderType: OrderType.GTC,
|
||||
});
|
||||
|
||||
// Ask at 0.52
|
||||
@@ -48,13 +47,12 @@ The core market making workflow is posting a bid and ask around your fair value.
|
||||
side: Side.SELL,
|
||||
price: 0.52,
|
||||
size: 1000,
|
||||
orderType: OrderType.GTC,
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import OrderArgs, OrderType
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
|
||||
token_id = "3409705850427531082723332342151729..."
|
||||
|
||||
@@ -72,8 +70,8 @@ The core market making workflow is posting a bid and ask around your fair value.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "3409705850427531082723332342151729...".parse()?;
|
||||
|
||||
@@ -112,33 +110,33 @@ For tighter spreads across multiple levels, use `postOrders` to submit up to 15
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType, PostOrdersArgs
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PostOrdersV2Args
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
|
||||
response = client.post_orders([
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.48, size=500, side=BUY, token_id=token_id,
|
||||
)),
|
||||
order_type=OrderType.GTC,
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.47, size=500, side=BUY, token_id=token_id,
|
||||
)),
|
||||
order_type=OrderType.GTC,
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.52, size=500, side=SELL, token_id=token_id,
|
||||
)),
|
||||
order_type=OrderType.GTC,
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.53, size=500, side=SELL, token_id=token_id,
|
||||
)),
|
||||
order_type=OrderType.GTC,
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
])
|
||||
```
|
||||
@@ -184,21 +182,26 @@ Auto-expire quotes before known events like market close or resolution:
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
// Expire in 1 hour
|
||||
const expiringOrder = await client.createOrder({
|
||||
tokenID,
|
||||
side: Side.BUY,
|
||||
price: 0.5,
|
||||
size: 1000,
|
||||
orderType: OrderType.GTD,
|
||||
expiration: Math.floor(Date.now() / 1000) + 3600,
|
||||
});
|
||||
const expiringOrder = await client.createAndPostOrder(
|
||||
{
|
||||
tokenID,
|
||||
side: Side.BUY,
|
||||
price: 0.5,
|
||||
size: 1000,
|
||||
expiration: Math.floor(Date.now() / 1000) + 3600,
|
||||
},
|
||||
undefined,
|
||||
OrderType.GTD,
|
||||
);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
import time
|
||||
from py_clob_client_v2 import OrderArgs, OrderType
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
# Expire in 1 hour
|
||||
expiring_order = client.create_order(
|
||||
expiring_order = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id=token_id,
|
||||
side=BUY,
|
||||
@@ -212,7 +215,7 @@ Auto-expire quotes before known events like market close or resolution:
|
||||
|
||||
```rust Rust theme={null}
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use polymarket_client_sdk::clob::types::OrderType;
|
||||
use polymarket_client_sdk_v2::clob::types::OrderType;
|
||||
|
||||
// Expire in 1 hour
|
||||
let order = client.limit_order()
|
||||
@@ -272,7 +275,7 @@ See [Cancel Orders](/trading/orders/cancel) for full details.
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
order = client.get_order(order_id)
|
||||
|
||||
@@ -282,7 +285,7 @@ See [Cancel Orders](/trading/orders/cancel) for full details.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
let order = client.order(order_id).await?;
|
||||
|
||||
|
||||
+22
-24
@@ -52,8 +52,8 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
|
||||
<Tab title="Rust">
|
||||
```rust theme={null}
|
||||
use polymarket_client_sdk::gamma::Client;
|
||||
use polymarket_client_sdk::gamma::types::request::MarketsRequest;
|
||||
use polymarket_client_sdk_v2::gamma::Client;
|
||||
use polymarket_client_sdk_v2::gamma::types::request::MarketsRequest;
|
||||
|
||||
let client = Client::default();
|
||||
|
||||
@@ -77,7 +77,7 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
<Step title="Install the SDK">
|
||||
<CodeGroup>
|
||||
```bash TypeScript theme={null}
|
||||
npm install @polymarket/clob-client-v2 ethers@5
|
||||
npm install @polymarket/clob-client-v2 viem
|
||||
```
|
||||
|
||||
```bash Python theme={null}
|
||||
@@ -85,7 +85,7 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
```
|
||||
|
||||
```bash Rust theme={null}
|
||||
cargo add polymarket-client-sdk
|
||||
cargo add polymarket_client_sdk_v2 --features gamma,clob
|
||||
```
|
||||
</CodeGroup>
|
||||
</Step>
|
||||
@@ -97,11 +97,13 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
<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 HOST = "https://clob.polymarket.com";
|
||||
const CHAIN_ID = 137; // Polygon mainnet
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive API credentials (L1 → L2 auth)
|
||||
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
|
||||
@@ -114,14 +116,14 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType: 0, // Signature type: 0 = EOA
|
||||
funderAddress: signer.address, // Funder address
|
||||
funderAddress: account.address, // Funder address
|
||||
});
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
host = "https://clob.polymarket.com"
|
||||
@@ -129,14 +131,14 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive API credentials (L1 → L2 auth)
|
||||
temp_client = ClobClient(host, key=private_key, chain=chain)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient(host, key=private_key, chain_id=chain)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
|
||||
# Initialize trading client
|
||||
client = ClobClient(
|
||||
host,
|
||||
key=private_key,
|
||||
chain=chain,
|
||||
chain_id=chain,
|
||||
creds=api_creds,
|
||||
signature_type=0, # Signature type: 0 = EOA
|
||||
funder="YOUR_WALLET_ADDRESS", # Funder address
|
||||
@@ -147,9 +149,9 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
<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)?
|
||||
@@ -197,7 +199,6 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
price: 0.50,
|
||||
size: 10,
|
||||
side: Side.BUY,
|
||||
orderType: OrderType.GTC,
|
||||
},
|
||||
{
|
||||
tickSize,
|
||||
@@ -212,8 +213,8 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
# Fetch market details to get tick size and neg risk
|
||||
market = client.get_market("YOUR_CONDITION_ID")
|
||||
@@ -226,12 +227,9 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
price=0.50,
|
||||
size=10,
|
||||
side=BUY,
|
||||
order_type=OrderType.GTC,
|
||||
),
|
||||
options={
|
||||
"tick_size": tick_size,
|
||||
"neg_risk": neg_risk,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size=tick_size, neg_risk=neg_risk),
|
||||
order_type=OrderType.GTC,
|
||||
)
|
||||
|
||||
print("Order ID:", response["orderID"])
|
||||
@@ -241,8 +239,8 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
|
||||
<Tab title="Rust">
|
||||
```rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
// token_id is a U256 — parse from the string returned in Step 1
|
||||
let token_id = "YOUR_TOKEN_ID".parse()?;
|
||||
|
||||
@@ -12,7 +12,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<Step title="Install the SDK">
|
||||
<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 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```bash Rust theme={null}
|
||||
cargo add polymarket-client-sdk --features clob
|
||||
cargo add polymarket_client_sdk_v2 --features clob
|
||||
```
|
||||
</CodeGroup>
|
||||
</Step>
|
||||
@@ -31,11 +31,13 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<CodeGroup>
|
||||
```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 HOST = "https://clob.polymarket.com";
|
||||
const CHAIN_ID = 137; // Polygon mainnet
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive API credentials
|
||||
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
|
||||
@@ -48,12 +50,12 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType: 0, // EOA
|
||||
funderAddress: signer.address,
|
||||
funderAddress: account.address,
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
host = "https://clob.polymarket.com"
|
||||
@@ -61,14 +63,14 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive API credentials
|
||||
temp_client = ClobClient(host, key=private_key, chain=chain)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient(host, key=private_key, chain_id=chain)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
|
||||
# Initialize trading client
|
||||
client = ClobClient(
|
||||
host,
|
||||
key=private_key,
|
||||
chain=chain,
|
||||
chain_id=chain,
|
||||
creds=api_creds,
|
||||
signature_type=0, # EOA
|
||||
funder="YOUR_WALLET_ADDRESS"
|
||||
@@ -77,9 +79,9 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
|
||||
```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)?
|
||||
@@ -132,8 +134,8 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
@@ -142,10 +144,10 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False, # Set to True for multi-outcome markets
|
||||
},
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=False, # Set to True for multi-outcome markets
|
||||
),
|
||||
order_type=OrderType.GTC
|
||||
)
|
||||
|
||||
@@ -154,8 +156,8 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "YOUR_TOKEN_ID".parse()?;
|
||||
|
||||
@@ -212,7 +214,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::{OrdersRequest, TradesRequest};
|
||||
use polymarket_client_sdk_v2::clob::types::request::{OrdersRequest, TradesRequest};
|
||||
|
||||
// View all open orders
|
||||
let open_orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
|
||||
+22
-24
@@ -52,8 +52,8 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
|
||||
<Tab title="Rust">
|
||||
```rust theme={null}
|
||||
use polymarket_client_sdk::gamma::Client;
|
||||
use polymarket_client_sdk::gamma::types::request::MarketsRequest;
|
||||
use polymarket_client_sdk_v2::gamma::Client;
|
||||
use polymarket_client_sdk_v2::gamma::types::request::MarketsRequest;
|
||||
|
||||
let client = Client::default();
|
||||
|
||||
@@ -77,7 +77,7 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
<Step title="Install the SDK">
|
||||
<CodeGroup>
|
||||
```bash TypeScript theme={null}
|
||||
npm install @polymarket/clob-client-v2 ethers@5
|
||||
npm install @polymarket/clob-client-v2 viem
|
||||
```
|
||||
|
||||
```bash Python theme={null}
|
||||
@@ -85,7 +85,7 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
```
|
||||
|
||||
```bash Rust theme={null}
|
||||
cargo add polymarket-client-sdk
|
||||
cargo add polymarket_client_sdk_v2 --features gamma,clob
|
||||
```
|
||||
</CodeGroup>
|
||||
</Step>
|
||||
@@ -97,11 +97,13 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
<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 HOST = "https://clob.polymarket.com";
|
||||
const CHAIN_ID = 137; // Polygon mainnet
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive API credentials (L1 → L2 auth)
|
||||
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
|
||||
@@ -114,14 +116,14 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType: 0, // Signature type: 0 = EOA
|
||||
funderAddress: signer.address, // Funder address
|
||||
funderAddress: account.address, // Funder address
|
||||
});
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
host = "https://clob.polymarket.com"
|
||||
@@ -129,14 +131,14 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive API credentials (L1 → L2 auth)
|
||||
temp_client = ClobClient(host, key=private_key, chain=chain)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient(host, key=private_key, chain_id=chain)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
|
||||
# Initialize trading client
|
||||
client = ClobClient(
|
||||
host,
|
||||
key=private_key,
|
||||
chain=chain,
|
||||
chain_id=chain,
|
||||
creds=api_creds,
|
||||
signature_type=0, # Signature type: 0 = EOA
|
||||
funder="YOUR_WALLET_ADDRESS", # Funder address
|
||||
@@ -147,9 +149,9 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
<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)?
|
||||
@@ -197,7 +199,6 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
price: 0.50,
|
||||
size: 10,
|
||||
side: Side.BUY,
|
||||
orderType: OrderType.GTC,
|
||||
},
|
||||
{
|
||||
tickSize,
|
||||
@@ -212,8 +213,8 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
# Fetch market details to get tick size and neg risk
|
||||
market = client.get_market("YOUR_CONDITION_ID")
|
||||
@@ -226,12 +227,9 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
price=0.50,
|
||||
size=10,
|
||||
side=BUY,
|
||||
order_type=OrderType.GTC,
|
||||
),
|
||||
options={
|
||||
"tick_size": tick_size,
|
||||
"neg_risk": neg_risk,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size=tick_size, neg_risk=neg_risk),
|
||||
order_type=OrderType.GTC,
|
||||
)
|
||||
|
||||
print("Order ID:", response["orderID"])
|
||||
@@ -241,8 +239,8 @@ Get up and running with the Polymarket API in minutes — fetch market data and
|
||||
|
||||
<Tab title="Rust">
|
||||
```rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
// token_id is a U256 — parse from the string returned in Step 1
|
||||
let token_id = "YOUR_TOKEN_ID".parse()?;
|
||||
|
||||
@@ -37,14 +37,14 @@ Builder attribution in V2 is handled natively through the order struct — you a
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client.clob_types import OrderArgs
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import ClobClient
|
||||
from py_clob_client_v2 import 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=creds,
|
||||
signature_type=signature_type,
|
||||
@@ -60,7 +60,7 @@ Builder attribution in V2 is handled natively through the order struct — you a
|
||||
side=BUY,
|
||||
builder_code=os.environ["POLY_BUILDER_CODE"],
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -14,9 +14,11 @@ L1 methods require the client to initialize with a signer.
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers";
|
||||
import { createWalletClient, http } from "viem";
|
||||
import { privateKeyToAccount } from "viem/accounts";
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
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",
|
||||
@@ -31,14 +33,14 @@ L1 methods require the client to initialize with a signer.
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
key=private_key # Signer required for L1 methods
|
||||
)
|
||||
|
||||
@@ -134,6 +136,13 @@ async createOrDeriveApiKey(nonce?: number): Promise<ApiKeyCreds>
|
||||
|
||||
## Order Signing
|
||||
|
||||
<Note>
|
||||
In CLOB V2, `expiration` is still accepted in order payloads for GTD/order
|
||||
expiry handling, but it is not part of the EIP-712 signed order struct. The
|
||||
signed struct uses `timestamp`, `metadata`, and `builder` instead of the V1
|
||||
`expiration`, `nonce`, `feeRateBps`, and `taker` fields.
|
||||
</Note>
|
||||
|
||||
### createOrder
|
||||
|
||||
Create and sign a limit order locally without posting it to the CLOB. Use this when you want to sign orders in advance or implement custom submission logic. Submit via [`postOrder()`](/trading/clients/l2#postorder) or [`postOrders()`](/trading/clients/l2#postorders).
|
||||
@@ -162,7 +171,8 @@ async createOrder(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="number">
|
||||
Optional expiration timestamp for the order. Optional.
|
||||
Optional expiration timestamp included in the order payload for GTD/order
|
||||
expiry handling. This is not part of the CLOB V2 EIP-712 signed order struct.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tickSize" type="TickSize">
|
||||
@@ -202,7 +212,22 @@ async createOrder(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="string">
|
||||
The expiration timestamp as a string.
|
||||
The expiration timestamp included in the order payload. This is not part of
|
||||
the CLOB V2 EIP-712 signed order struct.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="timestamp" type="string">
|
||||
Order creation timestamp in milliseconds, used for order uniqueness in CLOB
|
||||
V2.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="metadata" type="string">
|
||||
Reserved `bytes32` metadata field.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="builder" type="string">
|
||||
Builder code (`bytes32`) for attribution, or zero if no builder code is
|
||||
attached.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="signatureType" type="number">
|
||||
@@ -275,7 +300,22 @@ async createMarketOrder(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="string">
|
||||
The expiration timestamp as a string.
|
||||
The expiration timestamp included in the order payload. This is not part of
|
||||
the CLOB V2 EIP-712 signed order struct.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="timestamp" type="string">
|
||||
Order creation timestamp in milliseconds, used for order uniqueness in CLOB
|
||||
V2.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="metadata" type="string">
|
||||
Reserved `bytes32` metadata field.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="builder" type="string">
|
||||
Builder code (`bytes32`) for attribution, or zero if no builder code is
|
||||
attached.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="signatureType" type="number">
|
||||
|
||||
@@ -14,12 +14,14 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers";
|
||||
import { createWalletClient, http } from "viem";
|
||||
import { privateKeyToAccount } from "viem/accounts";
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
const apiCreds = {
|
||||
apiKey: process.env.API_KEY,
|
||||
key: process.env.API_KEY,
|
||||
secret: process.env.SECRET,
|
||||
passphrase: process.env.PASSPHRASE,
|
||||
};
|
||||
@@ -40,8 +42,8 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client.clob_types import ApiCreds
|
||||
from py_clob_client_v2 import ClobClient
|
||||
from py_clob_client_v2 import ApiCreds
|
||||
import os
|
||||
|
||||
api_creds = ApiCreds(
|
||||
@@ -52,7 +54,7 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
key=os.getenv("PRIVATE_KEY"),
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
|
||||
@@ -27,11 +27,11 @@ Public methods require the client to initialize with the host URL and Polygon ch
|
||||
|
||||
<Tab title="Python">
|
||||
```python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137
|
||||
chain_id=137
|
||||
)
|
||||
|
||||
# Ready to call public methods
|
||||
|
||||
@@ -20,11 +20,19 @@ Before merging, you need:
|
||||
2. **Condition ID** of the market
|
||||
3. **Sufficient gas** for the transaction
|
||||
|
||||
<Note>
|
||||
Polymarket uses thin collateral adapter contracts for pUSD-native CTF actions.
|
||||
Approve the adapter once, then route split, merge, and redeem actions through
|
||||
it. For merge flows, the adapter calls the underlying CTF contract, receives
|
||||
the released USDC.e collateral, wraps it into pUSD, and returns pUSD to your
|
||||
wallet automatically.
|
||||
</Note>
|
||||
|
||||
## How It Works
|
||||
|
||||
1. You call `mergePositions()` with the amount and market details
|
||||
1. You call the adapter's merge flow with the amount and market details
|
||||
2. One unit of each position in a full set is burned in return for 1 collateral unit
|
||||
3. The CTF contract releases pUSD back to your wallet
|
||||
3. The adapter converts the released collateral into pUSD and returns pUSD to your wallet
|
||||
|
||||
The operation is atomic — if you don't have enough of both tokens, the transaction reverts.
|
||||
|
||||
|
||||
@@ -41,6 +41,14 @@ Before redeeming:
|
||||
2. **Hold winning tokens** — only the winning outcome can be redeemed
|
||||
3. **Know the condition ID** — required for the redemption call
|
||||
|
||||
<Note>
|
||||
Polymarket uses thin collateral adapter contracts for pUSD-native CTF actions.
|
||||
Approve the adapter once, then route split, merge, and redeem actions through
|
||||
it. On redeem, the adapter burns the ERC1155 outcome tokens through the CTF
|
||||
contract, receives USDC.e collateral, wraps it into pUSD, and returns pUSD to
|
||||
your wallet automatically.
|
||||
</Note>
|
||||
|
||||
## Function Parameters
|
||||
|
||||
<ResponseField name="collateralToken" type="IERC20">
|
||||
@@ -74,11 +82,11 @@ The CTF uses a **payout vector** to determine redemption values:
|
||||
| Yes wins | `[1, 0]` | Yes = $1, No = $0 |
|
||||
| No wins | `[0, 1]` | Yes = $0, No = $1 |
|
||||
|
||||
When you call `redeemPositions()`:
|
||||
When you redeem through the adapter:
|
||||
|
||||
* Your token balance is multiplied by the payout
|
||||
* Winning tokens are burned
|
||||
* pUSD is transferred to your wallet
|
||||
* The released collateral is wrapped into pUSD and transferred to your wallet
|
||||
* Losing tokens are burned as well, but produce a \$0 payout
|
||||
|
||||
## Next Steps
|
||||
|
||||
@@ -17,9 +17,16 @@ $100 pUSD → 100 Yes tokens + 100 No tokens
|
||||
Before splitting, ensure you have:
|
||||
|
||||
1. **pUSD balance** on Polygon
|
||||
2. **pUSD approval** for the CTF contract to spend your tokens
|
||||
2. **pUSD approval** for the CTF collateral adapter to spend your tokens
|
||||
3. **Condition ID** of the market — the condition must already be prepared on the CTF contract (via `prepareCondition`)
|
||||
|
||||
<Note>
|
||||
Polymarket uses thin collateral adapter contracts for pUSD-native CTF actions.
|
||||
Approve the adapter once, then route split, merge, and redeem actions through
|
||||
it. The adapter handles the CTF collateral plumbing so user-facing flows stay
|
||||
in pUSD.
|
||||
</Note>
|
||||
|
||||
<Note>
|
||||
If the partition is trivial, invalid, or refers to more slots than the
|
||||
condition is prepared with, the transaction will revert.
|
||||
@@ -27,9 +34,9 @@ Before splitting, ensure you have:
|
||||
|
||||
## How It Works
|
||||
|
||||
1. You approve the CTF contract to spend your pUSD
|
||||
2. You call `splitPosition()` with the amount and market details
|
||||
3. The CTF contract transfers pUSD from your wallet and mints both outcome tokens
|
||||
1. You approve the CTF collateral adapter to spend your pUSD
|
||||
2. You call the adapter's split flow with the amount and market details
|
||||
3. The adapter calls the underlying CTF contract and mints both outcome tokens
|
||||
|
||||
The operation is atomic — if any step fails, the entire transaction reverts.
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@ Polymarket pays gas for all operations routed through the relayer:
|
||||
|
||||
The relayer uses **Relayer API Keys**. You can create one from [Settings > API Keys](https://polymarket.com/settings?tab=api-keys) on the Polymarket website.
|
||||
|
||||
<Note>
|
||||
**Already have a builder signing key?** Your existing HMAC-based builder API key keeps working with the Relayer — no need to rotate or reissue. Only order-signing moved to the native `builderCode` field in CLOB V2. See [Migrating to CLOB V2](/v2-migration#builder-program) for context.
|
||||
</Note>
|
||||
|
||||
Include these headers with your requests:
|
||||
|
||||
| Header | Description |
|
||||
|
||||
+12
-12
@@ -16,15 +16,15 @@ The orderbook is a public endpoint — no authentication required. You can read
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
|
||||
client = ClobClient("https://clob.polymarket.com", chain=137)
|
||||
client = ClobClient("https://clob.polymarket.com", chain_id=137)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::Client;
|
||||
use polymarket_client_sdk_v2::clob::{Client, Config};
|
||||
|
||||
let client = Client::default(); // https://clob.polymarket.com
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?;
|
||||
```
|
||||
|
||||
```bash REST theme={null}
|
||||
@@ -57,7 +57,7 @@ Fetch the full orderbook for a token, including all resting bid and ask levels:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrderBookSummaryRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrderBookSummaryRequest;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let request = OrderBookSummaryRequest::builder().token_id(token_id).build();
|
||||
@@ -130,7 +130,7 @@ Get the best available price for buying or selling a token:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::{Side, request::PriceRequest};
|
||||
use polymarket_client_sdk_v2::clob::types::{Side, request::PriceRequest};
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
|
||||
@@ -170,7 +170,7 @@ The midpoint is the average of the best bid and best ask. This is the price disp
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::MidpointRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::MidpointRequest;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let request = MidpointRequest::builder().token_id(token_id).build();
|
||||
@@ -206,7 +206,7 @@ The spread is the difference between the best ask and the best bid. Tighter spre
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::SpreadRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::SpreadRequest;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let request = SpreadRequest::builder().token_id(token_id).build();
|
||||
@@ -256,7 +256,7 @@ Fetch historical price data for a token over various time intervals:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::{Interval, TimeRange, request::PriceHistoryRequest};
|
||||
use polymarket_client_sdk_v2::clob::types::{Interval, TimeRange, request::PriceHistoryRequest};
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let request = PriceHistoryRequest::builder()
|
||||
@@ -316,7 +316,7 @@ Calculate the effective price you'd pay for a market order of a given size, acco
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderType
|
||||
from py_clob_client_v2 import OrderType
|
||||
|
||||
price = client.calculate_market_price(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -384,7 +384,7 @@ All orderbook queries have batch variants for fetching data across multiple toke
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::{Side, request::PriceRequest};
|
||||
use polymarket_client_sdk_v2::clob::types::{Side, request::PriceRequest};
|
||||
|
||||
let token_a = "TOKEN_A".parse()?;
|
||||
let token_b = "TOKEN_B".parse()?;
|
||||
@@ -424,7 +424,7 @@ Get the price and side of the most recent trade for a token:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::LastTradePriceRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::LastTradePriceRequest;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let request = LastTradePriceRequest::builder().token_id(token_id).build();
|
||||
|
||||
@@ -57,13 +57,13 @@ Pass `builderCode` in the order struct on every order you submit. The SDK serial
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import ClobClient
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
key=private_key,
|
||||
creds=api_creds,
|
||||
signature_type=2,
|
||||
@@ -78,7 +78,7 @@ Pass `builderCode` in the order struct on every order you submit. The SDK serial
|
||||
side=BUY,
|
||||
builder_code="0xabc123...", # your builder code from polymarket.com/settings?tab=builder
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTC,
|
||||
)
|
||||
```
|
||||
|
||||
@@ -126,7 +126,7 @@ Cancel all orders for a specific market, optionally filtered to a single token.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::CancelMarketOrderRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::CancelMarketOrderRequest;
|
||||
|
||||
let request = CancelMarketOrderRequest::builder()
|
||||
.market("0xbd31dc8a...".parse()?)
|
||||
@@ -191,7 +191,7 @@ Retrieve all open orders, optionally filtered by market or token:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -203,7 +203,7 @@ Retrieve all open orders, optionally filtered by market or token:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -262,7 +262,7 @@ When an order is matched, it creates a trade. Trades progress through these stat
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
trades = client.get_trades()
|
||||
|
||||
@@ -272,7 +272,7 @@ When an order is matched, it creates a trade. Trades progress through these stat
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -356,7 +356,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
scoring = client.is_order_scoring(
|
||||
OrderScoringParams(orderId="0x...")
|
||||
|
||||
@@ -60,8 +60,8 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
@@ -70,10 +70,7 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTC
|
||||
)
|
||||
|
||||
@@ -82,8 +79,8 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
let order = client
|
||||
@@ -132,10 +129,7 @@ For more control, you can separate signing from submission. This is useful for b
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
}
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)
|
||||
)
|
||||
|
||||
# Step 2: Submit to the CLOB
|
||||
@@ -197,17 +191,14 @@ GTD orders auto-expire at a specified time. Useful for quoting around known even
|
||||
side=BUY,
|
||||
expiration=expiration,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False,
|
||||
},
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.GTD
|
||||
)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use polymarket_client_sdk::clob::types::OrderType;
|
||||
use polymarket_client_sdk_v2::clob::types::OrderType;
|
||||
|
||||
let order = client
|
||||
.limit_order()
|
||||
@@ -266,32 +257,36 @@ Market orders execute immediately against resting liquidity using FOK or FAK typ
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client.clob_types import OrderType
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import MarketOrderArgs, OrderType, PartialCreateOrderOptions
|
||||
|
||||
# FOK BUY: spend exactly $100 or cancel entirely
|
||||
buy_order = client.create_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100, # dollar amount
|
||||
price=0.50, # worst-price limit (slippage protection)
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100, # dollar amount
|
||||
price=0.50, # worst-price limit (slippage protection)
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
client.post_order(buy_order, OrderType.FOK)
|
||||
|
||||
# FOK SELL: sell exactly 200 shares or cancel entirely
|
||||
sell_order = client.create_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=SELL,
|
||||
amount=200, # number of shares
|
||||
price=0.45, # worst-price limit (slippage protection)
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=SELL,
|
||||
amount=200, # number of shares
|
||||
price=0.45, # worst-price limit (slippage protection)
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
)
|
||||
client.post_order(sell_order, OrderType.FOK)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::{Amount, OrderType, Side};
|
||||
use polymarket_client_sdk_v2::clob::types::{Amount, OrderType, Side};
|
||||
|
||||
let token_id = "TOKEN_ID".parse()?;
|
||||
|
||||
@@ -347,12 +342,17 @@ For convenience, `createAndPostMarketOrder` handles creation, signing, and submi
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import MarketOrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_market_order(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100,
|
||||
price=0.50,
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_args=MarketOrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
side=BUY,
|
||||
amount=100,
|
||||
price=0.50,
|
||||
),
|
||||
options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False),
|
||||
order_type=OrderType.FOK,
|
||||
)
|
||||
```
|
||||
@@ -446,26 +446,26 @@ Place up to **15 orders** in a single request:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType, PostOrdersArgs
|
||||
from py_clob_client.order_builder.constants import BUY, SELL
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PostOrdersV2Args, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY, SELL
|
||||
|
||||
response = client.post_orders([
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.48,
|
||||
size=500,
|
||||
side=BUY,
|
||||
token_id="TOKEN_ID",
|
||||
), options={"tick_size": "0.01", "neg_risk": False}),
|
||||
), options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)),
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
PostOrdersArgs(
|
||||
PostOrdersV2Args(
|
||||
order=client.create_order(OrderArgs(
|
||||
price=0.52,
|
||||
size=500,
|
||||
side=SELL,
|
||||
token_id="TOKEN_ID",
|
||||
), options={"tick_size": "0.01", "neg_risk": False}),
|
||||
), options=PartialCreateOrderOptions(tick_size="0.01", neg_risk=False)),
|
||||
orderType=OrderType.GTC,
|
||||
),
|
||||
])
|
||||
|
||||
@@ -106,6 +106,9 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client_v2 import OrderArgs, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="TOKEN_ID",
|
||||
@@ -113,10 +116,10 @@ Multi-outcome events (e.g., "Who will win the election?" with 3+ candidates) use
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": True, # Required for multi-outcome markets
|
||||
}
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=True, # Required for multi-outcome markets
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -232,7 +235,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OpenOrderParams
|
||||
from py_clob_client_v2 import OpenOrderParams
|
||||
|
||||
# All open orders
|
||||
orders = client.get_orders()
|
||||
@@ -246,7 +249,7 @@ Retrieve your open orders, optionally filtered by market or asset:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::OrdersRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::OrdersRequest;
|
||||
|
||||
// All open orders
|
||||
let orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
@@ -360,7 +363,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import TradeParams
|
||||
from py_clob_client_v2 import TradeParams
|
||||
|
||||
# All trades
|
||||
trades = client.get_trades()
|
||||
@@ -374,7 +377,7 @@ Retrieve your trades with the SDK:
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
use polymarket_client_sdk_v2::clob::types::request::TradesRequest;
|
||||
|
||||
// All trades
|
||||
let trades = client.trades(&TradesRequest::default(), None).await?;
|
||||
@@ -445,7 +448,7 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderScoringParams, OrdersScoringParams
|
||||
from py_clob_client_v2 import OrderScoringParams, OrdersScoringParams
|
||||
|
||||
# Single order
|
||||
scoring = client.is_order_scoring(
|
||||
|
||||
+15
-13
@@ -13,7 +13,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
<CardGroup cols={3}>
|
||||
<Card title="TypeScript Client" icon="github" href="https://github.com/Polymarket/clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">
|
||||
npm install @polymarket/clob-client-v2
|
||||
npm install @polymarket/clob-client-v2 viem
|
||||
</p>
|
||||
</Card>
|
||||
|
||||
@@ -22,7 +22,7 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
</Card>
|
||||
|
||||
<Card title="Rust Client" icon="github" href="https://github.com/Polymarket/rs-clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket-client-sdk</p>
|
||||
<p className="font-mono text-[0.8rem]">cargo add polymarket\_client\_sdk\_v2 --features clob</p>
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -51,9 +51,11 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
<CodeGroup>
|
||||
```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 signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive L2 API credentials
|
||||
const tempClient = new ClobClient({ host: "https://clob.polymarket.com", chain: 137, signer });
|
||||
@@ -61,21 +63,21 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive L2 API credentials
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
```
|
||||
|
||||
```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)?
|
||||
@@ -125,7 +127,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
client = ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
key=private_key,
|
||||
chain=137,
|
||||
chain_id=137,
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
funder="0x..." # Your proxy wallet address
|
||||
@@ -133,7 +135,7 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::SignatureType;
|
||||
use polymarket_client_sdk_v2::clob::types::SignatureType;
|
||||
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?
|
||||
.authentication_builder(&signer)
|
||||
@@ -192,7 +194,7 @@ If you're using the REST API directly (without the SDK), you need to attach auth
|
||||
</Card>
|
||||
|
||||
<Card title="Builder Methods" icon="hammer" href="/trading/clients/builder">
|
||||
Track attributed trades and manage builder credentials.
|
||||
Track orders and trades attributed to your builder code.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
|
||||
+23
-21
@@ -12,7 +12,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<Step title="Install the SDK">
|
||||
<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 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```bash Rust theme={null}
|
||||
cargo add polymarket-client-sdk --features clob
|
||||
cargo add polymarket_client_sdk_v2 --features clob
|
||||
```
|
||||
</CodeGroup>
|
||||
</Step>
|
||||
@@ -31,11 +31,13 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<CodeGroup>
|
||||
```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 HOST = "https://clob.polymarket.com";
|
||||
const CHAIN_ID = 137; // Polygon mainnet
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
|
||||
const signer = createWalletClient({ account, transport: http() });
|
||||
|
||||
// Derive API credentials
|
||||
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
|
||||
@@ -48,12 +50,12 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType: 0, // EOA
|
||||
funderAddress: signer.address,
|
||||
funderAddress: account.address,
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_clob_client_v2 import ClobClient
|
||||
import os
|
||||
|
||||
host = "https://clob.polymarket.com"
|
||||
@@ -61,14 +63,14 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive API credentials
|
||||
temp_client = ClobClient(host, key=private_key, chain=chain)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
temp_client = ClobClient(host, key=private_key, chain_id=chain)
|
||||
api_creds = temp_client.create_or_derive_api_key()
|
||||
|
||||
# Initialize trading client
|
||||
client = ClobClient(
|
||||
host,
|
||||
key=private_key,
|
||||
chain=chain,
|
||||
chain_id=chain,
|
||||
creds=api_creds,
|
||||
signature_type=0, # EOA
|
||||
funder="YOUR_WALLET_ADDRESS"
|
||||
@@ -77,9 +79,9 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
|
||||
```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)?
|
||||
@@ -132,8 +134,8 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
from py_clob_client_v2 import OrderArgs, OrderType, PartialCreateOrderOptions
|
||||
from py_clob_client_v2.order_builder.constants import BUY
|
||||
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
@@ -142,10 +144,10 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
size=10,
|
||||
side=BUY,
|
||||
),
|
||||
options={
|
||||
"tick_size": "0.01",
|
||||
"neg_risk": False, # Set to True for multi-outcome markets
|
||||
},
|
||||
options=PartialCreateOrderOptions(
|
||||
tick_size="0.01",
|
||||
neg_risk=False, # Set to True for multi-outcome markets
|
||||
),
|
||||
order_type=OrderType.GTC
|
||||
)
|
||||
|
||||
@@ -154,8 +156,8 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::Side;
|
||||
use polymarket_client_sdk::types::dec;
|
||||
use polymarket_client_sdk_v2::clob::types::Side;
|
||||
use polymarket_client_sdk_v2::types::dec;
|
||||
|
||||
let token_id = "YOUR_TOKEN_ID".parse()?;
|
||||
|
||||
@@ -212,7 +214,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::{OrdersRequest, TradesRequest};
|
||||
use polymarket_client_sdk_v2::clob::types::request::{OrdersRequest, TradesRequest};
|
||||
|
||||
// View all open orders
|
||||
let open_orders = client.orders(&OrdersRequest::default(), None).await?;
|
||||
|
||||
Reference in New Issue
Block a user