Replay stable production books and validate resting-side quotes
This commit is contained in:
@@ -63,7 +63,7 @@ sequenceDiagram
|
||||
|
||||
## 核对生产买卖报价
|
||||
|
||||
`venue-probe --compare-prices` 在常规输出上增加每个结果的 price_check。它把报价响应、HTTP 状态、前后盘口和哈希放在同一条记录中。两侧都有报价且买一低于卖一,前后盘口哈希和两侧最优档相同,才判断价格方向。BUY 等于卖一、SELL 等于买一记为 matches_documentation,二者正好对调记为 reversed,其他数值组合记为 different_prices。盘口变化记为 book_changed,缺哈希、缺边、买卖同价或报价失败记为 inconclusive。两个结果都符合文档时 price_check_passed 才为 true;其余情况保留观测并以非零状态退出。HTTP 读取之间可能发生变化又恢复,因此单次一致记录只说明这次观测。[官方买卖报价](https://docs.polymarket.com/market-data/prices-order-books.md#best-market-price)
|
||||
`venue-probe --compare-prices` 在常规输出上增加每个结果的 price_check。它把报价响应、HTTP 状态、前后盘口和哈希放在同一条记录中。前后盘口稳定时,BUY 与买一、SELL 与卖一一致就标为 resting_side。缺失买或卖的一侧分别按生产样本的 0 或 1 对照;双侧均空时结论待定。
|
||||
|
||||
[市场 559651 的目录字段摘录](fixtures/gamma-559651.json)来自公开 Gamma JSON 的网页读取,记录自身的更新时间为 2026-12-02 21:08:08 UTC。该 v1 市场同时返回两套 ID,盘口请求使用 clobTokenIds。目录买一为 0.012、卖一为 0.013、最小价格步长为 0.001。测试以这些真实目录值构造模拟的 CLOB 响应;本次工作站直连 Gamma 超时,网页读取该资产的 CLOB book 和 price 也未取得响应。目录观测与模拟样例均不能确认线上 BUY 和 SELL 返回了什么。[Gamma 公开市场目录](https://gamma-api.polymarket.com/markets?limit=1)
|
||||
|
||||
@@ -119,3 +119,5 @@ sequenceDiagram
|
||||
| --- | --- |
|
||||
| [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 均为空数组。此时没有可从该快照读出的买一或卖一。 |
|
||||
|
||||
2026-12-03 06:55 UTC 采集的[同侧报价快照](fixtures/live-side-prices.json)按请求保存前后盘口、报价、时间、方法及响应。双侧盘口最优价为 0.039 和 0.04。缺买盘的结果返回 BUY 字符串 0,缺卖盘的结果返回 SELL 字符串 1。批量 POST 返回相同字符串。文档列出的逗号分隔 GET 在这次生产取样返回 400。三个资产的前后盘口哈希各自一致。[官方单价接口](https://docs.polymarket.com/api-reference/market-data/get-market-price)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -51,23 +51,18 @@ fn classify(before: &Value, after: &Value, buy: &Value, sell: &Value) -> &'stati
|
||||
{
|
||||
return "book_changed";
|
||||
}
|
||||
let (Some(bid), Some(ask), Some(buy), Some(sell)) = (
|
||||
before["best_bid"]["price_micros"].as_u64(),
|
||||
before["best_ask"]["price_micros"].as_u64(),
|
||||
buy["price_micros"].as_u64(),
|
||||
sell["price_micros"].as_u64(),
|
||||
) else {
|
||||
let bid = before["best_bid"]["price_micros"].as_u64();
|
||||
let ask = before["best_ask"]["price_micros"].as_u64();
|
||||
let (Some(buy), Some(sell)) = (buy["price_micros"].as_u64(), sell["price_micros"].as_u64())
|
||||
else {
|
||||
return "inconclusive";
|
||||
};
|
||||
if bid >= ask {
|
||||
return "inconclusive";
|
||||
}
|
||||
if (buy, sell) == (ask, bid) {
|
||||
"matches_documentation"
|
||||
} else if (buy, sell) == (bid, ask) {
|
||||
"reversed"
|
||||
} else {
|
||||
"different_prices"
|
||||
match (bid, ask) {
|
||||
(None, None) => "inconclusive",
|
||||
(Some(b), Some(a)) if b >= a => "inconclusive",
|
||||
_ if (buy, sell) == (bid.unwrap_or(0), ask.unwrap_or(1_000_000)) => "resting_side",
|
||||
(Some(b), Some(a)) if (buy, sell) == (a, b) => "opposing_side",
|
||||
_ => "different_prices",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +70,35 @@ fn classify(before: &Value, after: &Value, buy: &Value, sell: &Value) -> &'stati
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn public_side_prices_replay_against_bracketing_books() {
|
||||
let raw: Value =
|
||||
serde_json::from_str(include_str!("../fixtures/live-side-prices.json")).unwrap();
|
||||
for case in raw["cases"].as_array().unwrap() {
|
||||
let token = case["asset"].as_str().unwrap();
|
||||
let market = json!({"conditionId":case["before"]["body"]["market"]});
|
||||
let read = |key: &str| books::poly_book(&market, token, &case[key]["body"]).unwrap();
|
||||
let price = |side: &str| {
|
||||
let wire = &case[side]["body"]["price"];
|
||||
assert_eq!(
|
||||
&case["batch_post"]["body"][token][side.to_uppercase().as_str()],
|
||||
wire
|
||||
);
|
||||
json!({"price_micros":books::price(wire).unwrap()})
|
||||
};
|
||||
assert_eq!(
|
||||
classify(
|
||||
&read("before"),
|
||||
&read("after"),
|
||||
&price("buy"),
|
||||
&price("sell")
|
||||
),
|
||||
"resting_side"
|
||||
);
|
||||
assert_eq!(case["batch_get"]["http_status"], 400);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_distinct_book_differentiates_the_two_price_conventions() {
|
||||
let gamma: Value =
|
||||
@@ -88,11 +112,8 @@ mod tests {
|
||||
let before = books::poly_book(&gamma, &tokens[0], &raw).unwrap();
|
||||
let bid = json!({"price_micros":12000});
|
||||
let ask = json!({"price_micros":13000});
|
||||
assert_eq!(
|
||||
classify(&before, &before, &ask, &bid),
|
||||
"matches_documentation"
|
||||
);
|
||||
assert_eq!(classify(&before, &before, &bid, &ask), "reversed");
|
||||
assert_eq!(classify(&before, &before, &ask, &bid), "opposing_side");
|
||||
assert_eq!(classify(&before, &before, &bid, &ask), "resting_side");
|
||||
assert_eq!(classify(&before, &before, &bid, &bid), "different_prices");
|
||||
assert_eq!(
|
||||
classify(&before, &before, &json!({"http_status":404}), &bid),
|
||||
@@ -103,10 +124,13 @@ mod tests {
|
||||
assert_eq!(classify(&before, &after, &ask, &bid), "book_changed");
|
||||
after["hash"] = Value::Null;
|
||||
assert_eq!(classify(&before, &after, &ask, &bid), "inconclusive");
|
||||
for edge in [Value::Null, before["best_bid"].clone()] {
|
||||
for (edge, expected) in [
|
||||
(Value::Null, "different_prices"),
|
||||
(before["best_bid"].clone(), "inconclusive"),
|
||||
] {
|
||||
let mut one = before.clone();
|
||||
one["best_ask"] = edge;
|
||||
assert_eq!(classify(&one, &one, &ask, &bid), "inconclusive");
|
||||
assert_eq!(classify(&one, &one, &ask, &bid), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ fn polymarket_report(
|
||||
let passed = compare
|
||||
&& outcomes
|
||||
.iter()
|
||||
.all(|s| s["price_check"]["status"] == "matches_documentation");
|
||||
.all(|s| s["price_check"]["status"] == "resting_side");
|
||||
result["orderbooks_complete"] = json!(complete);
|
||||
if compare {
|
||||
result["price_check_passed"] = json!(passed);
|
||||
|
||||
Reference in New Issue
Block a user