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-trading-sdk

v0.2.1

Published

SDK for building Polymarket trading bots

Readme

polymarket-trading-sdk

A comprehensive SDK for building Polymarket trading bots.

Installation

npm install polymarket-trading-sdk
# or
pnpm add polymarket-trading-sdk

Quick Start

import {
  MarketDataClient,
  OrderManager,
  registerStrategy,
  type Strategy,
  type Signal,
} from "polymarket-trading-sdk";

// Fetch market data (no auth required)
const marketData = new MarketDataClient();
const data = await marketData.getMarketData("your-token-id");
console.log(`Midpoint: ${data.midpoint}, Spread: ${data.spread}`);

// Create an order manager
const orderManager = new OrderManager({
  mode: "paper", // or "live"
  executorUrl: "https://...",
  executorApiKey: "exk_...",
  executorWalletId: "my-wallet",
});

// Place an order
const result = await orderManager.placeOrder({
  slug: "my-market",
  label: "YES",
  tokenId: "123...",
  side: "buy",
  price: 0.5,
  size: 10,
});

Features

Market Data Client

Read-only access to Polymarket market data (no authentication required):

const client = new MarketDataClient();

// Price data
const midpoint = await client.getMidpoint(tokenId);
const price = await client.getPrice(tokenId, "buy");
const spread = await client.getSpread(tokenId);

// Order book
const book = await client.getOrderBook(tokenId);

// Search markets
const markets = await client.searchMarkets("bitcoin");

Order Manager

Unified interface for placing orders in paper or live mode:

const manager = new OrderManager({
  mode: "live",
  executorUrl: process.env.EXECUTOR_URL,
  executorApiKey: process.env.EXECUTOR_API_KEY,
  executorWalletId: process.env.EXECUTOR_WALLET_ID,
});

// Place order
await manager.placeOrder({ ... });

// Cancel order
await manager.cancelOrder("order-id");

// Get balance
const balance = await manager.getBalance();

Strategy System

Create plug-and-play trading strategies:

import {
  registerStrategy,
  getStrategy,
  type Strategy,
  type StrategyContext,
  type Signal,
} from "polymarket-trading-sdk";

const myStrategy: Strategy = {
  name: "my-strategy",

  async scan(ctx: StrategyContext): Promise<Signal[]> {
    // Find trading opportunities
    return [];
  },

  calculatePrice(signal, data, config): number | null {
    // Calculate limit price
    return data.bid ? data.bid + 0.01 : null;
  },
};

registerStrategy(myStrategy);

Pricing Utilities

Pure functions for price calculations:

import {
  roundToTick,
  calculateBid,
  isWideSpread,
} from "polymarket-trading-sdk";

// Round to tick size
roundToTick(0.567, 0.01); // 0.57

// Calculate smart bid
const bid = calculateBid({
  midpoint: 0.50,
  offset: 0.01,
  floor: 0.45,
  min: 0.40,
  max: 0.55,
});

// Check spread
isWideSpread(0.45, 0.55, 0.08); // true

Signing Utilities

HMAC and EIP-712 signing for Polymarket API:

import {
  createLevel2Headers,
  signOrder,
  getAddress,
} from "polymarket-trading-sdk";

// Get wallet address
const address = getAddress("0x...");

// Create authenticated headers
const headers = await createLevel2Headers({
  address,
  apiKey: "...",
  apiSecret: "...",
  apiPassphrase: "...",
  method: "POST",
  path: "/order",
  body: JSON.stringify({ ... }),
});

Auth Middleware

API key authentication for workers:

import { checkAuth, unauthorizedResponse } from "polymarket-trading-sdk";

// In your worker
const auth = checkAuth(request, env);
if (!auth.authorized) {
  return unauthorizedResponse(auth.error || "Unauthorized");
}

API Reference

Clients

  • MarketDataClient - Read-only market data access
  • ExecutorClient - Order executor Lambda client
  • TradingClient - Direct CLOB API client (requires auth)

Order Management

  • OrderManager - Unified order interface (paper/live modes)
  • createOrderManager(config) - Create from config
  • createOrderManagerFromEnv(env) - Create from env vars

Strategy

  • Strategy<TEnv> - Strategy interface
  • StrategyContext<TEnv> - Context passed to strategies
  • registerStrategy(strategy) - Register a strategy
  • getStrategy(name) - Get registered strategy
  • listStrategies() - List all strategies

Pricing

  • roundToTick(price, tickSize) - Round to tick
  • floorToTick(price, tickSize) - Floor to tick
  • ceilToTick(price, tickSize) - Ceil to tick
  • calculateBid(config) - Calculate smart bid
  • calculateAsk(config) - Calculate smart ask
  • calculateSpread(bid, ask) - Calculate spread
  • isWideSpread(bid, ask, threshold) - Check spread

Signing

  • buildHmacSignature(...) - HMAC-SHA256 signature
  • createLevel2Headers(...) - Level 2 auth headers
  • signOrder(...) - EIP-712 order signature
  • getAddress(privateKey) - Get wallet address

Auth

  • checkAuth(request, env) - Validate API key
  • unauthorizedResponse(error) - Create 401 response

License

MIT