Skip to main content

Documentation Index

Fetch the complete documentation index at: https://polynode.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

The SDK wraps the PolyNode WebSocket API with typed subscriptions, automatic reconnection, and transparent zlib compression. One connection handles multiple subscriptions simultaneously.

Subscribe

import { PolyNodeWS } from 'polynode-sdk';

const ws = new PolyNodeWS('pn_live_...', 'wss://ws.polynode.dev/ws');

const sub = await ws.subscribe('settlements')
  .minSize(100)
  .status('pending')
  .snapshotCount(20)
  .send();

Subscription Types

TypeWhat you get
settlementsPending detection + confirmed settlements
tradesAll trade activity (settlements + confirmed trades)
pricesPrice-moving events for specific markets
blocksNew Polygon blocks
walletsAll activity for specified wallets
marketsAll activity for specified markets
large_tradesTrades >= $1,000
oracleUMA resolution events (proposals, disputes)
chainlinkReal-time Chainlink price feeds (~1/sec)

Filters

All filters can be chained on any subscription:
ws.subscribe('settlements')
  .wallets(['0xabc...'])          // by wallet address
  .tokens(['21742633...'])        // by token ID
  .slugs(['bitcoin-100k'])        // by market slug
  .conditionIds(['0xabc...'])     // by condition ID
  .side('BUY')                    // BUY or SELL
  .status('pending')             // pending, confirmed, or all
  .minSize(100)                   // min USD size
  .maxSize(10000)                 // max USD size
  .eventTypes(['settlement'])     // specific event types
  .snapshotCount(50)              // initial history (tier-limited)
  .feeds(['BTC/USD'])             // Chainlink feed names
  .send();

Consuming Events

// Typed event callbacks
sub.on('settlement', (event) => {
  console.log(`${event.taker_side} $${event.taker_size} on ${event.market_title}`);
});

sub.on('status_update', (event) => {
  console.log(`Confirmed in ${event.latency_ms}ms`);
});

// Catch-all
sub.on('*', (event) => {
  console.log(event.event_type, event);
});

// Or use async iterator
for await (const event of sub) {
  console.log(event.event_type);
}

Multiple Subscriptions

Subscriptions stack on the same connection. Events are deduplicated.
const whales = await ws.subscribe('large_trades')
  .minSize(5000).send();

const myWallet = await ws.subscribe('wallets')
  .wallets(['0xabc...']).send();

// Both active simultaneously

Auto-Reconnect

Enabled by default. On disconnect, the SDK reconnects with exponential backoff and replays all active subscriptions.
ws.onConnect(() => console.log('connected'));
ws.onDisconnect((reason) => console.log('disconnected:', reason));
ws.onReconnect((attempt) => console.log('reconnected, attempt', attempt));
ws.onError((err) => console.error(err));

Compression

Zlib compression is enabled by default for all connections, saving ~50% bandwidth. Binary frames are transparently decompressed. No configuration needed.

Cleanup

sub.unsubscribe();       // remove one subscription
ws.unsubscribeAll();     // remove all
ws.disconnect();         // close connection