npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polymarket/clob-client-v2

v1.3.1

Published

TypeScript client for Polymarket's CLOB

Readme

[!WARNING] This package is deprecated. Please migrate to the unified Polymarket SDK. Follow the migration guide to get started.

Polymarket CLOB Client V2

TypeScript client for the Polymarket CLOB (v2)

Usage

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

import { ApiKeyCreds, Chain, ClobClient, OrderType, Side } from "@polymarket/clob-client-v2";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";

const host = "<polymarket-clob-host>";
const chainId = Chain.POLYGON; // or Chain.AMOY for testnet

const account = privateKeyToAccount("0x..."); // your private key
const walletClient = createWalletClient({ account, transport: http() });

// Step 1: obtain API credentials using your wallet (L1 auth)
const clobClient = new ClobClient({ host, chain: chainId, signer: walletClient });
const creds = await clobClient.createOrDeriveApiKey();

// Step 2: initialize a fully-authenticated client (L1 + L2)
const client = new ClobClient({ host, chain: chainId, signer: walletClient, creds });

// Place a resting limit buy (GTC)
const resp = await client.createAndPostOrder(
    {
        tokenID: "", // token ID of the market outcome — get from https://docs.polymarket.com
        price: 0.4,
        side: Side.BUY,
        size: 100,
    },
    { tickSize: "0.01" },
    OrderType.GTC,
);
console.log(resp);

For a position-backed outcome, provide positionID instead. The client uses the identifier field to select Exchange V3 signing automatically:

const resp = await client.createAndPostOrder(
    {
        positionID: "", // position ID of the market outcome
        price: 0.4,
        side: Side.BUY,
        size: 100,
    },
    { tickSize: "0.01" },
    OrderType.GTC,
);

See examples for more information.

Market Orders

// Market buy — amount is in USDC
// OrderType.FOK: entire order must fill immediately or it is cancelled
// OrderType.FAK: fills as much as possible, remainder is cancelled
const resp = await client.createAndPostMarketOrder(
    {
        tokenID: "",
        amount: 100, // USDC
        side: Side.BUY,
        orderType: OrderType.FOK,
    },
    { tickSize: "0.01" },
    OrderType.FOK,
);
console.log(resp);

Warm up order cache metadata

The first order on a new client fetches the order version and the market's tick size, neg-risk flag, and fee details before it can be signed. Both are public GET requests and need no signer or credentials. To take them off the first trade, run them ahead of time on the same client instance that will submit orders:

await Promise.all([
    client.getVersion(), // adopted as the order version for this client
    client.getClobMarketInfo(conditionID), // caches tick size, neg risk, and fees for both outcomes
]);

Each call asks the server and refreshes the caches, so repeating it costs one request. If the version request fails, getVersion adopts the default version 2 and the first order corrects it through the mismatch recovery built into order posting. With throwOnError both calls throw ApiError instead, so treat a rejected warm-up as a background failure. A new client instance starts with empty caches. Order creation and getVersion reuse a version or market request that is still in flight instead of starting another one. Orders never require these calls. An order placed before getClobMarketInfo resolves still performs its own token-to-market lookup. Books, balances, allowances, credentials, and builder fee rates are not cached by these calls.

Authentication

The client has two authentication levels:

L1 — wallet signature (EIP-712). Required to create or derive API keys.

const client = new ClobClient({ host, chain: chainId, signer: walletClient });
const creds = await client.createOrDeriveApiKey();

L2 — HMAC with API credentials. Required for order placement, cancellation, and account data.

const creds: ApiKeyCreds = {
    key: process.env.CLOB_API_KEY,
    secret: process.env.CLOB_SECRET,
    passphrase: process.env.CLOB_PASS_PHRASE,
};
const client = new ClobClient({ host, chain: chainId, signer: walletClient, creds });

Error Handling

By default, API errors are returned as { error: "...", status: ... } objects. Check a result with isApiErrorResponse before using it:

import { isApiErrorResponse, Side } from "@polymarket/clob-client-v2";

const books = await client.getOrderBooks([{ token_id: tokenID, side: Side.BUY }]);
if (isApiErrorResponse(books)) {
    console.log(books.status, books.error); // 500 "Internal server error"
} else {
    books.forEach(book => console.log(book.market));
}

To have the client throw instead, pass throwOnError: true:

import { ApiError, ClobClient } from "@polymarket/clob-client-v2";

const client = new ClobClient({ host, chain: chainId, signer: walletClient, creds, throwOnError: true });

try {
    const book = await client.getOrderBook(tokenID);
} catch (e) {
    if (e instanceof ApiError) {
        console.log(e.message); // "No orderbook exists for the requested token id"
        console.log(e.status);  // 404
        console.log(e.data);    // full error response object
    }
}

Methods that collect every page of a list (getTrades, getOpenOrders, getPreMigrationOrders, getEarningsForUserForDay, getUserEarningsAndMarketsConfig, getCurrentRewards, getRawRewardsForMarket) throw ApiError when any page fails, with or without throwOnError, because a partial list cannot be told apart from a complete one. The market metadata the client caches (getTickSize, getNegRisk, getFeeRateBps, builder fee rates, getClobMarketInfo) is also never cached from a failed response: those lookups throw ApiError instead, and so does market order pricing when the order book request fails.