Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.polymarket.com/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through placing an order on Polymarket end-to-end.
1

Install the SDK

npm install @polymarket/clob-client-v2 viem
2

Set Up Your Client

Derive your API credentials and initialize the trading client. This example uses a deposit wallet with signature type 3 (POLY_1271), which is the wallet path for new API users:
import { ClobClient, SignatureTypeV2 } from "@polymarket/clob-client-v2";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";

const HOST = "https://clob.polymarket.com";
const CHAIN_ID = 137; // Polygon mainnet
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const signer = createWalletClient({ account, transport: http() });
const depositWalletAddress = process.env.DEPOSIT_WALLET_ADDRESS!;

// Derive API credentials
const tempClient = new ClobClient({ host: HOST, chain: CHAIN_ID, signer });
const apiCreds = await tempClient.createOrDeriveApiKey();

// Initialize trading client
const client = new ClobClient({
  host: HOST,
  chain: CHAIN_ID,
  signer,
  creds: apiCreds,
  signatureType: SignatureTypeV2.POLY_1271,
  funderAddress: depositWalletAddress,
});
Existing EOA, Safe, and Proxy integrations can keep using their current signature type and funder address. See Signature Types for all wallet types.
Before trading from a deposit wallet, the deposit wallet needs pUSD and the required trading approvals. See the Deposit Wallet Guide for wallet creation, funding, approvals, and balance sync.
3

Place an Order

Get a token ID from the Markets API, then create and submit your order:
import { Side, OrderType } from "@polymarket/clob-client-v2";

const response = await client.createAndPostOrder(
  {
    tokenID: "YOUR_TOKEN_ID",
    price: 0.5,
    size: 10,
    side: Side.BUY,
  },
  {
    tickSize: "0.01",
    negRisk: false, // Set to true for multi-outcome markets
  },
  OrderType.GTC,
);

console.log("Order ID:", response.orderID);
console.log("Status:", response.status);
Look up a market’s tickSize and negRisk values using the SDK’s getTickSize() and getNegRisk() methods, or from the market object returned by the API.
4

Check Your Orders

// View all open orders
const openOrders = await client.getOpenOrders();
console.log(`You have ${openOrders.length} open orders`);

// View your trade history
const trades = await client.getTrades();
console.log(`You've made ${trades.length} trades`);

// Cancel an order
await client.cancelOrder(response.orderID);

Troubleshooting

Wrong private key, signature type, or funder address for the derived API credentials.
  • 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
Your funder address doesn’t have enough tokens:
  • BUY orders: need pUSD in your funder address
  • SELL orders: need outcome tokens in your funder address
  • Ensure you have more pUSD than what’s committed in open orders
You need to approve the Exchange contract to spend your tokens. Deposit wallet approvals must be executed from the deposit wallet through a relayer WALLET batch. Existing Safe and Proxy users should use their current relayer approval flow.
Your funder address is the wallet where your funds are held:
  • EOA (type 0): Your wallet address directly
  • Deposit wallet (type 3): The deposit wallet deployed for the owner or session signer
  • Proxy/Safe wallet (type 1 or 2): Existing Polymarket.com wallet address
New API users should create a deposit wallet. Existing Proxy and Safe users can continue using their current wallet address.
You’re trying to place a trade from a restricted region. See Geographic Restrictions for details.

Next Steps

Create Orders

Order types, tick sizes, and error handling

Order Attribution

Attribute orders to your builder account for volume credit