PolymarketClickHouse Workshops

05 値動きを調査する

運用上の 4 つの市場に関する問いを、明示的な ClickHouse SQL で答えます。

Your computer
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 ダッシュボードを公開する。

このページの内容

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.

JA