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

@chainsawteam/polymarket-sdk

v1.0.4

Published

TypeScript SDK for Polymarket trading - market data, order management, and position redemption

Readme

@chainsawteam/polymarket-sdk

TypeScript SDK for Polymarket trading - market data, order management, and position redemption.

特性

  • 📊 市场数据: 获取订单簿、价格、价差等市场数据
  • 📈 订单管理: 下单、取消订单、查询订单状态
  • 💰 持仓查询: 获取用户持仓和 PNL 数据
  • 🔄 赎回功能: 支持已结算市场的仓位赎回
  • 🔐 多钱包支持: EOA、Gnosis Safe、Polymarket 代理钱包
  • 🌐 代理支持: 支持 HTTP/HTTPS/SOCKS5 代理
  • 📡 WebSocket: 实时市场数据和订单更新

安装

npm install @chainsawteam/polymarket-sdk
# 或
pnpm add @chainsawteam/polymarket-sdk

快速开始

import { PolymarketSDK } from '@chainsawteam/polymarket-sdk';

// 初始化 SDK(必需参数)
const sdk = new PolymarketSDK({
  // 必需配置
  rpcUrl: 'https://rpc.ankr.com/polygon',
  usdcAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
  ctfAddress: '0xA16fb7fF7E72771834eD4E1a3474575dCe91ea13',

  // 可选:交易功能需要私钥
  walletPrivateKey: process.env.PRIVATE_KEY,

  // 可选:代理配置
  proxy: {
    type: 'socks5',
    host: '127.0.0.1',
    port: 1080,
    auth: {
      username: 'user',
      password: 'pass'
    }
  }
});

// 异步初始化(用于交易功能)
await sdk.initAsync();

// 获取市场数据
const orderBook = await sdk.getOrderBookSummary('token_id');
console.log(orderBook);

配置

必需参数

| 参数 | 类型 | 说明 | |-----|------|-----| | rpcUrl | string | Polygon RPC URL | | usdcAddress | string | USDC 合约地址 (Polygon) | | ctfAddress | string | CTF 合约地址 |

可选参数

| 参数 | 类型 | 说明 | |-----|------|-----| | walletPrivateKey | string | 钱包私钥(交易必需) | | funderAddress | string | 资金地址(默认等于 signer.address) | | proxy | ProxyConfig | 代理配置 | | timeout | number | 请求超时时间(毫秒) |

代理配置

SDK 支持多种代理类型,适用于不同网络环境:

// SOCKS5 代理(推荐)
proxy: {
  type: 'socks5',
  host: '127.0.0.1',
  port: 1080
}

// HTTP 代理
proxy: {
  type: 'http',
  host: '127.0.0.1',
  port: 8080
}

// 带认证的代理
proxy: {
  type: 'socks5',
  host: 'proxy.example.com',
  port: 1080,
  auth: {
    username: 'user',
    password: 'pass'
  }
}

注意: WebSocket 仅支持 SOCKS 代理。HTTP 代理不适用于 WebSocket 连接。

主要功能

市场数据

// 获取订单簿
const orderBook = await sdk.getOrderBookSummary(tokenId);

// 获取多个订单簿
const orderBooks = await sdk.getMultipleOrderBooks([tokenId1, tokenId2]);

// 获取市场价格
const price = await sdk.getMarketPrice(tokenId, 'BUY');

// 获取市场详情
const market = await sdk.getMarketDetailsByConditionId(conditionId);

订单管理

// 下单
const order = await sdk.placeOrder({
  tokenId: 'token_id',
  side: 'BUY',
  size: 10,
  price: 0.5,
  orderType: 'LIMIT'
});

// 获取活跃订单
const orders = await sdk.getActiveOrders();

// 取消订单
await sdk.cancelOrder(orderId);

持仓查询

// 获取用户持仓
const positions = await sdk.getUserPositions(walletAddress);

// 获取用户 PNL
const pnl = await sdk.getUserPnL(walletAddress);

赎回功能

// 获取可赎回的持仓
const redeemable = await sdk.getRedeemablePositions(walletAddress);

// 赎回持仓
const result = await sdk.redeemPositions({
  conditionId: 'condition_id',
  indexSets: [1] // 1 = NO, 2 = YES
});

WebSocket

// 连接 WebSocket
await sdk.connectWebSocket();

// 订阅订单簿更新
sdk.subscribeToAssetIds([tokenId]);

// 添加监听器
sdk.addOrderBookUpdateListener((update) => {
  console.log('Order book update:', update);
});

// 断开连接
sdk.disconnectWebSocket();

钱包类型

SDK 支持多种钱包类型,会自动检测或可手动配置:

| 类型 | SignatureType | 说明 | |-----|--------------|-----| | EOA | 0 | 直接签名,funderAddress 必须等于 signer.address | | Polymarket 代理 | 1 | 邮箱登录钱包,funderAddress 是代理地址 | | Gnosis Safe | 2 | 多签钱包 |

// 自动检测(默认)
const sdk = new PolymarketSDK({
  rpcUrl,
  usdcAddress,
  ctfAddress,
  walletPrivateKey,
  walletConfig: {
    funderAddress: '0x...', // 不同地址时会自动检测类型
  }
});

// 手动指定类型
const sdk = new PolymarketSDK({
  rpcUrl,
  usdcAddress,
  ctfAddress,
  walletPrivateKey,
  walletConfig: {
    funderAddress: '0x...',
    signatureType: SignatureType.POLY_GNOSIS_SAFE,
    autoDetect: false
  }
});

API 文档

完整的 API 文档请参考 TypeScript 类型定义。

License

MIT