docs: sync with official Polymarket docs - 2026-04-20
This commit is contained in:
@@ -6,14 +6,14 @@
|
||||
|
||||
> Bridge assets from any supported chain to fund your Polymarket account
|
||||
|
||||
Polymarket uses **USDC.e** (Bridged USDC) on Polygon as collateral for all trading. The Bridge API lets you deposit assets from Ethereum, Solana, Bitcoin, and other chains—they're automatically converted to USDC.e on Polygon.
|
||||
Polymarket uses **pUSD** (Polymarket USD) on Polygon as collateral for all trading. The Bridge API lets you deposit assets from Ethereum, Solana, Bitcoin, and other chains—they're automatically converted to pUSD on Polygon.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. Request deposit addresses for your Polymarket wallet
|
||||
2. Send assets to the appropriate address for your source chain
|
||||
3. Assets are bridged and swapped to USDC.e automatically
|
||||
4. USDC.e is credited to your wallet for trading
|
||||
3. Assets are bridged and swapped to pUSD automatically
|
||||
4. pUSD is credited to your wallet for trading
|
||||
|
||||
## Create Deposit Addresses
|
||||
|
||||
@@ -61,9 +61,9 @@ curl -X POST https://bridge.polymarket.com/deposit \
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
## USDC vs USDC.e
|
||||
## USDC vs pUSD
|
||||
|
||||
You can deposit either USDC (native) or USDC.e (bridged) to your Polymarket wallet. If you deposit native USDC, you will be prompted to "activate funds," which swaps it to USDC.e via the lowest-fee Uniswap pool (less than 10bp slippage).
|
||||
You can deposit either USDC (native) or USDC.e (bridged) as the source asset to your Polymarket wallet. Either way, the incoming USDC or USDC.e is wrapped into pUSD via the Collateral Onramp, and pUSD is what you hold and trade with on Polymarket.
|
||||
|
||||
## Large Deposits
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ curl -X POST https://bridge.polymarket.com/quote \
|
||||
"fromTokenAddress": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
||||
"recipientAddress": "0x17eC161f126e82A8ba337f4022d574DBEaFef575",
|
||||
"toChainId": "137",
|
||||
"toTokenAddress": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
|
||||
"toTokenAddress": "0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB"
|
||||
}'
|
||||
```
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ A response with active deposits:
|
||||
"fromTokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
"fromAmountBaseUnit": "1000000000",
|
||||
"toChainId": "137",
|
||||
"toTokenAddress": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
||||
"toTokenAddress": "0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB",
|
||||
"status": "COMPLETED",
|
||||
"txHash": "0xabc123...",
|
||||
"createdTimeMs": 1697875200000
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
> Chains and tokens supported for deposits to Polymarket
|
||||
|
||||
The Bridge API supports deposits from multiple chains and tokens. All deposits are automatically converted to **USDC.e on Polygon**, which is used as collateral for trading on Polymarket.
|
||||
The Bridge API supports deposits from multiple chains and tokens. All deposits are automatically converted to **pUSD on Polygon**, which is used as collateral for trading on Polymarket.
|
||||
|
||||
## Get Supported Assets
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
|
||||
# Withdraw
|
||||
|
||||
> Bridge USDC.e from Polymarket to any supported chain
|
||||
> Bridge pUSD from Polymarket to any supported chain
|
||||
|
||||
Withdraw USDC.e from your Polymarket wallet to any supported chain and token. Funds are automatically bridged and swapped to your desired token on the destination chain.
|
||||
Withdraw pUSD from your Polymarket wallet to any supported chain and token. Funds are automatically bridged and swapped to your desired token on the destination chain.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. Specify your destination chain, token, and recipient address
|
||||
2. Receive deposit addresses for each destination chain (EVM, Solana, Bitcoin)
|
||||
3. Send USDC.e from your Polymarket wallet to the appropriate deposit address
|
||||
3. Send pUSD from your Polymarket wallet to the appropriate deposit address
|
||||
4. Funds are automatically bridged and swapped to your desired token
|
||||
5. Funds arrive at your destination wallet
|
||||
|
||||
@@ -23,14 +23,14 @@ Withdraw USDC.e from your Polymarket wallet to any supported chain and token. Fu
|
||||
</Warning>
|
||||
|
||||
<Warning>
|
||||
When withdrawing, USDC.e (bridged USDC) is swapped through the
|
||||
When withdrawing, pUSD is unwrapped to USDC via the Collateral Offramp and swapped through the
|
||||
[Uniswap v3 pool](https://polygonscan.com/address/0xd36ec33c8bed5a9f7b6630855f1533455b98a418)
|
||||
for USDC (native). The UI enforces less than 10bp difference in output amount.
|
||||
At times, this pool may be exhausted. If you are having withdraw issues, try
|
||||
breaking your withdraw into smaller amounts or waiting for the pool to be
|
||||
rebalanced. Alternatively, you can withdraw USDC.e directly, which does not
|
||||
rebalanced. Alternatively, you can withdraw pUSD directly, which does not
|
||||
require Uniswap liquidity — just be aware that some exchanges no longer accept
|
||||
USDC.e deposits directly.
|
||||
pUSD deposits directly.
|
||||
</Warning>
|
||||
|
||||
<Tip>
|
||||
@@ -81,8 +81,8 @@ Withdrawals are **instant** and **free** — Polymarket does not charge withdraw
|
||||
and recipient.
|
||||
</Step>
|
||||
|
||||
<Step title="Send USDC.e">
|
||||
Transfer USDC.e from your Polymarket wallet to the appropriate deposit
|
||||
<Step title="Send pUSD">
|
||||
Transfer pUSD from your Polymarket wallet to the appropriate deposit
|
||||
address.
|
||||
</Step>
|
||||
|
||||
|
||||
+62
-127
@@ -4,116 +4,69 @@
|
||||
|
||||
# Builder Methods
|
||||
|
||||
> Methods for querying orders and trades using builder API credentials.
|
||||
> Methods for querying orders and trades attributed to your builder code.
|
||||
|
||||
## Client Initialization
|
||||
## Overview
|
||||
|
||||
Builder methods require the client to initialize with a separate builder config using credentials acquired from [Polymarket.com](https://polymarket.com/settings?tab=builder) and the `@polymarket/builder-signing-sdk` package.
|
||||
Builder attribution in V2 is handled natively through the order struct — you attach your **builder code** (a `bytes32` identifier from your [Builder Profile](https://polymarket.com/settings?tab=builder)) to every order you submit. No separate client configuration is required.
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Local Builder Credentials">
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { BuilderConfig, BuilderApiKeyCreds } from "@polymarket/builder-signing-sdk";
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
|
||||
const builderConfig = new BuilderConfig({
|
||||
localBuilderCreds: new BuilderApiKeyCreds({
|
||||
key: process.env.BUILDER_API_KEY,
|
||||
secret: process.env.BUILDER_SECRET,
|
||||
passphrase: process.env.BUILDER_PASS_PHRASE,
|
||||
}),
|
||||
});
|
||||
const client = new ClobClient({
|
||||
host: "https://clob.polymarket.com",
|
||||
chain: 137,
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType,
|
||||
funderAddress,
|
||||
});
|
||||
|
||||
const clobClient = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer,
|
||||
apiCreds, // User's API credentials from L1 authentication
|
||||
signatureType,
|
||||
funderAddress,
|
||||
undefined,
|
||||
false,
|
||||
builderConfig
|
||||
);
|
||||
```
|
||||
// Attach your builder code on every order
|
||||
const response = await client.createAndPostOrder(
|
||||
{
|
||||
tokenID: "0x...",
|
||||
price: 0.55,
|
||||
size: 100,
|
||||
side: Side.BUY,
|
||||
builderCode: process.env.POLY_BUILDER_CODE!,
|
||||
},
|
||||
{ tickSize: "0.01", negRisk: false },
|
||||
);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk.config import BuilderConfig, BuilderApiKeyCreds
|
||||
import os
|
||||
```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
|
||||
import os
|
||||
|
||||
builder_config = BuilderConfig(
|
||||
local_builder_creds=BuilderApiKeyCreds(
|
||||
key=os.getenv("BUILDER_API_KEY"),
|
||||
secret=os.getenv("BUILDER_SECRET"),
|
||||
passphrase=os.getenv("BUILDER_PASS_PHRASE"),
|
||||
)
|
||||
)
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain=137,
|
||||
key=os.getenv("PRIVATE_KEY"),
|
||||
creds=creds,
|
||||
signature_type=signature_type,
|
||||
funder=funder,
|
||||
)
|
||||
|
||||
clob_client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
key=os.getenv("PRIVATE_KEY"),
|
||||
creds=creds, # User's API credentials from L1 authentication
|
||||
signature_type=signature_type,
|
||||
funder=funder,
|
||||
builder_config=builder_config
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
|
||||
<Tab title="Remote Builder Signing">
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { BuilderConfig } from "@polymarket/builder-signing-sdk";
|
||||
|
||||
const builderConfig = new BuilderConfig({
|
||||
remoteBuilderConfig: { url: "http://localhost:3000/sign" }
|
||||
});
|
||||
|
||||
const clobClient = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer,
|
||||
apiCreds, // User's API credentials from L1 authentication
|
||||
signatureType,
|
||||
funder,
|
||||
undefined,
|
||||
false,
|
||||
builderConfig
|
||||
);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk.config import BuilderConfig, RemoteBuilderConfig
|
||||
import os
|
||||
|
||||
builder_config = BuilderConfig(
|
||||
remote_builder_config=RemoteBuilderConfig(
|
||||
url="http://localhost:3000/sign"
|
||||
)
|
||||
)
|
||||
|
||||
clob_client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
key=os.getenv("PRIVATE_KEY"),
|
||||
creds=creds, # User's API credentials from L1 authentication
|
||||
signature_type=signature_type,
|
||||
funder=funder,
|
||||
builder_config=builder_config
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
# Attach your builder code on every order
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="0x...",
|
||||
price=0.55,
|
||||
size=100,
|
||||
side=BUY,
|
||||
builder_code=os.environ["POLY_BUILDER_CODE"],
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Info>
|
||||
See [Order Attribution](/trading/orders/attribution) for more information on builder signing.
|
||||
See [Order Attribution](/trading/orders/attribution) for the full attribution flow.
|
||||
</Info>
|
||||
|
||||
***
|
||||
@@ -124,24 +77,20 @@ Builder methods require the client to initialize with a separate builder config
|
||||
|
||||
### getOrder
|
||||
|
||||
Get details for a specific order by ID using builder authentication. When called from a builder-configured client, the request authenticates with builder headers and returns orders attributed to the builder.
|
||||
Get details for a specific order by ID.
|
||||
|
||||
```typescript Signature theme={null}
|
||||
async getOrder(orderID: string): Promise<OpenOrder>
|
||||
```
|
||||
|
||||
<Info>
|
||||
When a `BuilderConfig` is present, the client automatically sends builder headers. If builder auth is unavailable, it falls back to standard L2 headers.
|
||||
</Info>
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
const order = await clobClient.getOrder("0xb816482a...");
|
||||
const order = await client.getOrder("0xb816482a...");
|
||||
console.log(order);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
order = clob_client.get_order("0xb816482a...")
|
||||
order = client.get_order("0xb816482a...")
|
||||
print(order)
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -150,7 +99,7 @@ async getOrder(orderID: string): Promise<OpenOrder>
|
||||
|
||||
### getOpenOrders
|
||||
|
||||
Get all open orders attributed to the builder. When called from a builder-configured client, returns orders placed through the builder rather than orders owned by the authenticated user.
|
||||
Get all open orders attributed to your builder code.
|
||||
|
||||
```typescript Signature theme={null}
|
||||
async getOpenOrders(
|
||||
@@ -175,10 +124,10 @@ async getOpenOrders(
|
||||
|
||||
```typescript TypeScript theme={null}
|
||||
// All open orders for this builder
|
||||
const orders = await clobClient.getOpenOrders();
|
||||
const orders = await client.getOpenOrders();
|
||||
|
||||
// Filtered by market
|
||||
const marketOrders = await clobClient.getOpenOrders({
|
||||
const marketOrders = await client.getOpenOrders({
|
||||
market: "0xbd31dc8a...",
|
||||
});
|
||||
```
|
||||
@@ -187,7 +136,7 @@ const marketOrders = await clobClient.getOpenOrders({
|
||||
|
||||
### getBuilderTrades
|
||||
|
||||
Retrieves all trades attributed to your builder account. Use this to track which trades were routed through your platform.
|
||||
Retrieves all trades attributed to your builder code. Use this to track which trades were routed through your platform.
|
||||
|
||||
```typescript Signature theme={null}
|
||||
async getBuilderTrades(
|
||||
@@ -254,7 +203,7 @@ async getBuilderTrades(
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="builder" type="string">
|
||||
Address of the builder who attributed this trade.
|
||||
Builder code attributed to this trade.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="market" type="string">
|
||||
@@ -335,20 +284,6 @@ async getBuilderTrades(
|
||||
|
||||
***
|
||||
|
||||
### revokeBuilderApiKey
|
||||
|
||||
Revokes the builder API key used to authenticate the current request. After revocation, the key can no longer be used for builder-authenticated requests.
|
||||
|
||||
```typescript Signature theme={null}
|
||||
async revokeBuilderApiKey(): Promise<any>
|
||||
```
|
||||
|
||||
<ResponseField name="returns" type="any">
|
||||
Response from the revocation request.
|
||||
</ResponseField>
|
||||
|
||||
***
|
||||
|
||||
## See Also
|
||||
|
||||
<CardGroup cols={2}>
|
||||
@@ -357,7 +292,7 @@ async revokeBuilderApiKey(): Promise<any>
|
||||
</Card>
|
||||
|
||||
<Card title="Order Attribution" icon="key" href="/trading/orders/attribution">
|
||||
Attribute orders to your builder account.
|
||||
Attach your builder code to orders for volume credit.
|
||||
</Card>
|
||||
|
||||
<Card title="L2 Methods" icon="lock" href="/trading/clients/l2">
|
||||
|
||||
@@ -13,16 +13,16 @@ L1 methods require the client to initialize with a signer.
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers";
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer // Signer required for L1 methods
|
||||
);
|
||||
const client = new ClobClient({
|
||||
host: "https://clob.polymarket.com",
|
||||
chain: 137,
|
||||
signer, // Signer required for L1 methods
|
||||
});
|
||||
|
||||
// Ready to create user API credentials
|
||||
const apiKey = await client.createApiKey();
|
||||
@@ -38,7 +38,7 @@ L1 methods require the client to initialize with a signer.
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
chain=137,
|
||||
key=private_key # Signer required for L1 methods
|
||||
)
|
||||
|
||||
@@ -161,22 +161,10 @@ async createOrder(
|
||||
The side of the order (buy or sell).
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feeRateBps" type="number">
|
||||
Optional fee rate in basis points. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="nonce" type="number">
|
||||
Optional nonce for the order. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="number">
|
||||
Optional expiration timestamp for the order. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="taker" type="string">
|
||||
Optional taker address for the order. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tickSize" type="TickSize">
|
||||
The tick size used for order validation (CreateOrderOptions).
|
||||
</ResponseField>
|
||||
@@ -197,10 +185,6 @@ async createOrder(
|
||||
The signer's address.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="taker" type="string">
|
||||
The taker's address in the signed order.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tokenId" type="string">
|
||||
The token ID in the signed order.
|
||||
</ResponseField>
|
||||
@@ -221,14 +205,6 @@ async createOrder(
|
||||
The expiration timestamp as a string.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="nonce" type="string">
|
||||
The nonce as a string.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feeRateBps" type="string">
|
||||
The fee rate in basis points as a string.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="signatureType" type="number">
|
||||
The type identifier for the signature scheme used.
|
||||
</ResponseField>
|
||||
@@ -266,18 +242,6 @@ async createMarketOrder(
|
||||
Optional price limit for the market order. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feeRateBps" type="number">
|
||||
Optional fee rate in basis points. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="nonce" type="number">
|
||||
Optional nonce for the order. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="taker" type="string">
|
||||
Optional taker address for the order. Optional.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="orderType" type="OrderType.FOK | OrderType.FAK">
|
||||
Optional order type, either FOK (Fill-Or-Kill) or FAK (Fill-And-Kill). Optional.
|
||||
</ResponseField>
|
||||
@@ -294,10 +258,6 @@ async createMarketOrder(
|
||||
The signer's address.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="taker" type="string">
|
||||
The taker's address in the signed order.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tokenId" type="string">
|
||||
The token ID in the signed order.
|
||||
</ResponseField>
|
||||
@@ -318,14 +278,6 @@ async createMarketOrder(
|
||||
The expiration timestamp as a string.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="nonce" type="string">
|
||||
The nonce as a string.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feeRateBps" type="string">
|
||||
The fee rate in basis points as a string.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="signatureType" type="number">
|
||||
The type identifier for the signature scheme used.
|
||||
</ResponseField>
|
||||
|
||||
@@ -13,7 +13,7 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers";
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
@@ -24,14 +24,14 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
passphrase: process.env.PASSPHRASE,
|
||||
};
|
||||
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
const client = new ClobClient({
|
||||
host: "https://clob.polymarket.com",
|
||||
chain: 137,
|
||||
signer,
|
||||
apiCreds,
|
||||
2, // GNOSIS_SAFE
|
||||
process.env.FUNDER_ADDRESS
|
||||
);
|
||||
creds: apiCreds,
|
||||
signatureType: 2, // GNOSIS_SAFE
|
||||
funderAddress: process.env.FUNDER_ADDRESS,
|
||||
});
|
||||
|
||||
// Ready to send authenticated requests
|
||||
const order = await client.postOrder(signedOrder);
|
||||
@@ -52,7 +52,7 @@ L2 methods require the client to initialize with a signer, signature type, API c
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
chain=137,
|
||||
key=os.getenv("PRIVATE_KEY"),
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
@@ -101,22 +101,10 @@ async createAndPostOrder(
|
||||
The side of the order (buy or sell).
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feeRateBps" type="number">
|
||||
Optional fee rate in basis points.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="nonce" type="number">
|
||||
Optional nonce for the order.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="expiration" type="number">
|
||||
Optional expiration timestamp for the order.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="taker" type="string">
|
||||
Optional taker address.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tickSize" type="TickSize">
|
||||
Tick size for the order. One of `"0.1"`, `"0.01"`, `"0.001"`, `"0.0001"`.
|
||||
</ResponseField>
|
||||
@@ -187,18 +175,6 @@ async createAndPostMarketOrder(
|
||||
Optional price hint for the market order.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feeRateBps" type="number">
|
||||
Optional fee rate in basis points.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="nonce" type="number">
|
||||
Optional nonce for the order.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="taker" type="string">
|
||||
Optional taker address.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="orderType" type="OrderType.FOK | OrderType.FAK">
|
||||
Optional order type override. Defaults to FOK.
|
||||
</ResponseField>
|
||||
|
||||
@@ -13,12 +13,12 @@ Public methods require the client to initialize with the host URL and Polygon ch
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
```typescript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137
|
||||
);
|
||||
const client = new ClobClient({
|
||||
host: "https://clob.polymarket.com",
|
||||
chain: 137,
|
||||
});
|
||||
|
||||
// Ready to call public methods
|
||||
const markets = await client.getMarkets();
|
||||
@@ -31,7 +31,7 @@ Public methods require the client to initialize with the host URL and Polygon ch
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137
|
||||
chain=137
|
||||
)
|
||||
|
||||
# Ready to call public methods
|
||||
@@ -584,6 +584,77 @@ async getMarketTradesEvents(conditionID: string): Promise<MarketTradeEvent[]>
|
||||
|
||||
***
|
||||
|
||||
### getClobMarketInfo
|
||||
|
||||
Fetch all CLOB-level parameters for a market in a single call — tokens, tick size, base fees, rewards config, RFQ status, and fee details.
|
||||
|
||||
```typescript Signature theme={null}
|
||||
async getClobMarketInfo(conditionID: string): Promise<ClobMarketDetails>
|
||||
```
|
||||
|
||||
<ResponseField name="conditionID" type="string">
|
||||
The condition ID of the market.
|
||||
</ResponseField>
|
||||
|
||||
**Response (`ClobMarketDetails`)**
|
||||
|
||||
<ResponseField name="gst" type="string | null">
|
||||
Game start time (used for sports markets), ISO 8601 timestamp or `null`.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="r" type="object">
|
||||
Rewards configuration for the market.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="t" type="ClobToken[]">
|
||||
Tokens for this market. Each entry has:
|
||||
|
||||
* `t` (string) — token ID
|
||||
* `o` (string) — outcome label (e.g. `Yes`, `No`)
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="mos" type="number">
|
||||
Minimum order size.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="mts" type="number">
|
||||
Minimum tick size (price increment).
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="mbf" type="number">
|
||||
Maker base fee in basis points.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tbf" type="number">
|
||||
Taker base fee in basis points.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="rfqe" type="boolean">
|
||||
Whether RFQ (Request for Quote) is enabled for this market.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="itode" type="boolean">
|
||||
Whether taker order delay is enabled.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="ibce" type="boolean">
|
||||
Whether Blockaid check is enabled.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="fd" type="object">
|
||||
Fee curve parameters:
|
||||
|
||||
* `r` (number) — fee rate
|
||||
* `e` (number) — fee curve exponent
|
||||
* `to` (boolean) — whether fees apply to takers only
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="oas" type="number">
|
||||
Minimum order age in seconds.
|
||||
</ResponseField>
|
||||
|
||||
***
|
||||
|
||||
### getFeeRateBps
|
||||
|
||||
Get the fee rate in basis points for a token.
|
||||
@@ -598,6 +669,20 @@ async getFeeRateBps(tokenID: string): Promise<number>
|
||||
|
||||
***
|
||||
|
||||
### getFeeExponent
|
||||
|
||||
Get the fee curve exponent for a token. The exponent shapes the fee curve used by the protocol when calculating fees at match time.
|
||||
|
||||
```typescript Signature theme={null}
|
||||
async getFeeExponent(tokenID: string): Promise<number>
|
||||
```
|
||||
|
||||
<ResponseField name="returns" type="number">
|
||||
The fee curve exponent for the specified token's market.
|
||||
</ResponseField>
|
||||
|
||||
***
|
||||
|
||||
### getTickSize
|
||||
|
||||
Get the tick size (minimum price increment) for a market.
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
# Merge Tokens
|
||||
|
||||
> Convert outcome token pairs back to USDC.e
|
||||
> Convert outcome token pairs back to pUSD
|
||||
|
||||
**Merging** is the inverse of splitting — it converts a full set of outcome tokens back into USDC.e collateral. For every 1 Yes token and 1 No token you merge, you receive \$1 USDC.e. The condition must already be prepared on the CTF contract (via `prepareCondition`).
|
||||
**Merging** is the inverse of splitting — it converts a full set of outcome tokens back into pUSD collateral. For every 1 Yes token and 1 No token you merge, you receive \$1 pUSD. The condition must already be prepared on the CTF contract (via `prepareCondition`).
|
||||
|
||||
```
|
||||
100 Yes tokens + 100 No tokens → $100 USDC.e
|
||||
100 Yes tokens + 100 No tokens → $100 pUSD
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
@@ -24,14 +24,14 @@ Before merging, you need:
|
||||
|
||||
1. You call `mergePositions()` 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 USDC.e back to your wallet
|
||||
3. The CTF contract releases pUSD back to your wallet
|
||||
|
||||
The operation is atomic — if you don't have enough of both tokens, the transaction reverts.
|
||||
|
||||
## Function Parameters
|
||||
|
||||
<ResponseField name="collateralToken" type="IERC20">
|
||||
USDC.e (Bridged USDC) contract address: `0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174`
|
||||
pUSD (Polymarket USD) contract address: `0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB`
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="parentCollectionId" type="bytes32">
|
||||
@@ -54,7 +54,7 @@ The operation is atomic — if you don't have enough of both tokens, the transac
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Redeem Tokens" icon="hand-holding-dollar" href="/trading/ctf/redeem">
|
||||
Exchange winning tokens for USDC.e after resolution
|
||||
Exchange winning tokens for pUSD after resolution
|
||||
</Card>
|
||||
|
||||
<Card title="CTF Overview" icon="book" href="/trading/ctf/overview">
|
||||
|
||||
@@ -12,12 +12,12 @@ All outcomes on Polymarket are tokenized using the **Conditional Token Framework
|
||||
|
||||
The Conditional Token Framework creates **ERC1155 tokens** representing outcomes of prediction markets. Each binary market has two tokens:
|
||||
|
||||
| Token | Redeems for | Condition |
|
||||
| ------- | ------------- | -------------------- |
|
||||
| **Yes** | \$1.00 USDC.e | Event occurs |
|
||||
| **No** | \$1.00 USDC.e | Event does not occur |
|
||||
| Token | Redeems for | Condition |
|
||||
| ------- | ----------- | -------------------- |
|
||||
| **Yes** | \$1.00 pUSD | Event occurs |
|
||||
| **No** | \$1.00 pUSD | Event does not occur |
|
||||
|
||||
These tokens are always **fully collateralized** — every Yes/No pair is backed by exactly \$1.00 USDC.e locked in the CTF contract.
|
||||
These tokens are always **fully collateralized** — every Yes/No pair is backed by exactly \$1.00 pUSD locked in the CTF contract.
|
||||
|
||||
## Core Operations
|
||||
|
||||
@@ -25,15 +25,15 @@ CTF provides three fundamental operations:
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Split" icon="scissors" href="/trading/ctf/split">
|
||||
Convert USDC.e into Yes + No token pairs
|
||||
Convert pUSD into Yes + No token pairs
|
||||
</Card>
|
||||
|
||||
<Card title="Merge" icon="merge" href="/trading/ctf/merge">
|
||||
Convert Yes + No pairs back to USDC.e
|
||||
Convert Yes + No pairs back to pUSD
|
||||
</Card>
|
||||
|
||||
<Card title="Redeem" icon="hand-holding-dollar" href="/trading/ctf/redeem">
|
||||
Exchange winning tokens for USDC.e after resolution
|
||||
Exchange winning tokens for pUSD after resolution
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -83,7 +83,7 @@ getPositionId(collateralToken, collectionId)
|
||||
|
||||
| Parameter | Type | Value |
|
||||
| ----------------- | --------- | ----------------------------------------- |
|
||||
| `collateralToken` | `IERC20` | USDC.e contract address on Polygon |
|
||||
| `collateralToken` | `IERC20` | pUSD contract address on Polygon |
|
||||
| `collectionId` | `bytes32` | One of the two collection IDs from step 2 |
|
||||
|
||||
The two resulting position IDs are the ERC1155 token IDs for the Yes and No outcomes of the market.
|
||||
@@ -109,7 +109,7 @@ For neg risk markets, an additional **conversion** operation allows exchanging a
|
||||
|
||||
## Contract Addresses
|
||||
|
||||
See [Contract Addresses](/resources/contract-addresses) for all Polymarket smart contract addresses on Polygon.
|
||||
See [Contracts](/resources/contracts) for all Polymarket smart contract addresses on Polygon.
|
||||
|
||||
## Resources
|
||||
|
||||
@@ -127,11 +127,11 @@ See [Contract Addresses](/resources/contract-addresses) for all Polymarket smart
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Split Tokens" icon="scissors" href="/trading/ctf/split">
|
||||
Create outcome token pairs from USDC.e
|
||||
Create outcome token pairs from pUSD
|
||||
</Card>
|
||||
|
||||
<Card title="Merge Tokens" icon="merge" href="/trading/ctf/merge">
|
||||
Convert token pairs back to USDC.e
|
||||
Convert token pairs back to pUSD
|
||||
</Card>
|
||||
|
||||
<Card title="Redeem Tokens" icon="hand-holding-dollar" href="/trading/ctf/redeem">
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
# Redeem Tokens
|
||||
|
||||
> Exchange winning tokens for USDC.e after market resolution
|
||||
> Exchange winning tokens for pUSD after market resolution
|
||||
|
||||
**Redeeming** converts winning outcome tokens into USDC.e after a market resolves. Each winning token is worth exactly $1.00 — the losing token is worth $0.
|
||||
**Redeeming** converts winning outcome tokens into pUSD after a market resolves. Each winning token is worth exactly $1.00 — the losing token is worth $0.
|
||||
|
||||
```
|
||||
Market resolves YES:
|
||||
100 Yes tokens → $100 USDC.e
|
||||
100 Yes tokens → $100 pUSD
|
||||
100 No tokens → $0
|
||||
```
|
||||
|
||||
@@ -18,7 +18,7 @@ Market resolves YES:
|
||||
|
||||
Redemption is only available **after a market resolves**. Once the oracle reports the outcome:
|
||||
|
||||
* **Winning tokens** can be redeemed for \$1.00 USDC.e each
|
||||
* **Winning tokens** can be redeemed for \$1.00 pUSD each
|
||||
* **Losing tokens** are worth \$0 and produce no payout
|
||||
|
||||
<Note>
|
||||
@@ -44,7 +44,7 @@ Before redeeming:
|
||||
## Function Parameters
|
||||
|
||||
<ResponseField name="collateralToken" type="IERC20">
|
||||
USDC.e (Bridged USDC) contract address: `0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174`
|
||||
pUSD (Polymarket USD) contract address: `0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB`
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="parentCollectionId" type="bytes32">
|
||||
@@ -78,7 +78,7 @@ When you call `redeemPositions()`:
|
||||
|
||||
* Your token balance is multiplied by the payout
|
||||
* Winning tokens are burned
|
||||
* USDC.e is transferred to your wallet
|
||||
* pUSD is transferred to your wallet
|
||||
* Losing tokens are burned as well, but produce a \$0 payout
|
||||
|
||||
## Next Steps
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
|
||||
# Split Tokens
|
||||
|
||||
> Convert USDC.e into outcome token pairs
|
||||
> Convert pUSD into outcome token pairs
|
||||
|
||||
**Splitting** converts USDC.e collateral into a full (position) set of outcome tokens. For every \$1 USDC.e you split, you receive 1 Yes token and 1 No token.
|
||||
**Splitting** converts pUSD collateral into a full (position) set of outcome tokens. For every \$1 pUSD you split, you receive 1 Yes token and 1 No token.
|
||||
|
||||
```
|
||||
$100 USDC.e → 100 Yes tokens + 100 No tokens
|
||||
$100 pUSD → 100 Yes tokens + 100 No tokens
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before splitting, ensure you have:
|
||||
|
||||
1. **USDC.e balance** on Polygon
|
||||
2. **USDC.e approval** for the CTF contract to spend your tokens
|
||||
1. **pUSD balance** on Polygon
|
||||
2. **pUSD approval** for the CTF contract to spend your tokens
|
||||
3. **Condition ID** of the market — the condition must already be prepared on the CTF contract (via `prepareCondition`)
|
||||
|
||||
<Note>
|
||||
@@ -27,16 +27,16 @@ Before splitting, ensure you have:
|
||||
|
||||
## How It Works
|
||||
|
||||
1. You approve the CTF contract to spend your USDC.e
|
||||
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 USDC.e from your wallet and mints both outcome tokens
|
||||
3. The CTF contract transfers pUSD from your wallet and mints both outcome tokens
|
||||
|
||||
The operation is atomic — if any step fails, the entire transaction reverts.
|
||||
|
||||
## Function Parameters
|
||||
|
||||
<ResponseField name="collateralToken" type="IERC20">
|
||||
USDC.e (Bridged USDC) contract address: `0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174`
|
||||
pUSD (Polymarket USD) contract address: `0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB`
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="parentCollectionId" type="bytes32">
|
||||
@@ -60,7 +60,7 @@ The operation is atomic — if any step fails, the entire transaction reverts.
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Merge Tokens" icon="merge" href="/trading/ctf/merge">
|
||||
Convert token pairs back to USDC.e
|
||||
Convert token pairs back to pUSD
|
||||
</Card>
|
||||
|
||||
<Card title="Trade on Orderbook" icon="chart-line" href="/trading/orders/create">
|
||||
|
||||
+80
-241
@@ -6,7 +6,7 @@
|
||||
|
||||
> Execute onchain operations without paying gas fees
|
||||
|
||||
Polymarket's **Relayer Client** enables gasless transactions for your users. Instead of requiring users to hold POL for gas, Polymarket's infrastructure pays all transaction fees. This creates a seamless experience where users only need USDC.e to trade.
|
||||
Polymarket's **Relayer Client** enables gasless transactions for your users. Instead of requiring users to hold POL for gas, Polymarket's infrastructure pays all transaction fees. This creates a seamless experience where users only need pUSD to trade.
|
||||
|
||||
## How It Works
|
||||
|
||||
@@ -18,43 +18,20 @@ The relayer acts as a transaction sponsor:
|
||||
4. The relayer submits it onchain and pays the gas fee
|
||||
5. The transaction executes from the user's wallet
|
||||
|
||||
<Note>
|
||||
Gasless transactions require authentication with **Builder API Keys** or **Relayer API Keys**.
|
||||
</Note>
|
||||
|
||||
## What Is Covered
|
||||
|
||||
Polymarket pays gas for all operations routed through the relayer:
|
||||
|
||||
| Operation | Description |
|
||||
| --------------------- | --------------------------------------------------- |
|
||||
| **Wallet deployment** | Deploy Safe or Proxy wallets for new users |
|
||||
| **Token approvals** | Approve contracts to spend USDC.e or outcome tokens |
|
||||
| **CTF operations** | Split, merge, and redeem positions |
|
||||
| **Transfers** | Move tokens between addresses |
|
||||
| Operation | Description |
|
||||
| --------------------- | ------------------------------------------------- |
|
||||
| **Wallet deployment** | Deploy Safe or Proxy wallets for new users |
|
||||
| **Token approvals** | Approve contracts to spend pUSD or outcome tokens |
|
||||
| **CTF operations** | Split, merge, and redeem positions |
|
||||
| **Transfers** | Move tokens between addresses |
|
||||
|
||||
## Authentication
|
||||
|
||||
The relayer supports two authentication methods. Choose the one that fits your use case.
|
||||
|
||||
### Using Builder API Keys
|
||||
|
||||
Builder API Keys are for [Builder Program](/builders/overview) members. They authenticate via HMAC-SHA256 signed headers and are required to use the relayer SDKs.
|
||||
|
||||
All requests must include these headers:
|
||||
|
||||
| Header | Description |
|
||||
| ------------------------- | ----------------------- |
|
||||
| `POLY_BUILDER_API_KEY` | Your Builder API key |
|
||||
| `POLY_BUILDER_TIMESTAMP` | Unix timestamp |
|
||||
| `POLY_BUILDER_PASSPHRASE` | Your Builder passphrase |
|
||||
| `POLY_BUILDER_SIGNATURE` | HMAC-SHA256 signature |
|
||||
|
||||
The SDKs handle header generation automatically when you provide your credentials via `BuilderConfig`.
|
||||
|
||||
### Using Relayer API Keys
|
||||
|
||||
Relayer API Keys are for market makers and anyone who needs a simpler alternative. You can create them from [Settings > API Keys](https://polymarket.com/settings?tab=api-keys) on the Polymarket website.
|
||||
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.
|
||||
|
||||
Include these headers with your requests:
|
||||
|
||||
@@ -71,205 +48,67 @@ Include these headers with your requests:
|
||||
|
||||
Before using the relayer, you need:
|
||||
|
||||
| Requirement | Source |
|
||||
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Builder API credentials **or** Relayer API key | [Builder Profile](https://polymarket.com/settings?tab=builder) or [Settings > API Keys](https://polymarket.com/settings?tab=api-keys) |
|
||||
| User's private key or signer | Your wallet integration |
|
||||
| USDC.e balance | For trading (not for gas) |
|
||||
|
||||
> The below section is for the Builder SDKs only. If you want to use the Relayer API Key directly without the SDK, see the [Relayer API Reference](/api-reference/relayer).
|
||||
| Requirement | Source |
|
||||
| ---------------------------- | ------------------------------------------------------------------- |
|
||||
| Relayer API Key | [Settings > API Keys](https://polymarket.com/settings?tab=api-keys) |
|
||||
| User's private key or signer | Your wallet integration |
|
||||
| pUSD balance | For trading (not for gas) |
|
||||
|
||||
## Installation
|
||||
|
||||
<CodeGroup>
|
||||
```bash npm theme={null}
|
||||
npm install @polymarket/builder-relayer-client @polymarket/builder-signing-sdk
|
||||
npm install @polymarket/builder-relayer-client
|
||||
```
|
||||
|
||||
```bash pip theme={null}
|
||||
pip install py-builder-relayer-client py-builder-signing-sdk
|
||||
pip install py-builder-relayer-client
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
## Client Setup
|
||||
|
||||
Initialize the relayer client with your signing configuration:
|
||||
Initialize the relayer client with your Relayer API Key:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Local Signing">
|
||||
Use local signing when your backend handles all transactions securely.
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { createWalletClient, http, Hex } from "viem";
|
||||
import { privateKeyToAccount } from "viem/accounts";
|
||||
import { polygon } from "viem/chains";
|
||||
import { RelayClient } from "@polymarket/builder-relayer-client";
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { createWalletClient, http, Hex } from "viem";
|
||||
import { privateKeyToAccount } from "viem/accounts";
|
||||
import { polygon } from "viem/chains";
|
||||
import { RelayClient } from "@polymarket/builder-relayer-client";
|
||||
import { BuilderConfig } from "@polymarket/builder-signing-sdk";
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex);
|
||||
const wallet = createWalletClient({
|
||||
account,
|
||||
chain: polygon,
|
||||
transport: http(process.env.RPC_URL),
|
||||
});
|
||||
|
||||
const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex);
|
||||
const wallet = createWalletClient({
|
||||
account,
|
||||
chain: polygon,
|
||||
transport: http(process.env.RPC_URL),
|
||||
});
|
||||
const client = new RelayClient({
|
||||
host: "https://relayer-v2.polymarket.com/",
|
||||
chain: 137,
|
||||
signer: wallet,
|
||||
relayerApiKey: process.env.RELAYER_API_KEY!,
|
||||
relayerApiKeyAddress: process.env.RELAYER_API_KEY_ADDRESS!,
|
||||
});
|
||||
```
|
||||
|
||||
const builderConfig = new BuilderConfig({
|
||||
localBuilderCreds: {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
},
|
||||
});
|
||||
```python Python theme={null}
|
||||
import os
|
||||
from py_builder_relayer_client.client import RelayClient
|
||||
|
||||
const client = new RelayClient(
|
||||
"https://relayer-v2.polymarket.com/",
|
||||
137,
|
||||
wallet,
|
||||
builderConfig,
|
||||
);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
import os
|
||||
from py_builder_relayer_client.client import RelayClient
|
||||
from py_builder_signing_sdk import BuilderConfig, BuilderApiKeyCreds
|
||||
|
||||
builder_config = BuilderConfig(
|
||||
local_builder_creds=BuilderApiKeyCreds(
|
||||
key=os.getenv("POLY_BUILDER_API_KEY"),
|
||||
secret=os.getenv("POLY_BUILDER_SECRET"),
|
||||
passphrase=os.getenv("POLY_BUILDER_PASSPHRASE"),
|
||||
)
|
||||
)
|
||||
|
||||
client = RelayClient(
|
||||
"https://relayer-v2.polymarket.com",
|
||||
137,
|
||||
os.getenv("PRIVATE_KEY"),
|
||||
builder_config
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
|
||||
<Tab title="Remote Signing">
|
||||
Use remote signing to keep credentials on a secure server you control.
|
||||
|
||||
**Your signing server** receives request details and returns authentication headers:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript Server (TypeScript) theme={null}
|
||||
import {
|
||||
buildHmacSignature,
|
||||
BuilderApiKeyCreds,
|
||||
} from "@polymarket/builder-signing-sdk";
|
||||
|
||||
const BUILDER_CREDENTIALS: BuilderApiKeyCreds = {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
};
|
||||
|
||||
// POST /sign endpoint
|
||||
export async function handleSignRequest(request) {
|
||||
const { method, path, body } = await request.json();
|
||||
const timestamp = Date.now().toString();
|
||||
|
||||
const signature = buildHmacSignature(
|
||||
BUILDER_CREDENTIALS.secret,
|
||||
parseInt(timestamp),
|
||||
method,
|
||||
path,
|
||||
body,
|
||||
);
|
||||
|
||||
return {
|
||||
POLY_BUILDER_SIGNATURE: signature,
|
||||
POLY_BUILDER_TIMESTAMP: timestamp,
|
||||
POLY_BUILDER_API_KEY: BUILDER_CREDENTIALS.key,
|
||||
POLY_BUILDER_PASSPHRASE: BUILDER_CREDENTIALS.passphrase,
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
```python Server (Python) theme={null}
|
||||
import os
|
||||
import time
|
||||
from py_builder_signing_sdk.signing.hmac import build_hmac_signature
|
||||
from py_builder_signing_sdk import BuilderApiKeyCreds
|
||||
|
||||
BUILDER_CREDENTIALS = BuilderApiKeyCreds(
|
||||
key=os.environ["POLY_BUILDER_API_KEY"],
|
||||
secret=os.environ["POLY_BUILDER_SECRET"],
|
||||
passphrase=os.environ["POLY_BUILDER_PASSPHRASE"],
|
||||
)
|
||||
|
||||
# POST /sign endpoint
|
||||
def handle_sign_request(method: str, path: str, body: str):
|
||||
timestamp = str(int(time.time()))
|
||||
|
||||
signature = build_hmac_signature(
|
||||
BUILDER_CREDENTIALS.secret,
|
||||
timestamp,
|
||||
method,
|
||||
path,
|
||||
body
|
||||
)
|
||||
|
||||
return {
|
||||
"POLY_BUILDER_SIGNATURE": signature,
|
||||
"POLY_BUILDER_TIMESTAMP": timestamp,
|
||||
"POLY_BUILDER_API_KEY": BUILDER_CREDENTIALS.key,
|
||||
"POLY_BUILDER_PASSPHRASE": BUILDER_CREDENTIALS.passphrase,
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
**Your client** points to your signing server:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript Client (TypeScript) theme={null}
|
||||
import { RelayClient } from "@polymarket/builder-relayer-client";
|
||||
import { BuilderConfig } from "@polymarket/builder-signing-sdk";
|
||||
|
||||
const builderConfig = new BuilderConfig({
|
||||
remoteBuilderConfig: {
|
||||
url: "https://your-server.com/sign",
|
||||
},
|
||||
});
|
||||
|
||||
const client = new RelayClient(
|
||||
"https://relayer-v2.polymarket.com/",
|
||||
137,
|
||||
wallet,
|
||||
builderConfig,
|
||||
);
|
||||
```
|
||||
|
||||
```python Client (Python) theme={null}
|
||||
from py_builder_relayer_client.client import RelayClient
|
||||
from py_builder_signing_sdk import BuilderConfig, RemoteBuilderConfig
|
||||
|
||||
builder_config = BuilderConfig(
|
||||
remote_builder_config=RemoteBuilderConfig(
|
||||
url="https://your-server.com/sign"
|
||||
)
|
||||
)
|
||||
|
||||
client = RelayClient(
|
||||
"https://relayer-v2.polymarket.com",
|
||||
137,
|
||||
private_key,
|
||||
builder_config
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
client = RelayClient(
|
||||
host="https://relayer-v2.polymarket.com",
|
||||
chain=137,
|
||||
signer=os.getenv("PRIVATE_KEY"),
|
||||
relayer_api_key=os.environ["RELAYER_API_KEY"],
|
||||
relayer_api_key_address=os.environ["RELAYER_API_KEY_ADDRESS"],
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Warning>
|
||||
Never expose Builder API credentials in client-side code. Use environment
|
||||
Never expose your Relayer API Key in client-side code. Use environment
|
||||
variables or a secrets manager.
|
||||
</Warning>
|
||||
|
||||
@@ -286,13 +125,14 @@ Choose a wallet type when initializing the client:
|
||||
```typescript Safe Wallet (TypeScript) theme={null}
|
||||
import { RelayClient, RelayerTxType } from "@polymarket/builder-relayer-client";
|
||||
|
||||
const client = new RelayClient(
|
||||
"https://relayer-v2.polymarket.com/",
|
||||
137,
|
||||
wallet,
|
||||
builderConfig,
|
||||
RelayerTxType.SAFE,
|
||||
);
|
||||
const client = new RelayClient({
|
||||
host: "https://relayer-v2.polymarket.com/",
|
||||
chain: 137,
|
||||
signer: wallet,
|
||||
relayerApiKey: process.env.RELAYER_API_KEY!,
|
||||
relayerApiKeyAddress: process.env.RELAYER_API_KEY_ADDRESS!,
|
||||
txType: RelayerTxType.SAFE,
|
||||
});
|
||||
|
||||
// Deploy before first transaction
|
||||
const response = await client.deploy();
|
||||
@@ -303,7 +143,7 @@ Choose a wallet type when initializing the client:
|
||||
```python Safe Wallet (Python) theme={null}
|
||||
from py_builder_relayer_client.client import RelayClient
|
||||
|
||||
# client initialized with builder_config (see Client Setup above)
|
||||
# client initialized with relayer credentials (see Client Setup above)
|
||||
|
||||
# Deploy before first transaction
|
||||
response = client.deploy()
|
||||
@@ -314,13 +154,14 @@ Choose a wallet type when initializing the client:
|
||||
```typescript Proxy Wallet (TypeScript) theme={null}
|
||||
import { RelayClient, RelayerTxType } from "@polymarket/builder-relayer-client";
|
||||
|
||||
const client = new RelayClient(
|
||||
"https://relayer-v2.polymarket.com/",
|
||||
137,
|
||||
wallet,
|
||||
builderConfig,
|
||||
RelayerTxType.PROXY,
|
||||
);
|
||||
const client = new RelayClient({
|
||||
host: "https://relayer-v2.polymarket.com/",
|
||||
chain: 137,
|
||||
signer: wallet,
|
||||
relayerApiKey: process.env.RELAYER_API_KEY!,
|
||||
relayerApiKeyAddress: process.env.RELAYER_API_KEY_ADDRESS!,
|
||||
txType: RelayerTxType.PROXY,
|
||||
});
|
||||
|
||||
// No deploy needed - auto-deploys on first transaction
|
||||
```
|
||||
@@ -328,7 +169,7 @@ Choose a wallet type when initializing the client:
|
||||
```python Proxy Wallet (Python) theme={null}
|
||||
from py_builder_relayer_client.client import RelayClient
|
||||
|
||||
# client initialized with builder_config (see Client Setup above)
|
||||
# client initialized with relayer credentials (see Client Setup above)
|
||||
# No deploy needed - auto-deploys on first transaction
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -356,11 +197,11 @@ Approve contracts to spend tokens:
|
||||
```typescript TypeScript theme={null}
|
||||
import { encodeFunctionData, maxUint256 } from "viem";
|
||||
|
||||
const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
||||
const pUSD = "0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB";
|
||||
const CTF = "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045";
|
||||
|
||||
const approveTx = {
|
||||
to: USDC,
|
||||
to: pUSD,
|
||||
data: encodeFunctionData({
|
||||
abi: [
|
||||
{
|
||||
@@ -379,21 +220,21 @@ Approve contracts to spend tokens:
|
||||
value: "0",
|
||||
};
|
||||
|
||||
const response = await client.execute([approveTx], "Approve USDC.e for CTF");
|
||||
const response = await client.execute([approveTx], "Approve pUSD for CTF");
|
||||
await response.wait();
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from web3 import Web3
|
||||
|
||||
USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
|
||||
pUSD = "0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB"
|
||||
CTF = "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045"
|
||||
MAX_UINT256 = 2**256 - 1
|
||||
|
||||
approve_tx = {
|
||||
"to": USDC,
|
||||
"to": pUSD,
|
||||
"data": Web3().eth.contract(
|
||||
address=USDC,
|
||||
address=pUSD,
|
||||
abi=[{
|
||||
"name": "approve",
|
||||
"type": "function",
|
||||
@@ -407,14 +248,14 @@ Approve contracts to spend tokens:
|
||||
"value": "0"
|
||||
}
|
||||
|
||||
response = client.execute([approve_tx], "Approve USDC.e for CTF")
|
||||
response = client.execute([approve_tx], "Approve pUSD for CTF")
|
||||
response.wait()
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
### Redeem Positions
|
||||
|
||||
Exchange winning tokens for USDC.e after market resolution:
|
||||
Exchange winning tokens for pUSD after market resolution:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
@@ -483,7 +324,7 @@ Execute multiple operations atomically in a single call:
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
const approveTx = {
|
||||
to: USDC,
|
||||
to: pUSD,
|
||||
data: encodeFunctionData({
|
||||
abi: erc20Abi,
|
||||
functionName: "approve",
|
||||
@@ -493,7 +334,7 @@ Execute multiple operations atomically in a single call:
|
||||
};
|
||||
|
||||
const transferTx = {
|
||||
to: USDC,
|
||||
to: pUSD,
|
||||
data: encodeFunctionData({
|
||||
abi: erc20Abi,
|
||||
functionName: "transfer",
|
||||
@@ -512,7 +353,7 @@ Execute multiple operations atomically in a single call:
|
||||
|
||||
```python Python theme={null}
|
||||
approve_tx = {
|
||||
"to": USDC,
|
||||
"to": pUSD,
|
||||
"data": contract.encode_abi(
|
||||
abi_element_identifier="approve",
|
||||
args=[CTF, MAX_UINT256]
|
||||
@@ -521,7 +362,7 @@ Execute multiple operations atomically in a single call:
|
||||
}
|
||||
|
||||
transfer_tx = {
|
||||
"to": USDC,
|
||||
"to": pUSD,
|
||||
"data": contract.encode_abi(
|
||||
abi_element_identifier="transfer",
|
||||
args=[recipient_address, 50 * 10**6]
|
||||
@@ -555,14 +396,12 @@ Track transaction progress through these states:
|
||||
|
||||
## Contract Addresses
|
||||
|
||||
See [Contract Addresses](/resources/contract-addresses) for all Polymarket smart contract addresses on Polygon.
|
||||
See [Contracts](/resources/contracts) for all Polymarket smart contract addresses on Polygon.
|
||||
|
||||
## Resources
|
||||
|
||||
* [Builder Relayer Client (TypeScript)](https://github.com/Polymarket/builder-relayer-client)
|
||||
* [Builder Relayer Client (Python)](https://github.com/Polymarket/py-builder-relayer-client)
|
||||
* [Builder Signing SDK (TypeScript)](https://github.com/Polymarket/builder-signing-sdk)
|
||||
* [Builder Signing SDK (Python)](https://github.com/Polymarket/py-builder-signing-sdk)
|
||||
|
||||
## Next Steps
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ The orderbook is a public endpoint — no authentication required. You can read
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
|
||||
const client = new ClobClient("https://clob.polymarket.com", 137);
|
||||
const client = new ClobClient({ host: "https://clob.polymarket.com", chain: 137 });
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
|
||||
client = ClobClient("https://clob.polymarket.com", chain_id=137)
|
||||
client = ClobClient("https://clob.polymarket.com", chain=137)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
@@ -230,7 +230,7 @@ Fetch historical price data for a token over various time intervals:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { PriceHistoryInterval } from "@polymarket/clob-client";
|
||||
import { PriceHistoryInterval } from "@polymarket/clob-client-v2";
|
||||
|
||||
const history = await client.getPricesHistory({
|
||||
market: "TOKEN_ID", // Note: this param is named "market" but takes a token ID
|
||||
@@ -302,7 +302,7 @@ Calculate the effective price you'd pay for a market order of a given size, acco
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { Side, OrderType } from "@polymarket/clob-client";
|
||||
import { Side, OrderType } from "@polymarket/clob-client-v2";
|
||||
|
||||
// What price would I pay to buy $500 worth?
|
||||
const price = await client.calculateMarketPrice(
|
||||
@@ -366,7 +366,7 @@ All orderbook queries have batch variants for fetching data across multiple toke
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { Side } from "@polymarket/clob-client";
|
||||
import { Side } from "@polymarket/clob-client-v2";
|
||||
|
||||
// Fetch prices for multiple tokens
|
||||
const prices = await client.getPrices([
|
||||
|
||||
@@ -4,301 +4,93 @@
|
||||
|
||||
# Order Attribution
|
||||
|
||||
> Attribute orders to your builder key for volume credit
|
||||
> Attribute orders to your builder code for volume credit and fee rewards
|
||||
|
||||
Order attribution adds builder authentication headers when placing orders through the CLOB, enabling Polymarket to credit trades to your builder account. This allows you to:
|
||||
Order attribution credits trades to your builder account by attaching your **builder code** to every order. This enables:
|
||||
|
||||
* Track volume on the [Builder Leaderboard](https://builders.polymarket.com/)
|
||||
* Earn rewards through the [Builder Program](/builders/overview)
|
||||
* Monitor performance via the Data API
|
||||
* Volume tracking on the [Builder Leaderboard](https://builders.polymarket.com/)
|
||||
* Fee rewards through the [Builder Program](/builders/overview)
|
||||
* Performance monitoring via the Data API
|
||||
|
||||
***
|
||||
|
||||
## Builder API Credentials
|
||||
## Builder Code
|
||||
|
||||
Each builder receives API credentials from their [Builder Profile](https://polymarket.com/settings?tab=builder):
|
||||
Your **builder code** is a `bytes32` identifier tied to your builder profile. Find it at [polymarket.com/settings?tab=builder](https://polymarket.com/settings?tab=builder).
|
||||
|
||||
| Credential | Description |
|
||||
| ------------ | ------------------------------------ |
|
||||
| `key` | Your builder API key identifier |
|
||||
| `secret` | Secret key for signing requests |
|
||||
| `passphrase` | Additional authentication passphrase |
|
||||
That's the only credential you need for attribution — no HMAC signing, no separate API key, no special headers.
|
||||
|
||||
<Warning>
|
||||
Builder API credentials are **not** the same as user API credentials. Builder
|
||||
credentials are for order attribution only — you still need user credentials
|
||||
for authentication. Never expose builder credentials in client-side code or
|
||||
commit them to version control.
|
||||
</Warning>
|
||||
<Note>
|
||||
Builder codes are public identifiers — they appear onchain in the `builder` field of every order you attribute. Only you control which orders include your code, so keep it scoped to apps you own.
|
||||
</Note>
|
||||
|
||||
***
|
||||
|
||||
## Remote Signing
|
||||
## Attaching the Builder Code
|
||||
|
||||
Remote signing keeps your builder credentials secure on a server you control. The user's client sends order details to your server, which adds the builder headers before forwarding to the CLOB.
|
||||
|
||||
### Server Implementation
|
||||
|
||||
Your signing server receives request details and returns the authentication headers:
|
||||
Pass `builderCode` in the order struct on every order you submit. The SDK serializes it into the onchain order's `builder` field, and the protocol attributes every matched trade to your profile.
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import {
|
||||
buildHmacSignature,
|
||||
BuilderApiKeyCreds,
|
||||
} from "@polymarket/builder-signing-sdk";
|
||||
import { ClobClient, Side, OrderType } from "@polymarket/clob-client-v2";
|
||||
|
||||
const BUILDER_CREDENTIALS: BuilderApiKeyCreds = {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
};
|
||||
const client = new ClobClient({
|
||||
host: "https://clob.polymarket.com",
|
||||
chain: 137,
|
||||
signer,
|
||||
creds: apiCreds,
|
||||
signatureType: 2,
|
||||
funderAddress,
|
||||
});
|
||||
|
||||
// POST /sign - receives { method, path, body } from the client SDK
|
||||
export async function handleSignRequest(request) {
|
||||
const { method, path, body } = await request.json();
|
||||
const timestamp = Date.now().toString();
|
||||
|
||||
const signature = buildHmacSignature(
|
||||
BUILDER_CREDENTIALS.secret,
|
||||
parseInt(timestamp),
|
||||
method,
|
||||
path,
|
||||
body,
|
||||
);
|
||||
|
||||
return {
|
||||
POLY_BUILDER_SIGNATURE: signature,
|
||||
POLY_BUILDER_TIMESTAMP: timestamp,
|
||||
POLY_BUILDER_API_KEY: BUILDER_CREDENTIALS.key,
|
||||
POLY_BUILDER_PASSPHRASE: BUILDER_CREDENTIALS.passphrase,
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
import os
|
||||
import time
|
||||
from py_builder_signing_sdk.signing.hmac import build_hmac_signature
|
||||
from py_builder_signing_sdk import BuilderApiKeyCreds
|
||||
|
||||
BUILDER_CREDENTIALS = BuilderApiKeyCreds(
|
||||
key=os.environ["POLY_BUILDER_API_KEY"],
|
||||
secret=os.environ["POLY_BUILDER_SECRET"],
|
||||
passphrase=os.environ["POLY_BUILDER_PASSPHRASE"],
|
||||
)
|
||||
|
||||
# POST /sign - receives { method, path, body } from the client SDK
|
||||
def handle_sign_request(method: str, path: str, body: str):
|
||||
timestamp = str(int(time.time()))
|
||||
|
||||
signature = build_hmac_signature(
|
||||
BUILDER_CREDENTIALS.secret,
|
||||
timestamp,
|
||||
method,
|
||||
path,
|
||||
body
|
||||
)
|
||||
|
||||
return {
|
||||
"POLY_BUILDER_SIGNATURE": signature,
|
||||
"POLY_BUILDER_TIMESTAMP": timestamp,
|
||||
"POLY_BUILDER_API_KEY": BUILDER_CREDENTIALS.key,
|
||||
"POLY_BUILDER_PASSPHRASE": BUILDER_CREDENTIALS.passphrase,
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
### Client Configuration
|
||||
|
||||
Point the CLOB client to your signing server:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { BuilderConfig } from "@polymarket/builder-signing-sdk";
|
||||
|
||||
const builderConfig = new BuilderConfig({
|
||||
remoteBuilderConfig: {
|
||||
url: "https://your-server.com/sign",
|
||||
token: "optional-auth-token", // optional
|
||||
const response = await client.createAndPostOrder(
|
||||
{
|
||||
tokenID: "0x...",
|
||||
price: 0.55,
|
||||
size: 100,
|
||||
side: Side.BUY,
|
||||
builderCode: "0xabc123...", // your builder code from polymarket.com/settings?tab=builder
|
||||
},
|
||||
});
|
||||
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer,
|
||||
apiCreds,
|
||||
2, // signature type
|
||||
funderAddress,
|
||||
undefined,
|
||||
false,
|
||||
builderConfig,
|
||||
{ tickSize: "0.01", negRisk: false },
|
||||
OrderType.GTC,
|
||||
);
|
||||
|
||||
// Orders automatically include builder headers
|
||||
const response = await client.createAndPostOrder(/* ... */);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk import BuilderConfig, RemoteBuilderConfig
|
||||
|
||||
builder_config = BuilderConfig(
|
||||
remote_builder_config=RemoteBuilderConfig(
|
||||
url="https://your-server.com/sign",
|
||||
token="optional-auth-token", # optional
|
||||
)
|
||||
)
|
||||
from py_clob_client.clob_types import OrderArgs, OrderType
|
||||
from py_clob_client.order_builder.constants import BUY
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
chain=137,
|
||||
key=private_key,
|
||||
creds=api_creds,
|
||||
signature_type=2,
|
||||
funder=funder_address,
|
||||
builder_config=builder_config
|
||||
)
|
||||
|
||||
# Orders automatically include builder headers
|
||||
response = client.create_and_post_order(...)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::auth::builder::Config as BuilderConfig;
|
||||
use polymarket_client_sdk::clob::types::SignatureType;
|
||||
|
||||
// First, authenticate as a normal user
|
||||
let client = Client::new("https://clob.polymarket.com", Config::default())?
|
||||
.authentication_builder(&signer)
|
||||
.signature_type(SignatureType::GnosisSafe)
|
||||
.authenticate()
|
||||
.await?;
|
||||
|
||||
// Then promote to builder with remote signing
|
||||
let builder_config = BuilderConfig::remote(
|
||||
"https://your-server.com/sign",
|
||||
Some("optional-auth-token".to_owned()),
|
||||
)?;
|
||||
let client = client.promote_to_builder(builder_config).await?;
|
||||
|
||||
// Orders automatically include builder headers
|
||||
response = client.create_and_post_order(
|
||||
OrderArgs(
|
||||
token_id="0x...",
|
||||
price=0.55,
|
||||
size=100,
|
||||
side=BUY,
|
||||
builder_code="0xabc123...", # your builder code from polymarket.com/settings?tab=builder
|
||||
),
|
||||
options={"tick_size": "0.01", "neg_risk": False},
|
||||
order_type=OrderType.GTC,
|
||||
)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
***
|
||||
|
||||
## Local Signing
|
||||
|
||||
Sign orders locally when you control the entire order placement flow (e.g., your backend places orders on behalf of users):
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import {
|
||||
BuilderConfig,
|
||||
BuilderApiKeyCreds,
|
||||
} from "@polymarket/builder-signing-sdk";
|
||||
|
||||
const builderCreds: BuilderApiKeyCreds = {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
};
|
||||
|
||||
const builderConfig = new BuilderConfig({
|
||||
localBuilderCreds: builderCreds,
|
||||
});
|
||||
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer,
|
||||
apiCreds,
|
||||
2,
|
||||
funderAddress,
|
||||
undefined,
|
||||
false,
|
||||
builderConfig,
|
||||
);
|
||||
|
||||
// Orders automatically include builder headers
|
||||
const response = await client.createAndPostOrder(/* ... */);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
import os
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk import BuilderConfig, BuilderApiKeyCreds
|
||||
|
||||
builder_creds = BuilderApiKeyCreds(
|
||||
key=os.environ["POLY_BUILDER_API_KEY"],
|
||||
secret=os.environ["POLY_BUILDER_SECRET"],
|
||||
passphrase=os.environ["POLY_BUILDER_PASSPHRASE"],
|
||||
)
|
||||
|
||||
builder_config = BuilderConfig(
|
||||
local_builder_creds=builder_creds,
|
||||
)
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
key=private_key,
|
||||
creds=api_creds,
|
||||
signature_type=2,
|
||||
funder=funder_address,
|
||||
builder_config=builder_config
|
||||
)
|
||||
|
||||
# Orders automatically include builder headers
|
||||
response = client.create_and_post_order(...)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::auth::{Credentials, builder::Config as BuilderConfig};
|
||||
|
||||
let builder_creds = Credentials::new(
|
||||
std::env::var("POLY_BUILDER_API_KEY")?.parse()?,
|
||||
std::env::var("POLY_BUILDER_SECRET")?,
|
||||
std::env::var("POLY_BUILDER_PASSPHRASE")?,
|
||||
);
|
||||
|
||||
let builder_config = BuilderConfig::local(builder_creds);
|
||||
let client = client.promote_to_builder(builder_config).await?;
|
||||
|
||||
// Orders automatically include builder headers
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
***
|
||||
|
||||
## Authentication Headers
|
||||
|
||||
The SDK automatically generates and attaches these headers to each request:
|
||||
|
||||
| Header | Description |
|
||||
| ------------------------- | ------------------------------------ |
|
||||
| `POLY_BUILDER_API_KEY` | Your builder API key |
|
||||
| `POLY_BUILDER_TIMESTAMP` | Unix timestamp of signature creation |
|
||||
| `POLY_BUILDER_PASSPHRASE` | Your builder passphrase |
|
||||
| `POLY_BUILDER_SIGNATURE` | HMAC signature of the request |
|
||||
|
||||
<Info>
|
||||
With **local signing**, the SDK constructs and attaches these headers
|
||||
automatically. With **remote signing**, your server returns these headers and
|
||||
the SDK attaches them.
|
||||
</Info>
|
||||
Every order placed with `builderCode` attached is credited to your builder profile — no additional configuration needed.
|
||||
|
||||
***
|
||||
|
||||
## Verifying Attribution
|
||||
|
||||
### Get Builder Trades
|
||||
|
||||
Query trades attributed to your builder account to verify attribution is working:
|
||||
Query trades attributed to your builder code:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
@@ -317,62 +109,23 @@ Query trades attributed to your builder account to verify attribution is working
|
||||
market="0xbd31dc8a..."
|
||||
)
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
use polymarket_client_sdk::clob::types::request::TradesRequest;
|
||||
|
||||
let trades = client.builder_trades(&TradesRequest::default(), None).await?;
|
||||
|
||||
// Filtered by market
|
||||
let request = TradesRequest::builder()
|
||||
.market("0xbd31dc8a...".parse()?)
|
||||
.build();
|
||||
let market_trades = client.builder_trades(&request, None).await?;
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
Each `BuilderTrade` includes: `id`, `market`, `assetId`, `side`, `size`, `price`, `status`, `outcome`, `owner`, `maker`, `transactionHash`, `matchTime`, `fee`, and `feeUsdc`.
|
||||
|
||||
### Revoke Builder API Key
|
||||
|
||||
If your credentials are compromised, revoke them immediately:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
await client.revokeBuilderApiKey();
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
client.revoke_builder_api_key()
|
||||
```
|
||||
|
||||
```rust Rust theme={null}
|
||||
client.revoke_builder_api_key().await?;
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
After revoking, generate new credentials from your [Builder Profile](https://polymarket.com/settings?tab=builder).
|
||||
Each `BuilderTrade` includes: `id`, `market`, `assetId`, `side`, `size`, `price`, `status`, `outcome`, `owner`, `maker`, `builder`, `transactionHash`, `matchTime`, `fee`, and `feeUsdc`.
|
||||
|
||||
***
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Invalid Signature Errors">
|
||||
* Verify the request body is passed correctly as JSON - Check that `path`,
|
||||
`body`, and `method` match what the client sends - Ensure your server and
|
||||
client use the same Builder API credentials
|
||||
<Accordion title="Volume not appearing on the leaderboard">
|
||||
* Confirm your `builderCode` is correctly attached to every order
|
||||
* Check that orders are being matched (not just placed)
|
||||
* Allow up to 24 hours for volume to appear on the leaderboard
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Missing Credentials">
|
||||
Ensure your environment variables are set: - `POLY_BUILDER_API_KEY` -
|
||||
`POLY_BUILDER_SECRET` - `POLY_BUILDER_PASSPHRASE`
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Volume not appearing on leaderboard">
|
||||
* Confirm your builder credentials are valid and not revoked - Check that
|
||||
orders are being placed with the builder config attached - Allow up to 24
|
||||
hours for volume to appear on the leaderboard
|
||||
<Accordion title="Invalid builder code">
|
||||
Verify the code matches what's shown on [your Builder Profile](https://polymarket.com/settings?tab=builder). Builder codes are `bytes32` hex values starting with `0x`.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
|
||||
@@ -149,16 +149,6 @@ Cancel all orders for a specific market, optionally filtered to a single token.
|
||||
|
||||
***
|
||||
|
||||
## Onchain Cancellation
|
||||
|
||||
If the API is unavailable, you can cancel orders directly on the [Exchange contract](https://github.com/Polymarket/ctf-exchange/tree/main/src) by calling `cancelOrder(Order order)` onchain. Pass the full order struct that was signed when placing the order.
|
||||
|
||||
Use the `CTFExchange` or `NegRiskCTFExchange` contract depending on the market type. See [Contract Addresses](/resources/contract-addresses) for addresses.
|
||||
|
||||
This is a fallback mechanism — API cancellation is instant while onchain cancellation requires a transaction.
|
||||
|
||||
***
|
||||
|
||||
## Querying Orders
|
||||
|
||||
### Get a Single Order
|
||||
|
||||
@@ -39,7 +39,7 @@ The simplest way to place a limit order — create, sign, and submit in one call
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient, Side, OrderType } from "@polymarket/clob-client";
|
||||
import { ClobClient, Side, OrderType } from "@polymarket/clob-client-v2";
|
||||
|
||||
const response = await client.createAndPostOrder(
|
||||
{
|
||||
@@ -238,7 +238,7 @@ Market orders execute immediately against resting liquidity using FOK or FAK typ
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { Side, OrderType } from "@polymarket/clob-client";
|
||||
import { Side, OrderType } from "@polymarket/clob-client-v2";
|
||||
|
||||
// FOK BUY: spend exactly $100 or cancel entirely
|
||||
const buyOrder = await client.createMarketOrder(
|
||||
@@ -413,7 +413,7 @@ Place up to **15 orders** in a single request:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { OrderType, Side, PostOrdersArgs } from "@polymarket/clob-client";
|
||||
import { OrderType, Side, PostOrdersArgs } from "@polymarket/clob-client-v2";
|
||||
|
||||
const orders: PostOrdersArgs[] = [
|
||||
{
|
||||
@@ -559,7 +559,7 @@ Multi-outcome events (3+ outcomes) use the Neg Risk CTF Exchange. Pass `negRisk:
|
||||
|
||||
Before placing an order, your funder address must have approved the Exchange contract to spend the relevant tokens:
|
||||
|
||||
* **BUY orders**: USDC.e allowance >= spending amount
|
||||
* **BUY orders**: pUSD allowance >= spending amount
|
||||
* **SELL orders**: conditional token allowance >= selling amount
|
||||
|
||||
Order size is limited by your available balance minus amounts reserved by existing open orders:
|
||||
@@ -569,21 +569,11 @@ $$
|
||||
$$
|
||||
|
||||
<Warning>
|
||||
Orders are continuously monitored for validity — balances, allowances, and
|
||||
onchain cancellations are tracked in real time. Any maker caught intentionally
|
||||
abusing these checks will be blacklisted.
|
||||
Orders are continuously monitored for validity — balances and allowances are
|
||||
tracked in real time. Any maker caught intentionally abusing these checks
|
||||
will be blacklisted.
|
||||
</Warning>
|
||||
|
||||
### Advanced Parameters
|
||||
|
||||
These optional fields can be passed in the `UserOrder` object for fine-grained control:
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| ------------ | ------ | ----------------------------------------------- |
|
||||
| `feeRateBps` | number | Fee rate in basis points (default: market rate) |
|
||||
| `nonce` | number | Custom nonce for order uniqueness |
|
||||
| `taker` | string | Restrict the order to a specific taker address |
|
||||
|
||||
### Sports Markets
|
||||
|
||||
Sports markets have additional behaviors:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
All orders on Polymarket are expressed as **limit orders**. Market orders are supported by submitting a limit order with a marketable price — your order executes immediately at the best available price on the book.
|
||||
|
||||
The underlying order primitive is structured, hashed, and signed using the [EIP-712](https://eips.ethereum.org/EIPS/eip-712) standard, then executed onchain via the Exchange contract. Preparing orders manually is involved, so we recommend using the open-source [TypeScript](https://github.com/Polymarket/clob-client) or [Python](https://github.com/Polymarket/py-clob-client) SDK clients, which handle signing and submission for you.
|
||||
The underlying order primitive is structured, hashed, and signed using the [EIP-712](https://eips.ethereum.org/EIPS/eip-712) standard, then executed onchain via the Exchange contract. Preparing orders manually is involved, so we recommend using the open-source [TypeScript](https://github.com/Polymarket/clob-client-v2) or [Python](https://github.com/Polymarket/py-clob-client-v2) SDK clients, which handle signing and submission for you.
|
||||
|
||||
<Info>
|
||||
If you prefer to use the REST API directly, you'll need to manage order
|
||||
@@ -158,7 +158,7 @@ You can check whether a market uses negative risk via the SDK or the market obje
|
||||
|
||||
Before placing an order, your funder address must have approved the Exchange contract to spend the relevant tokens:
|
||||
|
||||
* **Buying**: the funder must have set a **USDC.e** allowance greater than or equal to the spending amount.
|
||||
* **Buying**: the funder must have set a **pUSD** allowance greater than or equal to the spending amount.
|
||||
* **Selling**: the funder must have set a **conditional token** allowance greater than or equal to the selling amount.
|
||||
|
||||
This allows the Exchange contract to execute settlement according to your signed order instructions.
|
||||
@@ -171,13 +171,12 @@ Orders are continually monitored to make sure they remain valid. This includes t
|
||||
|
||||
* Underlying balances
|
||||
* Allowances
|
||||
* Onchain order cancellations
|
||||
|
||||
<Warning>
|
||||
Any maker caught intentionally abusing these checks will be blacklisted.
|
||||
</Warning>
|
||||
|
||||
There are also limits on order placement per market. You can only place orders that sum to less than or equal to your available balance for each market. For example, if you have 500 USDC.e in your funding wallet, you can place one order to buy 1000 YES at \$0.50 — but any additional buy orders in that market will be rejected since your entire balance is reserved for the first order.
|
||||
There are also limits on order placement per market. You can only place orders that sum to less than or equal to your available balance for each market. For example, if you have 500 pUSD in your funding wallet, you can place one order to buy 1000 YES at \$0.50 — but any additional buy orders in that market will be rejected since your entire balance is reserved for the first order.
|
||||
|
||||
The max size you can place for an order is:
|
||||
|
||||
@@ -475,16 +474,16 @@ Check if your resting orders are eligible for [maker rebates](/market-makers/mak
|
||||
|
||||
When a trade is settled onchain, the Exchange contract emits an `OrderFilled` event with the following fields:
|
||||
|
||||
| Field | Description |
|
||||
| ------------------- | ----------------------------------------------------------------------------------------------- |
|
||||
| `orderHash` | Unique hash for the filled order |
|
||||
| `maker` | The user who generated the order and source of funds |
|
||||
| `taker` | The user filling the order, or the Exchange contract if multiple limit orders are filled |
|
||||
| `makerAssetId` | ID of the asset given out. If `0`, the order is a **BUY** (giving USDC.e for outcome tokens) |
|
||||
| `takerAssetId` | ID of the asset received. If `0`, the order is a **SELL** (receiving USDC.e for outcome tokens) |
|
||||
| `makerAmountFilled` | Amount of the asset given out |
|
||||
| `takerAmountFilled` | Amount of the asset received |
|
||||
| `fee` | Fees paid by the order maker |
|
||||
| Field | Description |
|
||||
| ------------------- | --------------------------------------------------------------------------------------------- |
|
||||
| `orderHash` | Unique hash for the filled order |
|
||||
| `maker` | The user who generated the order and source of funds |
|
||||
| `taker` | The user filling the order, or the Exchange contract if multiple limit orders are filled |
|
||||
| `makerAssetId` | ID of the asset given out. If `0`, the order is a **BUY** (giving pUSD for outcome tokens) |
|
||||
| `takerAssetId` | ID of the asset received. If `0`, the order is a **SELL** (receiving pUSD for outcome tokens) |
|
||||
| `makerAmountFilled` | Amount of the asset given out |
|
||||
| `takerAmountFilled` | Amount of the asset received |
|
||||
| `fee` | Fees paid by the order maker |
|
||||
|
||||
***
|
||||
|
||||
@@ -525,7 +524,7 @@ When an order is successfully placed, the response includes a `status` field:
|
||||
|
||||
Polymarket's Exchange contract has been audited by Chainsecurity ([View Audit](https://github.com/Polymarket/ctf-exchange/blob/main/audit/ChainSecurity_Polymarket_Exchange_audit.pdf)).
|
||||
|
||||
The operator's privileges are limited to order matching and ensuring correct ordering. Operators cannot set prices or execute unauthorized trades. Users can cancel orders onchain independently if trust issues arise.
|
||||
The operator's privileges are limited to order matching and ensuring correct ordering. Operators cannot set prices or execute unauthorized trades.
|
||||
|
||||
***
|
||||
|
||||
|
||||
+19
-19
@@ -6,22 +6,22 @@
|
||||
|
||||
> Trading on the Polymarket CLOB
|
||||
|
||||
Polymarket's CLOB (Central Limit Order Book) is a hybrid-decentralized trading system — offchain order matching with onchain settlement via the [Exchange contract](https://github.com/Polymarket/ctf-exchange/tree/main/src) ([audited by Chainsecurity](https://github.com/Polymarket/ctf-exchange/blob/main/audit/ChainSecurity_Polymarket_Exchange_audit.pdf)). All trading is non-custodial. Orders are [EIP-712](https://eips.ethereum.org/EIPS/eip-712) signed messages, and matched trades settle atomically on Polygon. The operator cannot set prices or execute unauthorized trades — users can always cancel orders onchain independently.
|
||||
Polymarket's CLOB (Central Limit Order Book) is a hybrid-decentralized trading system — offchain order matching with onchain settlement via the [Exchange contract](https://github.com/Polymarket/ctf-exchange/tree/main/src) ([audited by Chainsecurity](https://github.com/Polymarket/ctf-exchange/blob/main/audit/ChainSecurity_Polymarket_Exchange_audit.pdf)). All trading is non-custodial. Orders are [EIP-712](https://eips.ethereum.org/EIPS/eip-712) signed messages, and matched trades settle atomically on Polygon. The operator cannot set prices or execute unauthorized trades.
|
||||
|
||||
We recommend using the open-source SDK clients, which handle order signing, authentication, and submission:
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="TypeScript Client" icon="github" href="https://github.com/Polymarket/clob-client">
|
||||
<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
|
||||
npm install @polymarket/clob-client-v2
|
||||
</p>
|
||||
</Card>
|
||||
|
||||
<Card title="Python Client" icon="github" href="https://github.com/Polymarket/py-clob-client">
|
||||
<p className="font-mono text-[0.8rem]">pip install py-clob-client</p>
|
||||
<Card title="Python Client" icon="github" href="https://github.com/Polymarket/py-clob-client-v2">
|
||||
<p className="font-mono text-[0.8rem]">pip install py-clob-client-v2</p>
|
||||
</Card>
|
||||
|
||||
<Card title="Rust Client" icon="github" href="https://github.com/Polymarket/rs-clob-client">
|
||||
<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>
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -29,9 +29,9 @@ We recommend using the open-source SDK clients, which handle order signing, auth
|
||||
<Info>
|
||||
You can also use the REST API directly, but you'll need to manage [EIP-712
|
||||
order
|
||||
signing](https://github.com/Polymarket/clob-client/blob/main/src/signing/eip712.ts)
|
||||
signing](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/eip712.ts)
|
||||
and [HMAC authentication
|
||||
headers](https://github.com/Polymarket/clob-client/blob/main/src/signing/hmac.ts)
|
||||
headers](https://github.com/Polymarket/clob-client-v2/blob/main/src/signing/hmac.ts)
|
||||
yourself. See [REST API Headers](#rest-api-headers) below.
|
||||
</Info>
|
||||
|
||||
@@ -50,13 +50,13 @@ 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";
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers"; // v5.8.0
|
||||
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
|
||||
// Derive L2 API credentials
|
||||
const tempClient = new ClobClient("https://clob.polymarket.com", 137, signer);
|
||||
const tempClient = new ClobClient({ host: "https://clob.polymarket.com", chain: 137, signer });
|
||||
const apiCreds = await tempClient.createOrDeriveApiKey();
|
||||
```
|
||||
|
||||
@@ -67,7 +67,7 @@ You use your private key once to derive **L2 credentials** (API key, secret, pas
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive L2 API credentials
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain_id=137)
|
||||
temp_client = ClobClient("https://clob.polymarket.com", key=private_key, chain=137)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
```
|
||||
|
||||
@@ -111,21 +111,21 @@ When initializing the trading client, you must specify your wallet's **signature
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
const client = new ClobClient({
|
||||
host: "https://clob.polymarket.com",
|
||||
chain: 137,
|
||||
signer,
|
||||
apiCreds,
|
||||
2, // GNOSIS_SAFE
|
||||
"0x...", // Your proxy wallet address
|
||||
);
|
||||
creds: apiCreds,
|
||||
signatureType: 2, // GNOSIS_SAFE
|
||||
funderAddress: "0x...", // Your proxy wallet address
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
client = ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
key=private_key,
|
||||
chain_id=137,
|
||||
chain=137,
|
||||
creds=api_creds,
|
||||
signature_type=2, # GNOSIS_SAFE
|
||||
funder="0x..." # Your proxy wallet address
|
||||
|
||||
+19
-19
@@ -12,11 +12,11 @@ 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 ethers@5
|
||||
npm install @polymarket/clob-client-v2 ethers@5
|
||||
```
|
||||
|
||||
```bash Python theme={null}
|
||||
pip install py-clob-client
|
||||
pip install py-clob-client-v2
|
||||
```
|
||||
|
||||
```bash Rust theme={null}
|
||||
@@ -30,7 +30,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { ClobClient } from "@polymarket/clob-client-v2";
|
||||
import { Wallet } from "ethers"; // v5.8.0
|
||||
|
||||
const HOST = "https://clob.polymarket.com";
|
||||
@@ -38,18 +38,18 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
const signer = new Wallet(process.env.PRIVATE_KEY);
|
||||
|
||||
// Derive API credentials
|
||||
const tempClient = new ClobClient(HOST, CHAIN_ID, signer);
|
||||
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
|
||||
const apiCreds = await tempClient.createOrDeriveApiKey();
|
||||
|
||||
// Initialize trading client
|
||||
const client = new ClobClient(
|
||||
HOST,
|
||||
CHAIN_ID,
|
||||
const client = new ClobClient({
|
||||
host: HOST,
|
||||
chain: CHAIN_ID,
|
||||
signer,
|
||||
apiCreds,
|
||||
0, // EOA
|
||||
signer.address,
|
||||
);
|
||||
creds: apiCreds,
|
||||
signatureType: 0, // EOA
|
||||
funderAddress: signer.address,
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
@@ -57,18 +57,18 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
import os
|
||||
|
||||
host = "https://clob.polymarket.com"
|
||||
chain_id = 137 # Polygon mainnet
|
||||
chain = 137 # Polygon mainnet
|
||||
private_key = os.getenv("PRIVATE_KEY")
|
||||
|
||||
# Derive API credentials
|
||||
temp_client = ClobClient(host, key=private_key, chain_id=chain_id)
|
||||
temp_client = ClobClient(host, key=private_key, chain=chain)
|
||||
api_creds = temp_client.create_or_derive_api_creds()
|
||||
|
||||
# Initialize trading client
|
||||
client = ClobClient(
|
||||
host,
|
||||
key=private_key,
|
||||
chain_id=chain_id,
|
||||
chain=chain,
|
||||
creds=api_creds,
|
||||
signature_type=0, # EOA
|
||||
funder="YOUR_WALLET_ADDRESS"
|
||||
@@ -100,7 +100,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
</Note>
|
||||
|
||||
<Warning>
|
||||
Before trading, your funder address needs **USDC.e** (for buying outcome
|
||||
Before trading, your funder address needs **pUSD** (for buying outcome
|
||||
tokens) and **POL** (for gas, if using EOA type `0`). Proxy wallet users
|
||||
(types `1` and `2`) can use Polymarket's gasless relayer instead.
|
||||
</Warning>
|
||||
@@ -111,7 +111,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { Side, OrderType } from "@polymarket/clob-client";
|
||||
import { Side, OrderType } from "@polymarket/clob-client-v2";
|
||||
|
||||
const response = await client.createAndPostOrder(
|
||||
{
|
||||
@@ -237,7 +237,7 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<Accordion title="L2 AUTH NOT AVAILABLE - Invalid Signature">
|
||||
Wrong private key, signature type, or funder address for the derived API credentials.
|
||||
|
||||
* Check that `signatureType` matches your account type (`0`, `1`, or `2`)
|
||||
* Check that `signatureType` matches your account type (`0`, `1`, `2`, or `3`)
|
||||
* Ensure `funder` is correct for your wallet type
|
||||
* Re-derive credentials with `createOrDeriveApiKey()` if unsure
|
||||
</Accordion>
|
||||
@@ -245,9 +245,9 @@ This guide walks you through placing an order on Polymarket end-to-end.
|
||||
<Accordion title="Order rejected - insufficient balance">
|
||||
Your funder address doesn't have enough tokens:
|
||||
|
||||
* **BUY orders**: need USDC.e in your funder address
|
||||
* **BUY orders**: need pUSD in your funder address
|
||||
* **SELL orders**: need outcome tokens in your funder address
|
||||
* Ensure you have more USDC.e than what's committed in open orders
|
||||
* Ensure you have more pUSD than what's committed in open orders
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Order rejected - insufficient allowance">
|
||||
|
||||
Reference in New Issue
Block a user