PolymarketClickHouse Workshops

01 Discover markets

공개 활성 시장, 결과(outcome), condition ID, CLOB 토큰 ID를 살펴봅니다.

Your computer
macOS terminal: Run workshop commands in Terminal using zsh or bash.

시작 지점

workshop_public/polymarket에 있고, .env.polymarket이 source되어 있으며, preflight가 준비된 상태입니다.

왜

Polymarket은 시장에 대해 condition ID를, 각 결과에 대해 별도의 토큰 ID를 사용합니다. WebSocket은 토큰 ID로 구독하고, 공개 거래 API는 condition ID로 필터링합니다.

Step 1 — Gamma에 가장 활발한 활성 시장 5개 요청

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 해시 하나와 결과별 토큰 ID 하나를 출력합니다. 정확한 질문은 실시간 시장에 따라 달라집니다.

Step 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을 고르세요. 인증은 사용하지 않습니다.

Step 3 — collector의 선택 방식 이해

collector는 시작 시 Step 1을 반복해 시장 다섯 개를 선택하고, JSON으로 인코딩된 결과/토큰 배열을 파싱한 뒤, 양쪽 결과 행을 polymarket.markets에 저장합니다. 오늘의 토큰 ID를 .env.polymarket에 하드코딩하지 않습니다.

완료 조건

  • 시장 하나에 대해 condition ID와 두 결과 토큰 ID를 식별할 수 있다; 그리고
  • 공개 거래 명령이 배열이 비어 있더라도 JSON을 반환한다.

다음: ClickHouse 데이터 모델을 만듭니다.

이 페이지의 내용

Track your progress?

Optional. We email a link to confirm your address; progress records once you open it.

Please use your work email address, not a personal one.

Progress tracking also requires accepting the current Terms of Service in Privacy settings.

KO