
Security News
TeamPCP Is Systematically Targeting Security Tools Across the OSS Ecosystem
TeamPCP is targeting security tools across the OSS ecosystem, turning scanners and CI pipelines into infostealers to access enterprise secrets.
polymarket-websocket-client
Advanced tools
Zero-dependency TypeScript WebSocket client for Polymarket CLOB and RTDS APIs with automatic reconnection and full type safety
Zero-dependency TypeScript WebSocket client for Polymarket CLOB and RTDS APIs. Supports all WebSocket channels with automatic reconnection, heartbeat, and comprehensive error handling.
npm install polymarket-websocket-client
# or
pnpm add polymarket-websocket-client
# or
yarn add polymarket-websocket-client
import { ClobMarketClient } from 'polymarket-websocket-client';
const client = new ClobMarketClient();
// Subscribe to orderbook updates
client.onBook((event) => {
console.log('Orderbook:', event.asset_id, event.bids, event.asks);
});
client.onPriceChange((event) => {
console.log('Price change:', event.price_changes);
});
client.onLastTradePrice((event) => {
console.log('Trade:', event.asset_id, event.price, event.size);
});
// Connect and subscribe to assets
await client.connect();
client.subscribe(['71321045679252212594626385532706912750332728571942532289631379312455583992563']);
import { ClobUserClient } from 'polymarket-websocket-client';
const client = new ClobUserClient({
apiKey: 'your-api-key',
secret: 'your-secret',
passphrase: 'your-passphrase',
});
// Listen for your trades and orders
client.onTrade((event) => {
console.log('Trade:', event.id, event.status, event.price, event.size);
});
client.onOrder((event) => {
console.log('Order:', event.id, event.type, event.price);
});
// Connect and subscribe to markets
await client.connect();
client.subscribe(['0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af']);
import { RtdsClient } from 'polymarket-websocket-client';
const client = new RtdsClient();
// Listen for crypto price updates
client.onCryptoPrice((message) => {
console.log('Price:', message.payload.symbol, message.payload.value);
});
// Listen for comments
client.onComment((message) => {
console.log('Comment:', message.payload.body);
});
await client.connect();
// Subscribe to crypto prices (Binance)
client.subscribeCryptoPrices(['btcusdt', 'ethusdt']);
// Subscribe to comments
client.subscribeComments('comment_created');
import { ClobClient } from 'polymarket-websocket-client';
const client = new ClobClient({
auth: {
apiKey: 'your-api-key',
secret: 'your-secret',
passphrase: 'your-passphrase',
},
});
// Access both channels
client.market.onBook((event) => console.log('Book:', event));
client.user.onTrade((event) => console.log('Trade:', event));
// Connect to both channels
await client.connectAll();
// Subscribe
client.market.subscribe(['asset-id']);
client.user.subscribe(['market-id']);
// Disconnect all
client.disconnect();
All clients accept configuration options:
interface ClientOptions {
url?: string; // Custom WebSocket URL
autoReconnect?: boolean; // Enable auto-reconnection (default: true)
maxReconnectAttempts?: number; // Max reconnection attempts (default: Infinity)
reconnectDelay?: number; // Base delay between reconnects in ms (default: 1000)
maxReconnectDelay?: number; // Max reconnection delay in ms (default: 30000)
heartbeatInterval?: number; // Heartbeat interval in ms (default: 30000 for CLOB, 5000 for RTDS)
connectionTimeout?: number; // Connection timeout in ms (default: 10000)
}
All clients emit connection lifecycle events:
client.on('connected', () => {
console.log('Connected!');
});
client.on('disconnected', ({ code, reason }) => {
console.log('Disconnected:', code, reason);
});
client.on('reconnecting', ({ attempt, maxAttempts }) => {
console.log(`Reconnecting... attempt ${attempt}/${maxAttempts}`);
});
client.on('error', (error) => {
console.error('Error:', error);
});
client.on('stateChange', ({ state, previousState }) => {
console.log(`State changed: ${previousState} -> ${state}`);
});
| Method | Description |
|---|---|
connect() | Connect to the WebSocket server |
disconnect() | Disconnect from the server |
subscribe(assetIds) | Subscribe to asset IDs (token IDs) |
unsubscribe(assetIds) | Unsubscribe from asset IDs |
onBook(callback) | Listen for orderbook snapshots |
onPriceChange(callback) | Listen for price changes |
onTickSizeChange(callback) | Listen for tick size changes |
onLastTradePrice(callback) | Listen for last trade prices |
onMarketMessage(callback) | Listen for all market events |
| Method | Description |
|---|---|
connect() | Connect to the WebSocket server |
disconnect() | Disconnect from the server |
subscribe(marketIds) | Subscribe to market IDs (condition IDs) |
unsubscribe(marketIds) | Unsubscribe from market IDs |
onTrade(callback) | Listen for trade events |
onOrder(callback) | Listen for order events |
onUserMessage(callback) | Listen for all user events |
| Method | Description |
|---|---|
connect() | Connect to the WebSocket server |
disconnect() | Disconnect from the server |
subscribeCryptoPrices(symbols?) | Subscribe to Binance crypto prices |
subscribeCryptoPricesChainlink(symbol?) | Subscribe to Chainlink prices |
subscribeComments(type?, gammaAuth?) | Subscribe to comment events |
subscribeActivity(type, clobAuth?, gammaAuth?) | Subscribe to activity events |
onCryptoPrice(callback) | Listen for crypto price updates |
onComment(callback) | Listen for comment events |
onActivity(callback) | Listen for activity events |
onRtdsMessage(callback) | Listen for all RTDS messages |
book: Full orderbook snapshotprice_change: Order placement/cancellation updatestick_size_change: Tick size changes at price extremeslast_trade_price: Trade execution eventstrade: Trade lifecycle (MATCHED → MINED → CONFIRMED/FAILED)order: Order lifecycle (PLACEMENT → UPDATE → CANCELLATION)crypto_prices: Binance price updatescrypto_prices_chainlink: Chainlink price updatescomments: Comment creation/removal and reactionsMIT
FAQs
Zero-dependency TypeScript WebSocket client for Polymarket CLOB and RTDS APIs with automatic reconnection and full type safety
We found that polymarket-websocket-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
TeamPCP is targeting security tools across the OSS ecosystem, turning scanners and CI pipelines into infostealers to access enterprise secrets.

Security News
TypeScript 6.0 introduces new standard APIs, modern default settings, and deprecations as it prepares projects for the upcoming TypeScript 7.0 release.

Security News
/Research
Newly published Trivy Docker images (0.69.4, 0.69.5, and 0.69.6) were found to contain infostealer IOCs and were pushed to Docker Hub without corresponding GitHub releases.