验证 Polymarket 与 Kalshi 的只读目录及盘口 #4
@@ -76,3 +76,5 @@ sequenceDiagram
|
||||
```
|
||||
|
||||
两侧各有至少两个严格有序的不同价位、最优价均在末尾且哈希一致时,`supports_local_snapshot` 才为 true。空盘与单档记为 `insufficient_levels`。重复价格或非单调价格记为 `non_monotonic_or_repeated`。固定版 SDK 的哈希测试向量恰好买侧最优在末尾、卖侧最优在开头;重放它能核对序列化与分类,但无法判定生产端排序。仓库样例把测试期望的哈希填入原向量的空 hash 字段。[样例](fixtures/sdk-book.json) · [官方 SDK 哈希测试](https://github.com/Polymarket/py-clob-client-v2/blob/9c7c9e89cbbc11528daae90dc66ef65c9380cbdf/tests/test_utilities.py) · [官方序列化顺序](https://github.com/Polymarket/py-clob-client-v2/blob/9c7c9e89cbbc11528daae90dc66ef65c9380cbdf/py_clob_client_v2/utilities.py)
|
||||
|
||||
单资产取样会记录请求资产及本机完成观测的时间 `observed_at_ms`(Unix 毫秒)。连接在响应前失败时,`http_status` 为 null;收到响应但 JSON 解码失败时保留 HTTP 状态。两类失败均写出一行带 `audit_error` 的 JSON 并以非零状态退出。重放已保存的观测要求 HTTP 状态为 2xx。成功取样中的盘口时间戳仍来自场所。
|
||||
|
||||
@@ -4,7 +4,31 @@ mod price_check;
|
||||
mod probes;
|
||||
use anyhow::{ensure, Result};
|
||||
use reqwest::blocking::Client;
|
||||
use std::time::Duration;
|
||||
use serde_json::{json, Value};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
fn observe_book(client: &Client, url: reqwest::Url, token: &str) -> Result<()> {
|
||||
let mut record = json!({"source":url.as_str(),"requested_asset":token,
|
||||
"http_status":null,"book":null,"audit":null,"audit_error":null});
|
||||
let result: Result<()> = (|| {
|
||||
let response = client.get(url).send()?;
|
||||
let status = response.status();
|
||||
record["http_status"] = json!(status.as_u16());
|
||||
let raw: Value = response.json()?;
|
||||
record["book"] = raw;
|
||||
ensure!(status.is_success(), "venue returned HTTP {status}");
|
||||
record["audit"] = book_audit::inspect(&record["book"], token)?;
|
||||
Ok(())
|
||||
})();
|
||||
record["observed_at_ms"] =
|
||||
json!(SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() as u64);
|
||||
if let Err(err) = &result {
|
||||
record["audit_error"] = json!(format!("{err:#}"));
|
||||
}
|
||||
println!("{record}");
|
||||
result
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<_> = std::env::args().skip(1).collect();
|
||||
let usage =
|
||||
@@ -12,6 +36,12 @@ fn main() -> Result<()> {
|
||||
if let [mode, token, file] = args.as_slice() {
|
||||
ensure!(mode == "--replay-book", usage);
|
||||
let input: serde_json::Value = serde_json::from_reader(std::fs::File::open(file)?)?;
|
||||
if let Some(status) = input.get("http_status") {
|
||||
ensure!(
|
||||
status.as_u64().is_some_and(|n| (200..300).contains(&n)),
|
||||
"saved observation has no successful HTTP response"
|
||||
);
|
||||
}
|
||||
let raw = input.get("book").unwrap_or(&input);
|
||||
let report = book_audit::inspect(raw, token)?;
|
||||
println!("{report}");
|
||||
@@ -33,16 +63,7 @@ fn main() -> Result<()> {
|
||||
"https://clob.polymarket.com/book",
|
||||
&[("token_id", token)],
|
||||
)?;
|
||||
let response = client.get(url.clone()).send()?;
|
||||
let status = response.status();
|
||||
let raw: serde_json::Value = response.json()?;
|
||||
let report = book_audit::inspect(&raw, token);
|
||||
let observation = serde_json::json!({"source":url.as_str(),"http_status":status.as_u16(),
|
||||
"book":raw,"audit":report.as_ref().ok(),"audit_error":report.as_ref().err().map(|e|format!("{e:#}"))});
|
||||
println!("{observation}");
|
||||
ensure!(status.is_success(), "venue returned HTTP {status}");
|
||||
report?;
|
||||
return Ok(());
|
||||
return observe_book(&client, url, token);
|
||||
}
|
||||
let mut ok = true;
|
||||
for (name, result) in [
|
||||
|
||||
Reference in New Issue
Block a user