Expose paginated token price history through the public HTTP service

This commit is contained in:
2026-12-03 08:12:01 +08:00
parent 2ef0784ddc
commit 9b25fdc424
11 changed files with 292 additions and 2 deletions
+49
View File
@@ -1529,6 +1529,26 @@ fn prices_history_keeps_the_terminal_tick_and_pins_pages_before_settlement() {
point(245, 0.55, 0, "trade")
])
);
let wire = |engine: &Exchange, params: Value| {
engine.public_price_history(serde_json::from_value(params).unwrap())
};
let first_wire = wire(
&e,
json!({"tokenId":"eb:YES:e","start":120,"end":290,"bucketSeconds":60,"limit":1}),
)
.unwrap();
assert_eq!(
first_wire["data"],
json!([{"timestamp":120,"price":0.47,"resolution_seconds":60}])
);
let saved = first_wire["pagination"]["next_cursor"].as_str().unwrap();
assert!(wire(&e, json!({"token_id":"eb:NO:e","cursor":saved})).is_err());
assert!(wire(
&e,
json!({"token_id":"eb:YES:e","start":121,"cursor":saved})
)
.is_err());
assert!(wire(&e, json!({"token_id":"eb:YES:e","cursor":"broken!"})).is_err());
let mut first = query.clone();
first["limit"] = json!(1);
let page = e.execute(first).unwrap();
@@ -1543,6 +1563,35 @@ fn prices_history_keeps_the_terminal_tick_and_pins_pages_before_settlement() {
.unwrap();
drop(e);
let mut e = Exchange::open(&path).unwrap();
let second_wire = wire(
&e,
json!({"token_id":"eb:YES:e","start":120,"end":290,"cursor":saved,"limit":99}),
)
.unwrap();
assert_eq!(second_wire["pagination"]["limit"], 1);
assert_eq!(second_wire["pagination"]["offset"], 1);
assert_eq!(
second_wire["data"],
json!([{"timestamp":240,"price":0.55,"resolution_seconds":60}])
);
let final_wire = wire(
&e,
json!({"token_id":"eb:YES:e","cursor":second_wire["pagination"]["next_cursor"]}),
)
.unwrap();
assert_eq!(
final_wire["data"],
json!([{"timestamp":245,"price":0.55,"resolution_seconds":0}])
);
assert_eq!(
final_wire["pagination"],
json!({"limit":1,"offset":2,"has_more":false,"next_cursor":null})
);
let at_resolution = wire(&e, json!({"token_id":"eb:YES:e","asOf":273})).unwrap();
assert_eq!(
at_resolution["data"],
json!([{"timestamp":273,"price":0.5,"resolution_seconds":0}])
);
let mut seen = page["data"].as_array().unwrap().clone();
let mut cursor = page["pagination"]["next_cursor"].clone();
while !cursor.is_null() {