05 Investigate movement
명시적인 ClickHouse SQL로 네 가지 운영 시장 질문에 답합니다.
macOS terminal: Run workshop commands in Terminal using zsh or bash.
시작 지점
원본 테이블과 1분 테이블에 최신 데이터가 들어 있습니다.
질문 1 — 현재 확률은 얼마인가?
SELECT
m.token_id,
m.question,
m.outcome,
round(argMax(t.midpoint, t.event_at) * 100, 2) AS probability_percent,
max(t.event_at) AS last_update
FROM polymarket.price_ticks AS t
INNER JOIN
(
SELECT token_id, question, outcome
FROM polymarket.markets FINAL
) AS m ON m.token_id = t.token_id
WHERE t.midpoint > 0
AND t.event_at >= now() - INTERVAL 30 MINUTE
GROUP BY m.token_id, m.question, m.outcome
ORDER BY m.question, m.outcome;중간값은 최우선 매수/매도 호가에서 나온 참고용 확률이며, 거래 가능한 가격을 보장하지 않습니다.
질문 2 — 어떤 결과가 가장 많이 움직였나?
WITH now() AS current_time
SELECT
m.token_id,
m.question,
m.outcome,
round(argMaxIf(t.midpoint, t.event_at, t.event_at > current_time - INTERVAL 1 MINUTE) * 100, 2) AS now_percent,
round(argMaxIf(t.midpoint, t.event_at, t.event_at <= current_time - INTERVAL 5 MINUTE) * 100, 2) AS five_minutes_ago_percent,
round(now_percent - five_minutes_ago_percent, 2) AS move_points
FROM polymarket.price_ticks AS t
INNER JOIN
(
SELECT token_id, question, outcome
FROM polymarket.markets FINAL
) AS m ON m.token_id = t.token_id
WHERE t.midpoint > 0
AND t.event_at >= current_time - INTERVAL 15 MINUTE
GROUP BY m.token_id, m.question, m.outcome
HAVING now_percent > 0 AND five_minutes_ago_percent > 0
ORDER BY abs(move_points) DESC;결과가 비어 있다면 피드가 아직 5분을 채우지 못한 것입니다. 다음 쿼리들을 계속 진행하고 나중에 다시 돌아오세요.
질문 3 — 스프레드가 넓은가, 데이터가 오래되었나?
SELECT
m.token_id,
m.question,
m.outcome,
round(argMax(t.best_bid, t.event_at) * 100, 2) AS bid_percent,
round(argMax(t.best_ask, t.event_at) * 100, 2) AS ask_percent,
round(ask_percent - bid_percent, 2) AS spread_points,
dateDiff('second', max(t.event_at), now()) AS age_seconds
FROM polymarket.price_ticks AS t
INNER JOIN
(
SELECT token_id, question, outcome
FROM polymarket.markets FINAL
) AS m ON m.token_id = t.token_id
WHERE t.best_bid > 0
AND t.best_ask > 0
AND t.event_at >= now() - INTERVAL 30 MINUTE
GROUP BY m.token_id, m.question, m.outcome
ORDER BY spread_points DESC;스프레드가 넓거나 호가가 오래된 상태에서 나온 움직임은, 신선하고 촘촘한 시장에서 나온 움직임보다 신뢰를 덜 받아야 합니다.
질문 4 — 최근 거래량이 가속되었나?
SELECT
condition_id,
token_id,
title,
outcome,
round(sumIf(price * size, event_at >= now() - INTERVAL 5 MINUTE), 2) AS current_5m_usd,
round(sumIf(
price * size,
event_at >= now() - INTERVAL 10 MINUTE
AND event_at < now() - INTERVAL 5 MINUTE
), 2) AS previous_5m_usd,
round(current_5m_usd / greatest(previous_5m_usd, 0.01), 2) AS velocity_ratio
FROM polymarket.trades_clean
WHERE event_at >= now() - INTERVAL 10 MINUTE
GROUP BY condition_id, token_id, title, outcome
ORDER BY current_5m_usd DESC;이는 price * size로 표현한 공개 체결 거래량이며, 분석이지 추천이 아닙니다.
완료 조건
최소한 현재 확률, 스프레드/신선도, 거래량 쿼리가 오류 없이 반환됩니다. 5분이 지나면 급변동 종목 쿼리도 행을 반환해야 합니다.
다음: Cloud 대시보드를 배포합니다.