Huakun

Polymarket Kit

A fully typed SDK and proxy server built with Elysia for Polymarket APIs. Available in TypeScript and Go.

GitHub: https://github.com/HuakunShen/polymarket-kit
JSR: https://jsr.io/@hk/polymarket

Features

  • Fully Typed SDK: Complete TypeScript support with no any types
  • WebSocket Client: Real-time market data streaming with auto-reconnection
  • Proxy Server: REST API with OpenAPI documentation
  • MCP Server: Model Context Protocol server for AI interactions
  • Type Safety: End-to-end type validation and transformation
  • Multiple Runtimes: Supports Bun, Node.js, Deno, and Cloudflare Workers
  • Multi-Language: TypeScript and Go clients with identical APIs

Architecture

Dual-purpose package:

  1. Standalone SDK Clients

    • PolymarketSDK: For CLOB operations (requires credentials)
    • GammaSDK: For Gamma API operations (no credentials required)
    • PolymarketWebSocketClient: Real-time market data streaming
  2. Proxy Server (Optional)

    • Gamma API (/gamma/*) - Market and event data
    • CLOB API (/clob/*) - Trading and price history

Installation

# Deno
deno add @hk/polymarket

# Bun
bunx jsr add @hk/polymarket

# npm
npx jsr add @hk/polymarket

Usage

GammaSDK (No credentials)

import { GammaSDK } from "@hk/polymarket";

const gamma = new GammaSDK();

// Get active markets
const markets = await gamma.getActiveMarkets();

// Get market by slug
const market = await gamma.getMarketBySlug("bitcoin-above-100k");

PolymarketSDK (With credentials)

import { PolymarketSDK } from "@hk/polymarket";

const sdk = new PolymarketSDK({
  privateKey: process.env.POLYMARKET_KEY!,
  funderAddress: process.env.POLYMARKET_FUNDER!,
});

const priceHistory = await sdk.getPriceHistory({
  market: "0x123...",
  interval: "1h",
});

WebSocket Real-Time Data

import { PolymarketWebSocketClient } from "@hk/polymarket";

const ws = new PolymarketWebSocketClient(clobClient, {
  assetIds: [
    "60487116984468020978247225474488676749601001829886755968952521846780452448915",
  ],
  autoReconnect: true,
});

ws.on({
  onBook: (msg) => console.log(`Bids: ${msg.bids.length}`),
  onPriceChange: (msg) => console.log(`Changes: ${msg.price_changes.length}`),
  onLastTradePrice: (msg) => console.log(`Trade: ${msg.price}`),
});

await ws.connect();

MCP Server

Natural language interface to Polymarket data for AI models:

{
  "mcpServers": {
    "polymarket": {
      "command": "bun",
      "args": ["run", "path/to/polymarket-kit/src/mcp/polymarket.ts"]
    }
  }
}

Example queries:

  • "Show me the most active prediction markets right now"
  • "Find markets about the 2024 US election"
  • "What are the trending markets in the last 24 hours?"

A fully typed Polymarket SDK with WebSocket support, proxy server, and MCP integration.

On this page