PolymarketClickHouse Workshops

07 AI 市场分析师

把实时市场表交给 ClickHouse Agent,让它自己检测并调查一次价格变动,然后用确定性 SQL 审阅它的回答。

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

起点

采集器在 live、degraded 或 fixture 模式下处于健康状态,模块 05 的查询都能 返回结果,并且你已登录拥有 polymarket-workshop 的那个组织。不需要新的 API key,也不需要新的本地进程:ClickHouse Agents 在 Cloud 中以你在模块 00 里创建的 身份运行。

为什么

模块 05 回答的是你早已写好的四个问题。市场不会等你把问题列表列完。 真正有用的形态是一位值班分析师:发现变动、提出 假设、写出验证假设的查询,并给出结论及其依据。这个 循环也会悄无声息地出错,所以最后两步是审阅 agent,而不是信任它。

第 1 步:打开 ClickHouse Agents 并连接这个服务

open 'https://ai.clickhouse.cloud'

Cloud 控制台也能到同一个地方:进入你的服务,然后点 ClickHouse agents。

创建一个名为 Polymarket analyst 的 agent,添加 ClickHouse 工具,让它指向 polymarket-workshop,并确认它显示 Connected。没有已连接的工具, agent 只会凭猜测推断你的表结构。把下面这段内容粘贴为它的 instructions;每一行都是因为 agent 在缺少它时会出错才写上的:

You answer questions about live public prediction-market data in the polymarket database
of this service. Rules:
- Probability is the quote midpoint: polymarket.price_ticks where midpoint > 0, or the
  merged close of polymarket.market_midpoints_1m. A last_trade_price tick is not one.
- market_midpoints_1m holds AggregateFunction states. Read them only through
  argMinMerge(open), maxMerge(high), minMerge(low), argMaxMerge(close) and
  countMerge(updates), grouped by minute, token_id.
- Metadata comes from polymarket.markets FINAL, trades from polymarket.trades_clean.
- One condition_id per market, one token_id per outcome. A Yes move and its No
  counterpart are one event, not two findings.
- Timestamps are UTC and the newest minute is usually still filling.
- Show the SQL you ran and the age of the data behind every number.
- Public-data analysis only. Never give trading advice.

第 2 步:第一轮:让它自己找出这次变动

Using the ClickHouse tool, find the largest midpoint move in the last 30 minutes of
polymarket.market_midpoints_1m. For each token_id compare the merged close of the most
recent complete minute with the merged close five minutes earlier. Report the question,
the outcome, the token_id, both probabilities in percent, the move in percentage points,
and the two minutes you compared. Show the SQL.

预期:一个具名的结果选项、一个带符号的以百分点表示的变动,以及一段合并了聚合 状态、而不是直接 select 原始 state 列的 SQL。

第 3 步:第二轮:让它调查自己的发现

Investigate that move before you believe it. From polymarket.price_ticks report the
latest best_bid, best_ask, spread in percentage points, and quote age in seconds for that
token_id. From polymarket.trades_clean compare matched volume as price * size over the
five minutes covering the move against the previous five minutes. Then give a verdict of
corroborated, weakly corroborated, or likely artifact, and name the evidence behind it.

你从没告诉它这三个信号该如何组合。让它自己做这个判断,才使它成为一个 agent, 而不是一个 text-to-SQL 盒子。

第 4 步:第三轮:让它反驳自己的结论

List every assumption in that verdict that could be wrong, and for each one the single
query that would falsify it. Run the two you consider most likely to be wrong, then tell
me whether the verdict survives.

一个有价值的回答会指出最新那个不完整的分钟、报价年龄,以及数据稀薄的那一分钟 背后只有寥寥几次更新。记录下结论是否站得住脚。

第 5 步:用确定性 SQL 审阅 agent

在 Cloud SQL 控制台中运行下面这段。它不借助 agent 就回答了第 2 步的问题,所以它的第一行就是 你的参考答案:

WITH per_minute AS
(
    SELECT
        token_id,
        minute,
        argMaxMerge(close) AS close_midpoint
    FROM polymarket.market_midpoints_1m
    WHERE minute >= now() - INTERVAL 30 MINUTE
      AND minute < toStartOfMinute(now())
    GROUP BY token_id, minute
)
SELECT
    m.question,
    m.outcome,
    p.token_id,
    round(argMax(p.close_midpoint, p.minute) * 100, 2) AS latest_percent,
    round(argMin(p.close_midpoint, p.minute) * 100, 2) AS oldest_percent,
    round(latest_percent - oldest_percent, 2) AS move_points,
    min(p.minute) AS window_start,
    max(p.minute) AS window_end
FROM per_minute AS p
INNER JOIN
(
    SELECT token_id, question, outcome
    FROM polymarket.markets FINAL
) AS m ON m.token_id = p.token_id
GROUP BY m.question, m.outcome, p.token_id
ORDER BY abs(move_points) DESC
LIMIT 5;

两者的时间窗口不同,这是故意的:这段 SQL 覆盖现有数据中最旧到最新的完整分钟, 而 agent 被要求的是五分钟步长。请比较 token_id、move_points 的 符号和量级,而不是小数位。然后拿 agent 给出的佐证数字,去核对模块 06 中保存的 Spread and freshness 和 Volume velocity 查询结果。

第 6 步:写下 agent 错在哪里

下面这些问题通常至少会出现一个。在对话记录中找出你遇到的那个:

  • 从 market_midpoints_1m 中 select close 或 high 却没用 Merge 函数,然后 对返回的任何结果都信心满满地加以解释;
  • 把最新那个仍在填充的分钟当作完整分钟,从而夸大了最后一段变动;
  • 把某个 Yes token 和它对应的 No token 当成两个独立的涨跌项来汇报;
  • 在 polymarket.markets 上漏掉了 FINAL,导致被重新发现的市场 join 出两行;
  • 把中间价说成可成交价格,或者报出变动却不说明数据年龄。

如果它的数字与审阅查询完全一致,就直接测试那个不完整的分钟:问它 最新那个分钟是否完整,然后比较 polymarket.market_midpoints_1m 中的 max(minute) 与 toStartOfMinute(now())。两者相等就说明它并不完整, 而声称完整的 agent 就是在关于实时数据说了假话。

完成标准

  • agent 的检测 SQL 是通过 Merge 函数读取 market_midpoints_1m 的;
  • 它的结论引用了价差、报价年龄和交易量,而不是只看价格;
  • 审阅查询的第一行在 token 和方向上与 agent 一致,或者你能 解释清楚差异的原因;以及
  • 你已经写下了 agent 弄错或夸大的一件事。

下一步:收尾与清理。

本页内容

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.

ZH