Reconstruct public CLOB chart samples from historical books

This commit is contained in:
2026-12-03 16:29:55 +08:00
parent d7a77c734d
commit 2a8916e1d9
11 changed files with 223 additions and 85 deletions
+58 -23
View File
@@ -1512,6 +1512,64 @@ fn wallet_activity_paginates_fills_and_records_each_automatic_redemption_once()
assert_eq!(deposit["activity"][0]["cash_delta_cents"], 2000);
}
#[test]
fn legacy_history_samples_the_book_without_fills_and_appends_the_latest_mark() {
let dir = tempdir().unwrap();
let path = dir.path().join("chart.db");
let mut exchange = Exchange::open(&path).unwrap();
for line in include_str!("../../../docs/examples/midpoint.jsonl").lines() {
exchange
.execute(serde_json::from_str(line).unwrap())
.unwrap();
}
let db = rusqlite::Connection::open(&path).unwrap();
db.execute(
"UPDATE quote_events SET at_ms=CASE WHEN yes_ask IS NULL THEN 119000 ELSE 180001 END",
[],
)
.unwrap();
db.execute(
"UPDATE chart_origins SET at_ms=119000 WHERE market='mid-example'",
[],
)
.unwrap();
let read = |e: &Exchange, outcome: &str, start: f64, end: f64| {
e.clob_price_history(serde_json::from_value(json!({
"market":format!("eb:{outcome}:mid-example"), "startTs":start, "endTs":end, "fidelity":1
})).unwrap()).unwrap()["history"].as_array().unwrap().clone()
};
let points = read(&exchange, "YES", 120.0, 240.0);
assert_eq!(points.len(), 4);
assert_eq!(
&points[..3],
&[
json!({"t":120,"p":0.54}),
json!({"t":180,"p":0.54}),
json!({"t":240,"p":0.085})
]
);
assert_eq!(points[3]["p"], 0.085);
assert!(points[3]["t"].as_i64().unwrap() > 240);
exchange
.execute(json!({"op":"close","id":"close","market":"mid-example"}))
.unwrap();
exchange
.execute(json!({"op":"finalize","id":"verdict","market":"mid-example","winner":"NO"}))
.unwrap();
db.execute("UPDATE price_settlements SET at_ms=273000", [])
.unwrap();
drop(exchange);
let reopened = Exchange::open(path).unwrap();
assert_eq!(
read(&reopened, "NO", 180.001, 240.0),
vec![json!({"t":240,"p":0.915}), json!({"t":273,"p":1})]
);
assert_eq!(
read(&reopened, "YES", 5.0, 5.0),
vec![json!({"t":273,"p":0})]
);
}
#[test]
fn prices_history_keeps_the_terminal_tick_and_pins_pages_before_settlement() {
let dir = tempdir().unwrap();
@@ -1543,25 +1601,6 @@ fn prices_history_keeps_the_terminal_tick_and_pins_pages_before_settlement() {
let wire = |engine: &Exchange, params: Value| {
engine.public_price_history(serde_json::from_value(params).unwrap())
};
let clob = |engine: &Exchange, start: f64, end: f64, minutes: i64| {
engine
.clob_price_history(
serde_json::from_value(json!({
"market":"eb:YES:e","startTs":start,"endTs":end,"fidelity":minutes
}))
.unwrap(),
)
.unwrap()
};
assert_eq!(
clob(&e, 120.0, 245.0, 1),
json!({"history":[{"t":149,"p":0.47},{"t":245,"p":0.55}]})
);
assert_eq!(clob(&e, 149.001, 244.999, 1), json!({"history":[]}));
assert_eq!(
clob(&e, 120.0, 245.0, 10),
json!({"history":[{"t":245,"p":0.55}]})
);
let first_wire = wire(
&e,
json!({"tokenId":"eb:YES:e","start":120,"end":290,"bucketSeconds":60,"limit":1}),
@@ -1593,10 +1632,6 @@ fn prices_history_keeps_the_terminal_tick_and_pins_pages_before_settlement() {
.unwrap();
drop(e);
let mut e = Exchange::open(&path).unwrap();
assert_eq!(
clob(&e, 120.0, 290.0, 1),
json!({"history":[{"t":149,"p":0.47},{"t":273,"p":0.5}]})
);
let second_wire = wire(
&e,
json!({"token_id":"eb:YES:e","start":120,"end":290,"cursor":saved,"limit":99}),