Update Polymarket documentation (2026-02-19)
- Added new documentation URLs from llms.txt index - Updated TARGET.md with 244 total documentation pages - Scraped new pages for trading, concepts, and API reference sections - Updated changelog and new index pages
This commit is contained in:
@@ -4,20 +4,19 @@
|
||||
|
||||
# Order Attribution
|
||||
|
||||
> Learn how to attribute orders to your builder account
|
||||
> Attribute orders to your builder key for volume credit
|
||||
|
||||
## Overview
|
||||
|
||||
The [CLOB (Central Limit Order Book)](/developers/CLOB/introduction) is Polymarket's order matching system. Order attribution adds builder authentication headers when placing orders through the CLOB Client, enabling Polymarket to credit trades to your builder account. This allows you to:
|
||||
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:
|
||||
|
||||
* Track volume on the [Builder Leaderboard](https://builders.polymarket.com/)
|
||||
* Earn rewards through the [Builder Program](/builders/overview)
|
||||
* Monitor performance via the Data API
|
||||
|
||||
***
|
||||
|
||||
## Builder API Credentials
|
||||
|
||||
Each builder receives API credentials from their [Builder Profile](/developers/builders/builder-profile):
|
||||
Each builder receives API credentials from their [Builder Profile](https://polymarket.com/settings?tab=builder):
|
||||
|
||||
| Credential | Description |
|
||||
| ------------ | ------------------------------------ |
|
||||
@@ -26,305 +25,217 @@ Each builder receives API credentials from their [Builder Profile](/developers/b
|
||||
| `passphrase` | Additional authentication passphrase |
|
||||
|
||||
<Warning>
|
||||
**Security Notice**: Your Builder API keys must be kept secure. Never expose them in client-side code.
|
||||
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>
|
||||
|
||||
***
|
||||
|
||||
## Signing Methods
|
||||
## Remote Signing (Recommended)
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Remote Signing (Recommended)">
|
||||
Remote signing keeps your credentials secure on a server you control.
|
||||
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.
|
||||
|
||||
**How it works:**
|
||||
### Server Implementation
|
||||
|
||||
1. User signs an order payload
|
||||
2. Payload is sent to your builder signing server
|
||||
3. Your server adds builder authentication headers
|
||||
4. Complete order is sent to the CLOB
|
||||
Your signing server receives request details and returns the authentication headers:
|
||||
|
||||
### Server Implementation
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import {
|
||||
buildHmacSignature,
|
||||
BuilderApiKeyCreds,
|
||||
} from "@polymarket/builder-signing-sdk";
|
||||
|
||||
Your signing server receives request details and returns the authentication headers. Use the `buildHmacSignature` function from the SDK:
|
||||
const BUILDER_CREDENTIALS: BuilderApiKeyCreds = {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
};
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import {
|
||||
buildHmacSignature,
|
||||
BuilderApiKeyCreds
|
||||
} from "@polymarket/builder-signing-sdk";
|
||||
// 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 BUILDER_CREDENTIALS: BuilderApiKeyCreds = {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
};
|
||||
const signature = buildHmacSignature(
|
||||
BUILDER_CREDENTIALS.secret,
|
||||
parseInt(timestamp),
|
||||
method,
|
||||
path,
|
||||
body,
|
||||
);
|
||||
|
||||
// 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(
|
||||
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,
|
||||
parseInt(timestamp),
|
||||
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,
|
||||
};
|
||||
return {
|
||||
"POLY_BUILDER_SIGNATURE": signature,
|
||||
"POLY_BUILDER_TIMESTAMP": timestamp,
|
||||
"POLY_BUILDER_API_KEY": BUILDER_CREDENTIALS.key,
|
||||
"POLY_BUILDER_PASSPHRASE": BUILDER_CREDENTIALS.passphrase,
|
||||
}
|
||||
```
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
```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
|
||||
### Client Configuration
|
||||
|
||||
BUILDER_CREDENTIALS = BuilderApiKeyCreds(
|
||||
key=os.environ["POLY_BUILDER_API_KEY"],
|
||||
secret=os.environ["POLY_BUILDER_SECRET"],
|
||||
passphrase=os.environ["POLY_BUILDER_PASSPHRASE"],
|
||||
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 client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer,
|
||||
apiCreds,
|
||||
2, // signature type
|
||||
funderAddress,
|
||||
undefined,
|
||||
false,
|
||||
builderConfig,
|
||||
);
|
||||
|
||||
// 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
|
||||
)
|
||||
)
|
||||
|
||||
# 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
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
return {
|
||||
"POLY_BUILDER_SIGNATURE": signature,
|
||||
"POLY_BUILDER_TIMESTAMP": timestamp,
|
||||
"POLY_BUILDER_API_KEY": BUILDER_CREDENTIALS.key,
|
||||
"POLY_BUILDER_PASSPHRASE": BUILDER_CREDENTIALS.passphrase,
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
# Orders automatically include builder headers
|
||||
response = client.create_and_post_order(...)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Warning>
|
||||
Never commit credentials to version control. Use environment variables or a secrets manager.
|
||||
</Warning>
|
||||
***
|
||||
|
||||
### Client Configuration
|
||||
## Local Signing
|
||||
|
||||
Point your client to your signing server:
|
||||
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 } from "@polymarket/builder-signing-sdk";
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import {
|
||||
BuilderConfig,
|
||||
BuilderApiKeyCreds,
|
||||
} from "@polymarket/builder-signing-sdk";
|
||||
|
||||
// Point to your signing server
|
||||
const builderConfig = new BuilderConfig({
|
||||
remoteBuilderConfig: {
|
||||
url: "https://your-server.com/sign"
|
||||
}
|
||||
});
|
||||
const builderCreds: BuilderApiKeyCreds = {
|
||||
key: process.env.POLY_BUILDER_API_KEY!,
|
||||
secret: process.env.POLY_BUILDER_SECRET!,
|
||||
passphrase: process.env.POLY_BUILDER_PASSPHRASE!,
|
||||
};
|
||||
|
||||
// Or with optional authorization token
|
||||
const builderConfigWithAuth = new BuilderConfig({
|
||||
remoteBuilderConfig: {
|
||||
url: "https://your-server.com/sign",
|
||||
token: "your-auth-token"
|
||||
}
|
||||
});
|
||||
const builderConfig = new BuilderConfig({
|
||||
localBuilderCreds: builderCreds,
|
||||
});
|
||||
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer, // ethers v5.x EOA signer
|
||||
creds, // User's API Credentials
|
||||
2, // signatureType for the Safe proxy wallet
|
||||
funderAddress, // Safe proxy wallet address
|
||||
undefined,
|
||||
false,
|
||||
builderConfig
|
||||
);
|
||||
const client = new ClobClient(
|
||||
"https://clob.polymarket.com",
|
||||
137,
|
||||
signer,
|
||||
apiCreds,
|
||||
2,
|
||||
funderAddress,
|
||||
undefined,
|
||||
false,
|
||||
builderConfig,
|
||||
);
|
||||
|
||||
// Orders automatically use the signing server
|
||||
const order = await client.createOrder({
|
||||
price: 0.40,
|
||||
side: Side.BUY,
|
||||
size: 5,
|
||||
tokenID: "YOUR_TOKEN_ID"
|
||||
});
|
||||
// Orders automatically include builder headers
|
||||
const response = await client.createAndPostOrder(/* ... */);
|
||||
```
|
||||
|
||||
const response = await client.postOrder(order);
|
||||
```
|
||||
```python Python theme={null}
|
||||
import os
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk import BuilderConfig, BuilderApiKeyCreds
|
||||
|
||||
```python Python theme={null}
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk import BuilderConfig, RemoteBuilderConfig
|
||||
builder_creds = BuilderApiKeyCreds(
|
||||
key=os.environ["POLY_BUILDER_API_KEY"],
|
||||
secret=os.environ["POLY_BUILDER_SECRET"],
|
||||
passphrase=os.environ["POLY_BUILDER_PASSPHRASE"],
|
||||
)
|
||||
|
||||
# Point to your signing server
|
||||
builder_config = BuilderConfig(
|
||||
remote_builder_config=RemoteBuilderConfig(
|
||||
url="https://your-server.com/sign"
|
||||
)
|
||||
)
|
||||
builder_config = BuilderConfig(
|
||||
local_builder_creds=builder_creds,
|
||||
)
|
||||
|
||||
# Or with optional authorization token
|
||||
builder_config_with_auth = BuilderConfig(
|
||||
remote_builder_config=RemoteBuilderConfig(
|
||||
url="https://your-server.com/sign",
|
||||
token="your-auth-token"
|
||||
)
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
client = ClobClient(
|
||||
host="https://clob.polymarket.com",
|
||||
chain_id=137,
|
||||
key=private_key,
|
||||
creds=creds, # User's API Credentials
|
||||
signature_type=2, # signatureType for the Safe proxy wallet
|
||||
funder=funder_address, # Safe proxy wallet address
|
||||
builder_config=builder_config
|
||||
)
|
||||
|
||||
# Orders automatically use the signing server
|
||||
order = client.create_order({
|
||||
"price": 0.40,
|
||||
"side": "BUY",
|
||||
"size": 5,
|
||||
"token_id": "YOUR_TOKEN_ID"
|
||||
})
|
||||
|
||||
response = client.post_order(order)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Invalid Signature Errors">
|
||||
**Error:** Client receives invalid signature errors
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify the request body is passed correctly as JSON
|
||||
2. Check that `path`, `body`, and `method` match what the client sends
|
||||
3. Ensure your server and client use the same Builder API credentials
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Missing Credentials">
|
||||
**Error:** `Builder credentials not configured` or undefined values
|
||||
|
||||
**Solution:** Ensure your environment variables are set:
|
||||
|
||||
* `POLY_BUILDER_API_KEY`
|
||||
* `POLY_BUILDER_SECRET`
|
||||
* `POLY_BUILDER_PASSPHRASE`
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
</Tab>
|
||||
|
||||
<Tab title="Local Signing">
|
||||
Sign orders locally when you control the entire order placement flow.
|
||||
|
||||
**How it works:**
|
||||
|
||||
1. Your system creates and signs orders on behalf of users
|
||||
2. Your system uses Builder API credentials locally to add headers
|
||||
3. Complete signed order is sent directly to the CLOB
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
import { ClobClient } from "@polymarket/clob-client";
|
||||
import { BuilderConfig, BuilderApiKeyCreds } from "@polymarket/builder-signing-sdk";
|
||||
|
||||
// Configure with local builder credentials
|
||||
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, // ethers v5.x EOA signer
|
||||
creds, // User's API Credentials
|
||||
2, // signatureType for the Safe proxy wallet
|
||||
funderAddress, // Safe proxy wallet address
|
||||
undefined,
|
||||
false,
|
||||
builderConfig
|
||||
);
|
||||
|
||||
// Orders automatically include builder headers
|
||||
const order = await client.createOrder({
|
||||
price: 0.40,
|
||||
side: Side.BUY,
|
||||
size: 5,
|
||||
tokenID: "YOUR_TOKEN_ID"
|
||||
});
|
||||
|
||||
const response = await client.postOrder(order);
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
import os
|
||||
from py_clob_client.client import ClobClient
|
||||
from py_builder_signing_sdk import BuilderConfig, BuilderApiKeyCreds
|
||||
|
||||
# Configure with local builder credentials
|
||||
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=creds, # User's API Credentials
|
||||
signature_type=2, # signatureType for the Safe proxy wallet
|
||||
funder=funder_address, # Safe proxy wallet address
|
||||
builder_config=builder_config
|
||||
)
|
||||
|
||||
# Orders automatically include builder headers
|
||||
order = client.create_order({
|
||||
"price": 0.40,
|
||||
"side": "BUY",
|
||||
"size": 5,
|
||||
"token_id": "YOUR_TOKEN_ID"
|
||||
})
|
||||
|
||||
response = client.post_order(order)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Warning>
|
||||
Never commit credentials to version control. Use environment variables or a secrets manager.
|
||||
</Warning>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
# Orders automatically include builder headers
|
||||
response = client.create_and_post_order(...)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
***
|
||||
|
||||
@@ -340,19 +251,89 @@ The SDK automatically generates and attaches these headers to each request:
|
||||
| `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 must return these headers (see Server Implementation above), and the SDK attaches them to the request.
|
||||
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>
|
||||
|
||||
***
|
||||
|
||||
## Verifying Attribution
|
||||
|
||||
### Get Builder Trades
|
||||
|
||||
Query trades attributed to your builder account to verify attribution is working:
|
||||
|
||||
<CodeGroup>
|
||||
```typescript TypeScript theme={null}
|
||||
const trades = await client.getBuilderTrades();
|
||||
|
||||
// Filtered by market
|
||||
const marketTrades = await client.getBuilderTrades({
|
||||
market: "0xbd31dc8a...",
|
||||
});
|
||||
```
|
||||
|
||||
```python Python theme={null}
|
||||
trades = client.get_builder_trades()
|
||||
|
||||
market_trades = client.get_builder_trades(
|
||||
market="0xbd31dc8a..."
|
||||
)
|
||||
```
|
||||
</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()
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
After revoking, generate new credentials from your [Builder Profile](https://polymarket.com/settings?tab=builder).
|
||||
|
||||
***
|
||||
|
||||
## 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>
|
||||
|
||||
<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>
|
||||
</AccordionGroup>
|
||||
|
||||
***
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Relayer Client" icon="bolt" href="/developers/builders/relayer-client">
|
||||
Learn how to configure and use the Relay Client too!
|
||||
<Card title="Builder Program" icon="hammer" href="/builders/overview">
|
||||
Learn about the Builder Program tiers and rewards
|
||||
</Card>
|
||||
|
||||
<Card title="CLOB Client Methods" icon="book" href="/developers/CLOB/clients/methods-overview">
|
||||
Explore the complete CLOB client reference
|
||||
<Card title="Create Orders" icon="plus" href="/trading/orders/create">
|
||||
Build, sign, and submit orders
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
Reference in New Issue
Block a user