API · 참고 자료

gamma-api.polymarket.com에 있는 Gamma API는 "카탈로그"입니다. 시장과 이벤트를 탐색하고 CLOB이 거래에 필요로 하는 토큰 ID를 얻는 방법입니다. 공개형이며 인증이 없어서, 브라우저나 curl로 지금 바로 모든 엔드포인트를 탐색할 수 있고, 이 페이지의 실시간 도구도 마찬가지입니다.

한눈에 보기
  • Base URL: https://gamma-api.polymarket.com · 인증 불필요, 읽기 전용.
  • 요청 한도: 전체 약 10초당 4,000건(/events 약 500, /markets 약 300).
  • 거의 모든 봇의 1단계: 시장을 토큰 ID로 변환한 뒤 CLOB에서 거래.
  • 모든 것이 JSON입니다. 중요한 세 필드는 다시 파싱해야 하는 JSON 문자열로 돌아옵니다(아래 참조).

실제로 쓰게 될 엔드포인트

엔드포인트반환값용도
GET /markets메타데이터, 실시간 가격, 토큰 ID가 포함된 시장.슬러그를 토큰 ID로 변환; 거래 가능한 시장 스캔.
GET /events관련 시장 묶음인 이벤트와 그 하위 시장.주제별 탐색; 다중 아웃컴 카드 렌더링.
GET /public-search?q=이벤트와 시장에 대한 전문 검색.이름만 알 때 시장 찾기.
GET /tags카테고리 태그(정치, 크립토, 스포츠...).유효한 tag_slug 필터 탐색.

/markets와 /events의 일반적인 쿼리 파라미터: active=true, closed=false, slug=, tag_slug=, order=volume24hr, ascending=false, 페이징을 위한 limit=과 offset=.

GET /markets - 요청과 응답

슬러그로 시장 하나를 요청합니다. 시장이 하나여도 배열이 돌아오므로, 요소 [0]을 취하세요:

curl -s "https://gamma-api.polymarket.com/markets?slug=will-it-rain-in-nyc-today" | jq '.[0]'
import requests, json
m = requests.get("https://gamma-api.polymarket.com/markets",
                 params={"slug": "will-it-rain-in-nyc-today"}).json()[0]

축약하고 주석을 단 응답(봇이 신경 쓰는 필드):

{
  "id": "519284",
  "question": "Will it rain in NYC today?",
  "slug": "will-it-rain-in-nyc-today",
  "conditionId": "0x1f2e...c0",      // the market id (NOT what you trade on)
  "active": true,                    // listed and live
  "closed": false,                   // not yet resolved
  "acceptingOrders": true,           // the CLOB is currently taking orders
  "outcomes": "[\"Yes\", \"No\"]",          // JSON string -> parse it
  "clobTokenIds": "[\"7142...\", \"1098...\"]", // JSON string, aligned with outcomes
  "outcomePrices": "[\"0.62\", \"0.38\"]",     // JSON string, last prices
  "bestBid": 0.61,
  "bestAsk": 0.63,
  "lastTradePrice": 0.62,
  "volume24hr": 48213.5,
  "endDate": "2026-06-16T00:00:00Z"
}

두 아웃컴 토큰 ID는 clobTokenIds 안에 있습니다. 이것이 CLOB이 거래하는 대상입니다 - 이를 읽으면 주문을 넣을 수 있습니다.

1순위 함정: JSON 인코딩 문자열 필드

Gamma는 clobTokenIds, outcomes, outcomePrices를 JSON 안의 JSON 인코딩 문자열로 반환하므로, 한 번 더 디코딩해야 합니다. 그리고 어느 토큰이 "Yes"인지 절대 하드코딩하지 마세요. 순서가 보장되지 않으므로, 파싱한 outcomes 배열을 읽어 이름으로 매핑하세요.

import requests, json
m = requests.get("https://gamma-api.polymarket.com/markets",
                 params={"slug": SLUG}).json()[0]
