跳转到主要内容
Polymarket 提供 WebSocket 频道,用于近实时流式传输订单簿数据、交易和个人订单活动。共有四个可用频道:marketusersportsRTDS(Real-Time Data Socket)。

频道

频道端点需要认证
Marketwss://ws-subscriptions-clob.polymarket.com/ws/market
Userwss://ws-subscriptions-clob.polymarket.com/ws/user
Sportswss://sports-api.polymarket.com/ws
RTDSwss://ws-live-data.polymarket.com可选

Market 频道

类型说明自定义功能
book完整订单簿快照
price_change价格级别更新
tick_size_change最小价格变动单位变化
last_trade_price交易执行
best_bid_ask最优价格更新
new_market新市场创建
market_resolved市场判定
标记为”自定义功能”的类型需要在订阅时设置 custom_feature_enabled: true

User 频道

类型说明
trade交易生命周期更新(MATCHED → CONFIRMED)
order订单下单、更新和取消

Sports

类型说明
sport_result实时比赛分数、时段和状态

订阅

连接后发送订阅消息以指定你想接收的数据。

Market 频道

{
  "assets_ids": [
    "21742633143463906290569050155826241533067272736897614950488156847949938836455",
    "48331043336612883890938759509493159234755048973500640148014422747788308965732"
  ],
  "type": "market",
  "custom_feature_enabled": true
}
字段类型说明
assets_idsstring[]要订阅的代币 ID
typestring频道标识符
custom_feature_enabledboolean启用 best_bid_asknew_marketmarket_resolved 事件

User 频道

{
  "auth": {
    "apiKey": "your-api-key",
    "secret": "your-api-secret",
    "passphrase": "your-passphrase"
  },
  "markets": ["0x1234...condition_id"],
  "type": "user"
}
auth 字段(apiKeysecretpassphrase仅在 user 频道中需要。对于 market 频道,这些字段是可选的,可以省略。
字段类型说明
authobjectAPI 凭证(apiKeysecretpassphrase
marketsstring[]要接收事件的 condition ID
typestring频道标识符
user 频道通过 condition ID(市场标识符)订阅,而不是 asset ID。每个市场有一个 condition ID,但有两个 asset ID(Yes 和 No 代币)。

Sports 频道

无需订阅消息。连接后即可开始接收所有活跃体育赛事的数据。

动态订阅

无需重新连接即可修改订阅。

订阅更多资产

{
  "assets_ids": ["new_asset_id_1", "new_asset_id_2"],
  "operation": "subscribe",
  "custom_feature_enabled": true
}

取消订阅资产

{
  "assets_ids": ["asset_id_to_remove"],
  "operation": "unsubscribe"
}
对于 user 频道,使用 markets 而不是 assets_ids
{
  "markets": ["0x1234...condition_id"],
  "operation": "subscribe"
}

心跳

Market 和 User 频道

每 10 秒发送一次 PING。服务器会响应 PONG
PING

Sports 频道

服务器每 5 秒发送一次 ping。你需要在 10 秒内响应 pong
pong
如果你在 10 秒内没有响应服务器的 ping,连接将被关闭。

故障排除

连接后立即发送有效的订阅消息。服务器可能会关闭在超时时间内未订阅的连接。
你没有发送心跳。对于 market/user 频道,每 10 秒发送一次 PING;对于 sports 频道,用 pong 响应服务器的 ping
  1. 验证你的 asset ID 或 condition ID 是否正确 2. 检查市场是否处于活跃状态(未判定) 3. 如果期望接收 best_bid_asknew_marketmarket_resolved 事件,请设置 custom_feature_enabled: true
验证你的 API 凭证是否正确且未过期。