01 发现市场
查看公开的活跃市场、结果选项、condition ID 和 CLOB token ID。
macOS terminal: Run workshop commands in Terminal using zsh or bash.
起点
你位于 workshop_public/polymarket 目录,已经 source 了 .env.polymarket,并且
preflight 已通过。
为什么
Polymarket 用 condition ID 标识一个市场,用另外一个独立的 token ID 标识每个结果选项。 WebSocket 按 token ID 订阅;公开的 trades API 按 condition ID 过滤。
第 1 步:向 Gamma 请求交易最活跃的五个活跃市场
curl --fail --silent --show-error --get \
'https://gamma-api.polymarket.com/markets' \
--data-urlencode 'active=true' \
--data-urlencode 'closed=false' \
--data-urlencode 'limit=20' \
--data-urlencode 'order=volume24hr' \
--data-urlencode 'ascending=false' \
| python3 -c '
import json, sys
selected = 0
for market in json.load(sys.stdin):
if not market.get("acceptingOrders"):
continue
outcomes = json.loads(market["outcomes"])
tokens = json.loads(market["clobTokenIds"])
print(market["question"])
print(" condition:", market["conditionId"])
for outcome, token in zip(outcomes, tokens):
print(f" {outcome}: {token}")
selected += 1
if selected == 5:
break
'预期:五个问题。每个都会打印一个 66 字符的 condition 哈希,以及每个结果选项对应的 一个 token ID。具体问题会随实时市场而变化。
第 2 步:确认某个 condition 的公开交易
从输出中复制一个 condition ID:
export POLYMARKET_CONDITION_ID='0x...'
curl --fail --silent --show-error --get \
'https://data-api.polymarket.com/trades' \
--data-urlencode "market=$POLYMARKET_CONDITION_ID" \
--data-urlencode 'limit=3' \
| python3 -c '
import json, sys
for trade in json.load(sys.stdin):
print(trade["outcome"], trade["side"], trade["size"], "@", trade["price"])
'对于一个交易清淡的市场,返回空结果也是正常的。如果你想立刻看到交易记录, 可以换一个 condition。这里不使用任何身份认证。
第 3 步:理解采集器的选择逻辑
采集器在启动时会重复第 1 步,选出五个市场,解析 JSON 编码的
outcome/token 数组,并把两个结果选项的记录都写入 polymarket.markets。你不需要
把当天的 token ID 硬编码到 .env.polymarket 中。
完成标准
- 你能够为某一个市场指出它的 condition ID 和两个结果选项的 token ID;以及
- 公开的 trades 命令返回了 JSON,即使数组为空也算通过。
下一步:创建 ClickHouse 数据模型。