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-data/client

v0.1.1

Published

Node.js SDK for polymarket-data-collector REST API

Readme

@polymarket-data/client

Node.js client for the polymarket-data-collector REST API. Provides typed access to real-time and historical Polymarket market data.

Install

npm install @polymarket-data/client

Requires Node.js >= 18.

Quick Start

import { DataCollectorClient, MarketStream } from '@polymarket-data/client';

const client = new DataCollectorClient({
  baseUrl: 'http://localhost:8000',
  apiKey: 'your-api-key',  // optional
  timeout: 10000,          // optional, default 10s
  retries: 2,              // optional, default 2
  retryDelay: 1000,        // optional, default 1s
});

// Get market snapshot
const snapshot = await client.market.getSnapshot(tokenId);

// Get order book
const book = await client.market.getBook(tokenId);

// Get price
const price = await client.market.getPrice(tokenId);

API Reference

DataCollectorClient

Main client class. All REST requests go to {baseUrl}/api/v1.

Constructor Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | baseUrl | string | — | Required. Base URL of the data collector service | | apiKey | string | — | API key (sent as X-API-Key header) | | timeout | number | 10000 | Request timeout in ms | | retries | number | 2 | Retry count for 502/503/504 and network errors | | retryDelay | number | 1000 | Base retry delay in ms (exponential backoff) |


client.market

Market data for a single token.

| Method | Return Type | Description | |--------|-------------|-------------| | getSnapshot(tokenId) | MarketSnapshot \| null | Full market snapshot (price, spread, liquidity, holders, rewards, rank) | | getBook(tokenId) | OrderBookResponse \| null | Order book with bids, asks, and depth | | getPrice(tokenId) | PriceResponse | Current price, spread, best bid/ask | | getMetadata(tokenId) | MetadataResponse \| null | Market metadata from Gamma API | | getOpenInterest(tokenId) | OpenInterestResponse \| null | Open interest data | | getHolders(tokenId) | HoldersResponse \| null | Top holders and concentration metrics | | getRewards(tokenId) | RewardsResponse \| null | Liquidity rewards info | | getRank(tokenId) | RankResponse \| null | Probability rank among all markets | | getStatus(tokenId) | MarketStatus \| null | Market status (open/closed/settled) | | getChanges(tokenId, params?) | ChangesResponse \| null | Price changes across time intervals | | getTrend(tokenId, params?) | TrendResponse \| null | Consecutive price trend | | getOhlc(tokenId, params?) | OhlcResponse | OHLC candlestick data | | getTrades(tokenId, params?) | TradesResponse | Recent trades | | getHistory(tokenId, params?) | HistoryResponse | Historical price points |

Methods returning T | null return null when the market is not found (404).

// Price changes with custom intervals
const changes = await client.market.getChanges(tokenId, {
  intervals: ['5m', '1h', '24h'],
  withWindowStats: true,
});

// OHLC candles
const ohlc = await client.market.getOhlc(tokenId, {
  interval: '1h',   // '1m' | '5m' | '15m' | '1h' | '4h' | '1d'
  limit: 100,
  source: 'midpoint', // 'midpoint' | 'trade'
});

client.batch

Batch queries for multiple tokens (max 200 per request).

| Method | Return Type | Description | |--------|-------------|-------------| | snapshots(tokenIds) | BatchSnapshotResponse | Snapshots for multiple tokens | | changes(tokenIds) | BatchChangesResponse | Price changes for multiple tokens |

const batch = await client.batch.snapshots([tokenId1, tokenId2, tokenId3]);
// batch.results: Record<tokenId, { collected_at, data }>
// batch.missing: string[]

client.subscriptions

Manage data collection subscriptions.

| Method | Return Type | Description | |--------|-------------|-------------| | create(params) | SubscriptionCreateResponse | Create a new subscription | | list(params?) | SubscriptionListResponse | List subscriptions | | get(tokenId) | SubscriptionResponse \| null | Get subscription by token ID | | update(tokenId, params) | SubscriptionResponse | Update subscription | | delete(tokenId) | SubscriptionDeleteResponse | Delete subscription | | batchCreate(items) | BatchSubscriptionResult | Create multiple subscriptions |


client.quality

Data quality metrics.

const quality = await client.quality.get(tokenId, { period: 'last_24h' });
// quality.completeness.completeness_rate → 0.98

Periods: last_10m, last_30m, last_1h, last_6h, last_24h, last_7d, last_30d, all


client.export

Export historical data in JSON, CSV, or XLSX format.

// JSON
const ticks = await client.export.ticks({
  tokenId,
  start: '2026-01-01',
  end: '2026-01-31',
  format: 'json',
});

// CSV (returns Buffer)
const csv = await client.export.ticks({
  tokenId,
  start: '2026-01-01',
  end: '2026-01-31',
  format: 'csv',
});

client.sql

Execute read-only SQL queries against the data store.

const result = await client.sql.query('SELECT * FROM ticks WHERE token_id = ? LIMIT 10');
// or with params
const result = await client.sql.query({ query: 'SELECT ...', limit: 100 });

client.users

User portfolio data.

| Method | Return Type | Description | |--------|-------------|-------------| | list(params?) | UserListResponse | List tracked users | | discovered(params?) | UserDiscoveredResponse | Recently discovered users | | getProfile(userId) | UserProfileResponse \| null | User profile with PnL summary | | getPositions(userId, params?) | UserPositionsResponse \| null | User positions |


client.status

System health.

const status = await client.status.get();
const healthy = await client.status.isHealthy(); // boolean

MarketStream

Server-Sent Events (SSE) stream for real-time market updates.

import { MarketStream } from '@polymarket-data/client';

const stream = new MarketStream({ baseUrl: 'http://localhost:8000' });

for await (const event of stream.subscribe(tokenId)) {
  console.log(event.snapshot);  // MarketSnapshot | null
  console.log(event.book);     // OrderBookResponse | null
}

// Stop the stream
stream.close();

Error Handling

All errors extend DataCollectorError:

| Error | Status | Description | |-------|--------|-------------| | NotFoundError | 404 | Resource not found | | AuthenticationError | 401 | Invalid or missing API key | | ForbiddenError | 403 | Insufficient permissions | | RateLimitError | 429 | Rate limit exceeded (includes retryAfter) | | TimeoutError | — | Request timed out | | ConnectionError | — | Network error |

import { RateLimitError, NotFoundError } from '@polymarket-data/client';

try {
  await client.market.getPrice(tokenId);
} catch (e) {
  if (e instanceof RateLimitError) {
    console.log(`Retry after ${e.retryAfter}s`);
  }
}

License

MIT