From 0aabc9fa029055f06f2388f1c72599b8eb89d1ea Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Thu, 3 Dec 2026 14:47:57 +0800 Subject: [PATCH] Capture and verify production Polymarket and Kalshi order books --- crates/venue-probe/README.md | 10 + .../fixtures/live-kalshi-book.json | 17 + .../fixtures/live-polymarket-books.json | 698 ++++++++++++++++++ crates/venue-probe/src/probes.rs | 44 ++ 4 files changed, 769 insertions(+) create mode 100644 crates/venue-probe/fixtures/live-kalshi-book.json create mode 100644 crates/venue-probe/fixtures/live-polymarket-books.json diff --git a/crates/venue-probe/README.md b/crates/venue-probe/README.md index 174426b..9215050 100644 --- a/crates/venue-probe/README.md +++ b/crates/venue-probe/README.md @@ -109,3 +109,13 @@ sequenceDiagram | `fixtures/gamma-v2-docs.json` | positionIds | PositionManager、Router。两侧解得同一个 31 字节条件 | 取自官方 Market Details 页的两个 JSON 示例,未取得该市场同期生产盘口 | 这两份记录验证了目录所指的标识与目标。生产盘口深度、钱包授权和链上操作仍须分别验证。[Gamma 目录](https://gamma-api.polymarket.com/markets?limit=1) · [官方市场样例](https://docs.polymarket.com/market-data/market-details) + + +## 生产盘口取样 + +2026-12-03 06:46 UTC 从官方接口匿名读取了下列快照。fixture 保存了请求 URL、HTTP 状态、响应日期和完整 JSON 响应体,可离线检查。该次取样只覆盖公开行情读取。 + +| 场所与样例 | 当时的观测 | +| --- | --- | +| [Polymarket 两个结果](fixtures/live-polymarket-books.json) | 美联储十二月降息 25 个基点市场。一个结果只有 82 档卖单,最低卖价 0.001。另一个结果只有 82 档买单,最高买价 0.999。两侧最优档均在数组末尾,两个响应的 SHA-1 都能用 SDK 字段顺序重算。 | +| [Kalshi 空盘口](fixtures/live-kalshi-book.json) | KXPLATINUMH-26DEC0303-T1377.49 返回 HTTP 200,yes_dollars 和 no_dollars 均为空数组。此时没有可从该快照读出的买一或卖一。 | diff --git a/crates/venue-probe/fixtures/live-kalshi-book.json b/crates/venue-probe/fixtures/live-kalshi-book.json new file mode 100644 index 0000000..4850c2d --- /dev/null +++ b/crates/venue-probe/fixtures/live-kalshi-book.json @@ -0,0 +1,17 @@ +{ + "venue": "kalshi", + "retrieved_at": "2026-12-03T06:46:06.218024+00:00", + "responses": [ + { + "url": "https://external-api.kalshi.com/trade-api/v2/markets/KXPLATINUMH-26DEC0303-T1377.49/orderbook?depth=5", + "status": 200, + "http_date": "Thu, 03 Dec 2026 06:46:06 GMT", + "body": { + "orderbook_fp": { + "no_dollars": [], + "yes_dollars": [] + } + } + } + ] +} diff --git a/crates/venue-probe/fixtures/live-polymarket-books.json b/crates/venue-probe/fixtures/live-polymarket-books.json new file mode 100644 index 0000000..7d37e99 --- /dev/null +++ b/crates/venue-probe/fixtures/live-polymarket-books.json @@ -0,0 +1,698 @@ +{ + "venue": "polymarket", + "retrieved_at": "2026-12-03T06:46:07.125735+00:00", + "responses": [ + { + "url": "https://clob.polymarket.com/book?token_id=77367448845023382525249480243608609306658725883285195065573683809293972009019", + "status": 200, + "http_date": "Thu, 03 Dec 2026 06:46:06 GMT", + "body": { + "market": "0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8", + "asset_id": "77367448845023382525249480243608609306658725883285195065573683809293972009019", + "timestamp": "1796280316915", + "hash": "019ed79339d95dcaeaefa222db1474502202a87c", + "bids": [], + "asks": [ + { + "price": "0.999", + "size": "21016611" + }, + { + "price": "0.998", + "size": "67500" + }, + { + "price": "0.997", + "size": "13583.32" + }, + { + "price": "0.996", + "size": "1750" + }, + { + "price": "0.995", + "size": "1400" + }, + { + "price": "0.994", + "size": "19166.66" + }, + { + "price": "0.993", + "size": "999.99" + }, + { + "price": "0.992", + "size": "875" + }, + { + "price": "0.991", + "size": "777.77" + }, + { + "price": "0.99", + "size": "4503.92" + }, + { + "price": "0.989", + "size": "66129.54" + }, + { + "price": "0.988", + "size": "1216.66" + }, + { + "price": "0.98", + "size": "500" + }, + { + "price": "0.97", + "size": "734.07" + }, + { + "price": "0.969", + "size": "1000" + }, + { + "price": "0.95", + "size": "245.41" + }, + { + "price": "0.939", + "size": "5000" + }, + { + "price": "0.925", + "size": "3000" + }, + { + "price": "0.91", + "size": "5" + }, + { + "price": "0.904", + "size": "4720" + }, + { + "price": "0.9", + "size": "10" + }, + { + "price": "0.899", + "size": "250" + }, + { + "price": "0.89", + "size": "90.9" + }, + { + "price": "0.888", + "size": "1999.99" + }, + { + "price": "0.855", + "size": "4810" + }, + { + "price": "0.799", + "size": "250" + }, + { + "price": "0.798", + "size": "9000" + }, + { + "price": "0.74", + "size": "38.46" + }, + { + "price": "0.54", + "size": "21.73" + }, + { + "price": "0.47", + "size": "15790.08" + }, + { + "price": "0.469", + "size": "5000" + }, + { + "price": "0.43", + "size": "10032.89" + }, + { + "price": "0.39", + "size": "7500" + }, + { + "price": "0.388", + "size": "1500" + }, + { + "price": "0.38", + "size": "1000" + }, + { + "price": "0.35", + "size": "8666.66" + }, + { + "price": "0.288", + "size": "500" + }, + { + "price": "0.28", + "size": "1005" + }, + { + "price": "0.279", + "size": "4810" + }, + { + "price": "0.22", + "size": "6" + }, + { + "price": "0.21", + "size": "10" + }, + { + "price": "0.2", + "size": "50" + }, + { + "price": "0.18", + "size": "1020.25" + }, + { + "price": "0.179", + "size": "365" + }, + { + "price": "0.175", + "size": "150" + }, + { + "price": "0.17", + "size": "1000" + }, + { + "price": "0.14", + "size": "5" + }, + { + "price": "0.139", + "size": "400" + }, + { + "price": "0.1", + "size": "500" + }, + { + "price": "0.098", + "size": "1000" + }, + { + "price": "0.097", + "size": "980" + }, + { + "price": "0.096", + "size": "100" + }, + { + "price": "0.08", + "size": "150" + }, + { + "price": "0.079", + "size": "100" + }, + { + "price": "0.039", + "size": "499.98" + }, + { + "price": "0.038", + "size": "500" + }, + { + "price": "0.034", + "size": "53" + }, + { + "price": "0.03", + "size": "50" + }, + { + "price": "0.028", + "size": "1000" + }, + { + "price": "0.025", + "size": "20" + }, + { + "price": "0.024", + "size": "1248" + }, + { + "price": "0.023", + "size": "97" + }, + { + "price": "0.022", + "size": "1292.31" + }, + { + "price": "0.021", + "size": "74" + }, + { + "price": "0.02", + "size": "50" + }, + { + "price": "0.019", + "size": "550" + }, + { + "price": "0.018", + "size": "1495" + }, + { + "price": "0.015", + "size": "400" + }, + { + "price": "0.014", + "size": "857" + }, + { + "price": "0.013", + "size": "1087" + }, + { + "price": "0.012", + "size": "45" + }, + { + "price": "0.011", + "size": "749.29" + }, + { + "price": "0.01", + "size": "1203" + }, + { + "price": "0.009", + "size": "11287.36" + }, + { + "price": "0.008", + "size": "4830" + }, + { + "price": "0.007", + "size": "1349.03" + }, + { + "price": "0.006", + "size": "850" + }, + { + "price": "0.005", + "size": "1273" + }, + { + "price": "0.004", + "size": "931.25" + }, + { + "price": "0.003", + "size": "287998.71" + }, + { + "price": "0.002", + "size": "525378.36" + }, + { + "price": "0.001", + "size": "391881.71" + } + ], + "min_order_size": "5", + "tick_size": "0.001", + "neg_risk": true, + "last_trade_price": "0.001" + } + }, + { + "url": "https://clob.polymarket.com/book?token_id=23677896678650147625251750117853328843601853501710889530409633595389256242910", + "status": 200, + "http_date": "Thu, 03 Dec 2026 06:46:06 GMT", + "body": { + "market": "0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8", + "asset_id": "23677896678650147625251750117853328843601853501710889530409633595389256242910", + "timestamp": "1796280316915", + "hash": "cf7a136a82ea7081f8a77202b0d8d57d6e9d7042", + "bids": [ + { + "price": "0.001", + "size": "21016611" + }, + { + "price": "0.002", + "size": "67500" + }, + { + "price": "0.003", + "size": "13583.32" + }, + { + "price": "0.004", + "size": "1750" + }, + { + "price": "0.005", + "size": "1400" + }, + { + "price": "0.006", + "size": "19166.66" + }, + { + "price": "0.007", + "size": "999.99" + }, + { + "price": "0.008", + "size": "875" + }, + { + "price": "0.009", + "size": "777.77" + }, + { + "price": "0.01", + "size": "4503.92" + }, + { + "price": "0.011", + "size": "66129.54" + }, + { + "price": "0.012", + "size": "1216.66" + }, + { + "price": "0.02", + "size": "500" + }, + { + "price": "0.03", + "size": "734.07" + }, + { + "price": "0.031", + "size": "1000" + }, + { + "price": "0.05", + "size": "245.41" + }, + { + "price": "0.061", + "size": "5000" + }, + { + "price": "0.075", + "size": "3000" + }, + { + "price": "0.09", + "size": "5" + }, + { + "price": "0.096", + "size": "4720" + }, + { + "price": "0.1", + "size": "10" + }, + { + "price": "0.101", + "size": "250" + }, + { + "price": "0.11", + "size": "90.9" + }, + { + "price": "0.112", + "size": "1999.99" + }, + { + "price": "0.145", + "size": "4810" + }, + { + "price": "0.201", + "size": "250" + }, + { + "price": "0.202", + "size": "9000" + }, + { + "price": "0.26", + "size": "38.46" + }, + { + "price": "0.46", + "size": "21.73" + }, + { + "price": "0.53", + "size": "15790.08" + }, + { + "price": "0.531", + "size": "5000" + }, + { + "price": "0.57", + "size": "10032.89" + }, + { + "price": "0.61", + "size": "7500" + }, + { + "price": "0.612", + "size": "1500" + }, + { + "price": "0.62", + "size": "1000" + }, + { + "price": "0.65", + "size": "8666.66" + }, + { + "price": "0.712", + "size": "500" + }, + { + "price": "0.72", + "size": "1005" + }, + { + "price": "0.721", + "size": "4810" + }, + { + "price": "0.78", + "size": "6" + }, + { + "price": "0.79", + "size": "10" + }, + { + "price": "0.8", + "size": "50" + }, + { + "price": "0.82", + "size": "1020.25" + }, + { + "price": "0.821", + "size": "365" + }, + { + "price": "0.825", + "size": "150" + }, + { + "price": "0.83", + "size": "1000" + }, + { + "price": "0.86", + "size": "5" + }, + { + "price": "0.861", + "size": "400" + }, + { + "price": "0.9", + "size": "500" + }, + { + "price": "0.902", + "size": "1000" + }, + { + "price": "0.903", + "size": "980" + }, + { + "price": "0.904", + "size": "100" + }, + { + "price": "0.92", + "size": "150" + }, + { + "price": "0.921", + "size": "100" + }, + { + "price": "0.961", + "size": "499.98" + }, + { + "price": "0.962", + "size": "500" + }, + { + "price": "0.966", + "size": "53" + }, + { + "price": "0.97", + "size": "50" + }, + { + "price": "0.972", + "size": "1000" + }, + { + "price": "0.975", + "size": "20" + }, + { + "price": "0.976", + "size": "1248" + }, + { + "price": "0.977", + "size": "97" + }, + { + "price": "0.978", + "size": "1292.31" + }, + { + "price": "0.979", + "size": "74" + }, + { + "price": "0.98", + "size": "50" + }, + { + "price": "0.981", + "size": "550" + }, + { + "price": "0.982", + "size": "1495" + }, + { + "price": "0.985", + "size": "400" + }, + { + "price": "0.986", + "size": "857" + }, + { + "price": "0.987", + "size": "1087" + }, + { + "price": "0.988", + "size": "45" + }, + { + "price": "0.989", + "size": "749.29" + }, + { + "price": "0.99", + "size": "1203" + }, + { + "price": "0.991", + "size": "11287.36" + }, + { + "price": "0.992", + "size": "4830" + }, + { + "price": "0.993", + "size": "1349.03" + }, + { + "price": "0.994", + "size": "850" + }, + { + "price": "0.995", + "size": "1273" + }, + { + "price": "0.996", + "size": "931.25" + }, + { + "price": "0.997", + "size": "287998.71" + }, + { + "price": "0.998", + "size": "525378.36" + }, + { + "price": "0.999", + "size": "391881.71" + } + ], + "asks": [], + "min_order_size": "5", + "tick_size": "0.001", + "neg_risk": true, + "last_trade_price": "0.001" + } + } + ] +} diff --git a/crates/venue-probe/src/probes.rs b/crates/venue-probe/src/probes.rs index fb9c09f..bd2f47f 100644 --- a/crates/venue-probe/src/probes.rs +++ b/crates/venue-probe/src/probes.rs @@ -116,6 +116,50 @@ fn kalshi_report( mod tests { use super::*; + #[test] + fn captured_production_books_keep_empty_sides_and_exact_prices() { + let capture: Value = + serde_json::from_str(include_str!("../fixtures/live-polymarket-books.json")).unwrap(); + let responses = capture["responses"].as_array().unwrap(); + assert_eq!(responses.len(), 2); + let condition = json!({"conditionId":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8"}); + for (i, response) in responses.iter().enumerate() { + let asset = response["url"] + .as_str() + .unwrap() + .split_once("token_id=") + .unwrap() + .1; + let raw = &response["body"]; + let book = books::poly_book(&condition, asset, raw).unwrap(); + let audit = crate::book_audit::inspect(raw, asset).unwrap(); + assert_eq!(audit["hash_matches"], true); + let (active, empty, side, price) = if i == 0 { + ("best_ask", "best_bid", "asks", 1_000) + } else { + ("best_bid", "best_ask", "bids", 999_000) + }; + assert!(book[empty].is_null()); + assert_eq!( + book[active], + json!({"price_micros":price,"size":"391881.71"}) + ); + assert_eq!(audit[side]["levels"], 82); + assert_eq!(audit[side]["order"], "best_last"); + } + + let capture: Value = + serde_json::from_str(include_str!("../fixtures/live-kalshi-book.json")).unwrap(); + let book = books::kalshi_book( + "KXPLATINUMH-26DEC0303-T1377.49", + &capture["responses"][0]["body"], + ) + .unwrap(); + for side in ["yes", "no"] { + assert_eq!(book[side], json!({"best_bid":null,"best_ask":null})); + } + } + #[test] fn failed_first_polymarket_book_preserves_the_second_observation() { let market: Value =