wikis / Polymarket / wiki / entities / clob-client.md view as markdown report a mistake
clob-client
Overview
clob-client is the TypeScript client for the Polymarket CLOB --
Polymarket/clob-client, published on npm as @polymarket/clob-client. It
signs and posts orders and reads market data against
https://clob.polymarket.com.
[!WARNING] This repository has been archived and is no longer maintained. The client is no longer functional and should not be used for new or existing integrations. Please migrate to our new unified SDK: https://github.com/Polymarket/ts-sdk
The newer generation client is @polymarket/clob-client-v2 (see
authentication); the Python counterpart is
py clob client.
Characteristics
- Language: TypeScript / Node.
- Signer via
ethersWallet(private key) or a viemWalletClient. funderis your Polymarket Profile Address (where you send USDC).signatureType:0Browser Wallet (MetaMask, Coinbase Wallet, etc.),1Magic/Email Login.- Order placement needs the market's
tickSizeandnegRiskflag, obtained from the Gamma Markets API get-markets endpoint. - By default API errors return as
{ error, status }objects; passthrowOnError: trueas the last constructor argument to throwApiError.
How to Use
Install (from the README usage comments):
// npm install @polymarket/clob-client
// npm install ethers
Client initialization and placing a GTC order:
import { ApiKeyCreds, ClobClient, OrderType, Side, } from "@polymarket/clob-client";
import { Wallet } from "@ethersproject/wallet";
const host = 'https://clob.polymarket.com';
const funder = ''; // This is your Polymarket Profile Address, where you send UDSC to.
const signer = new Wallet(""); // This is your Private Key. If using email login export from https://reveal.magic.link/polymarket otherwise export from your Web3 Application
// In general don't create a new API key, always derive or createOrDerive
const creds = new ClobClient(host, 137, signer).createOrDeriveApiKey();
//0: Browser Wallet(Metamask, Coinbase Wallet, etc)
//1: Magic/Email Login
const signatureType = 1;
(async () => {
const clobClient = new ClobClient(host, 137, signer, await creds, signatureType, funder);
const resp2 = await clobClient.createAndPostOrder(
{
tokenID: "", //Use https://docs.polymarket.com/developers/gamma-markets-api/get-markets to grab a sample token
price: 0.01,
side: Side.BUY,
size: 5,
},
{ tickSize: "0.001",negRisk: false }, //You'll need to adjust these based on the market. Get the tickSize and negRisk T/F from the get-markets above
//{ tickSize: "0.001",negRisk: true },
OrderType.GTC,
);
console.log(resp2)
})();
Using a viem WalletClient instead of ethers:
import { ClobClient } from "@polymarket/clob-client";
import { createWalletClient, http } from "viem";
import { polygon } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
const host = "https://clob.polymarket.com";
const account = privateKeyToAccount("0x...");
const walletClient = createWalletClient({
account,
chain: polygon,
transport: http(),
});
const clobClient = new ClobClient(host, 137, walletClient);
Related Entities
- py clob client -- the Python CLOB client.
- authentication -- L1/L2 auth and API credentials.
- order types and execution -- CLOB order types vs RFQ.
