PMWallets
EN

Node.js

用 TypeScript 安装、连接并接收成交。

GitHub pmwallets-node,npm pmwallets。 Node.js ≥ 20,自带 TypeScript 类型。

shell
npm install pmwallets
typescript
import { PmwClient, FillStream, FileStateStore, verifyWebhook } from 'pmwallets';

const pmw = new PmwClient({ apiKey: process.env.PMW_API_KEY! });

// who is making money on Polymarket, and how
const board = await pmw.leaderboard({ minWinLo: 0.55, minEligible: 30, style: 'taker', status: 'active', limit: 50 });
// only wallets whose address unlocks for free or in the cheapest paid band (0 = free … 5; the ladder is board.pricing.bands)
const cheap = await pmw.leaderboard({ bands: [0, 1], minWinLo: 0.55 });

// follow one (billed per entity per hour; 402 = balance too low, 409 = dormant)
await pmw.subscribe({ entityId: board.rows[0].entityId, channels: ['ws'] });

// every fill of every entity you follow
const stream = new FillStream({
  client: pmw,
  store: new FileStateStore('./stream.json'),    // a restart resumes from the last saved cursor
  onFill: async (fill, { source }) => console.log(source, fill.side, fill.price, fill.tokenId),
  onEvent: (e) => e.type === 'replaced' && console.warn('another connection took the stream'),
});
await stream.start();
作用
PmwClient全部 REST 调用,见方法一览
FillStreamWebSocket,带重连与保活;发现断档并补回;去重;游标落盘
verifyWebhook(rawBody, signature, secret)校验 x-pmw-signature(原始 body 的 HMAC-SHA256)