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-gamma

v0.4.0

Published

TypeScript client for Polymarket Gamma API - access prediction markets, events, and related data

Downloads

169

Readme

polymarket-gamma

NPM Version NPM Downloads License TypeScript GitHub Stars GitHub Issues Bundle Size Tests

A clean, type-safe TypeScript client for the Polymarket Gamma API. Access prediction markets, events, tags, and related data with full TypeScript support.

Features

  • 🎯 Type-Safe - Full TypeScript support with comprehensive type definitions
  • 🚀 Simple API - Intuitive methods for accessing all Gamma API endpoints
  • 📦 Zero Config - Works out of the box with sensible defaults
  • 🔄 Modern - Built with modern JavaScript features (ESM, async/await)
  • 🧪 Well-Tested - Comprehensive test suite with 37 passing tests
  • 🔧 Customizable - Custom fetch, headers, retries, caching, and more
  • 🎨 Clean Code - Linted with BiomeJS for consistent code quality
  • Auto-Parsing - Automatically parses JSON string fields (outcomes, prices, token IDs)

Installation

npm install polymarket-gamma
yarn add polymarket-gamma
pnpm add polymarket-gamma
bun add polymarket-gamma

Quick Start

import { PolymarketGammaClient } from 'polymarket-gamma';

// Create a new client
const client = new PolymarketGammaClient();

// Get a market by slug
const market = await client.getMarket('will-btc-hit-100k-by-2024');
console.log(market.question);
console.log(market.outcomes);       // Automatically parsed: ['Yes', 'No']
console.log(market.outcome_prices); // Automatically parsed: ['0.5', '0.5']

// Get active markets
const markets = await client.getMarkets({ active: true, limit: 10 });

// Search for events
const results = await client.search({ query: 'election', limit: 5 });

API Reference

Client Configuration

const client = new PolymarketGammaClient({
  baseUrl: 'https://gamma-api.polymarket.com', // optional, default shown
  timeout: 30000, // optional, in milliseconds
  headers: {
    // optional, custom headers for all requests
    'X-API-Key': 'your-key',
    'User-Agent': 'MyApp/1.0',
  },
  fetch: customFetchFn, // optional, custom fetch implementation
});

Customization Options:

  • baseUrl - Override the API base URL
  • timeout - Request timeout in milliseconds (default: 30000)
  • headers - Custom headers added to all requests
  • fetch - Custom fetch implementation for logging, retries, caching, etc.

Custom Fetch Example:

// Add request logging
const loggingFetch = async (url, init) => {
  console.log(`Request: ${init?.method || 'GET'} ${url}`);
  return fetch(url, init);
};

const client = new PolymarketGammaClient({
  fetch: loggingFetch as typeof fetch,
});

See examples/custom-client.ts for more advanced examples including retries, caching, and rate limiting.

Markets

// Get a specific market by ID or slug
const market = await client.getMarket('market-id-or-slug');

// Get markets with filters
const markets = await client.getMarkets({
  active: true,
  closed: false,
  archived: false,
  featured: true,
  tags: ['politics', 'us-elections'],
  category: 'politics',
  limit: 20,
  offset: 0,
  order_by: 'volume', // Common: 'liquidity', 'volume', 'created_at', 'end_date' (accepts any string)
  ascending: false,
});

// Get tags for a market
const tags = await client.getMarketTags('market-id');

Events

// Get a specific event by ID or slug
const event = await client.getEvent('event-id-or-slug');

// Get events with filters
const events = await client.getEvents({
  active: true,
  closed: false,
  tags: ['sports'],
  limit: 10,
  offset: 0,
});

// Get events with pagination metadata
const paginatedEvents = await client.getEventsPaginated({
  active: true,
  archived: false,
  closed: false,
  order: 'startDate',
  ascending: false,
  limit: 10,
  offset: 0,
});
console.log(paginatedEvents.data); // Array of events
console.log(paginatedEvents.pagination.hasMore); // true/false
console.log(paginatedEvents.pagination.totalResults); // Total count

// Get tags for an event
const tags = await client.getEventTags('event-id');

Search

// Search across events, tags, and profiles
const results = await client.search({
  query: 'bitcoin',
  limit: 10,
  offset: 0,
});

console.log(results.events);
console.log(results.tags);
console.log(results.profiles);

Tags

// Get all tags
const tags = await client.getTags({ limit: 50, offset: 0 });

// Get a specific tag
const tag = await client.getTag('tag-id-or-slug');

// Get related tags
const relatedTags = await client.getRelatedTags('tag-id-or-slug');

Sports

// Get all teams
const teams = await client.getTeams({ limit: 50 });

// Get all sports
const sports = await client.getSports();

Series

// Get all series
const series = await client.getSeries({ limit: 10 });

// Get a specific series
const seriesDetail = await client.getSeriesById('series-id');

Comments

// Get all comments
const comments = await client.getComments({ limit: 20, offset: 0 });

// Get a specific comment
const comment = await client.getComment('comment-id');

// Get comments by user
const userComments = await client.getCommentsByUser('0x123...', { limit: 10 });

Grok AI Features

// Get AI-powered event summary
const summary = await client.grokEventSummary('event-slug');

// Get AI-powered market explanation
const explanation = await client.grokElectionMarketExplanation('market-slug');

Examples

Check out the examples directory for more detailed usage examples:

Type Definitions

The package includes comprehensive TypeScript type definitions for all API responses:

  • GammaMarket - Market data
  • Event - Event information
  • Tag - Tag data
  • Series - Series/tournament data
  • Team - Sports team data
  • Sport - Sport data
  • Comment - Comment data
  • Profile - User profile data
  • And more...

Development

# Install dependencies
npm install

# Run tests
npm run test

# Run tests in watch mode
npm run test:watch

# Run tests with UI
npm run test:ui

# Run tests with coverage
npm run test:coverage

# Run linting
npm run lint

# Fix linting issues
npm run lint:fix

# Format code
npm run format

# Type check
npm run check

# Build
npm run build

Testing

This package includes comprehensive unit tests using Vitest. Tests cover:

  • ✅ All API methods (markets, events, tags, series, sports, comments)
  • ✅ Request parameter handling (filters, pagination, arrays)
  • ✅ Error handling (HTTP errors, timeouts, network failures)
  • ✅ Grok AI features
  • ✅ URL construction and query parameters
  • ✅ Automatic parsing of JSON string fields

Test Coverage: 37 tests, all passing

Run tests with:

npm run test              # Run tests once
npm run test:watch        # Run tests in watch mode
npm run test:coverage     # Run tests with coverage report

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

MIT License - see LICENSE for details.

Related Projects

Disclaimer

This is an unofficial client library for the Polymarket Gamma API. It is not affiliated with or endorsed by Polymarket.

Links