outcomes   = json.loads(m["outcomes"])        # e.g. ["Yes", "No"]
token_ids  = json.loads(m["clobTokenIds"])    # aligned with outcomes
prices     = json.loads(m["outcomePrices"])   # aligned with outcomes
yes_token  = token_ids[outcomes.index("Yes")]
print(yes_token, prices[outcomes.index("Yes")])
const r = await fetch(`https://gamma-api.polymarket.com/markets?slug=${SLUG}`);
const m = (await r.json())[0];
const outcomes  = JSON.parse(m.outcomes);
const tokenIds  = JSON.parse(m.clobTokenIds);
const yesToken  = tokenIds[outcomes.indexOf("Yes")];
curl -s "https://gamma-api.polymarket.com/markets?slug=$SLUG" | jq -r '.[0].clobTokenIds | fromjson | .[0]'

실제 시장에서 시도해 보세요 - 슬러그를 붙여넣고 토큰 ID를 실시간으로 가져옵니다:

거래 가능한 시장 스캔

일반적인 봇의 탐색 쿼리는 활성·미정산 시장을 거래량 많은 순으로 한 카테고리에서 요청합니다:

GET https://gamma-api.polymarket.com/markets
    ?active=true&closed=false&order=volume24hr&ascending=false&limit=20&tag_slug=politics

행동에 옮기기 전에 결과를 클라이언트 측에서 실제로 거래 가능한 시장으로 필터링하세요:

# keep only markets the CLOB will accept orders on right now
tradeable = [m for m in markets
             if m.get("active") and not m.get("closed") and m.get("acceptingOrders")]

실시간 검색(이는 /public-search를 호출한 뒤 시장별로 토큰 ID를 로드합니다):

페이징과 최신성

  • 페이징: limit과 offset을 추가하고 짧은 페이지가 나올 때까지 순회하세요. /events에서는 limit을 500 이하로, /markets에서는 300 이하로 유지하세요.
  • 최신성: 가격(bestBid, bestAsk, lastTradePrice)은 끊임없이 움직입니다. Gamma는 탐색과 대략적인 가격에는 좋지만, 호가와 거래는 캐시된 Gamma 가격이 아니라 실시간 CLOB 호가창에서 하세요.
  • 캐싱: 슬러그 → token_id 매핑(안정적임)은 캐시하고, 가격은 캐시하지 마세요.

GET /events - 다중 아웃컴 그룹

이벤트는 관련 시장을 묶습니다(예: "NYC 시장 선거"는 후보별로 시장 하나씩 담습니다). 다중 아웃컴 카드를 렌더링하거나 한 주제의 모든 시장을 찾는 데 사용하세요:

curl -s "https://gamma-api.polymarket.com/events?slug=nyc-mayor-2025" | jq '.[0].markets | length'

각 이벤트에는 markets 배열이 있고, 모든 항목은 최상위 시장과 동일한 clobTokenIds / outcomes 문자열 필드를 가지므로, 같은 파싱이 적용됩니다.

conditionId 대 token_id. Gamma는 시장의 conditionId와 그 clobTokenIds(아웃컴당 하나)를 줍니다. CLOB은 conditionId가 아니라 token_id로 거래합니다 - 이 둘을 혼동하는 것이 첫 봇에서 가장 흔한 버그입니다.

필드 참고 (발목 잡는 것들)

필드의미
conditionId시장 식별자. 정산과 온체인 조회에 쓰이며, 주문 넣기에는 쓰이지 않음.
clobTokenIds아웃컴 토큰 ID의 JSON 문자열 배열. 파싱해서 CLOB에서 거래하세요.
outcomes / outcomePricesJSON 문자열 배열, clobTokenIds와 인덱스 정렬됨.
active / closed상장·활성 / 정산됨. 거래 가능한 시장은 active && !closed.
acceptingOrdersCLOB이 지금 주문을 받는지 여부. 호가 전에 확인하세요.
bestBid / bestAsk / lastTradePrice참고 가격. 권위 있는 가격은 CLOB 호가창에서 옵니다.

다음: CLOB API (token_id로 거래) · Data API (기록 & PnL) · 오류 해결.