Model sports events and market rules and persist trade price history
This commit is contained in:
@@ -220,3 +220,28 @@ fn failed_receipt_discards_planned_fill() {
|
||||
assert_eq!(e.execute(bid).unwrap(), reply);
|
||||
assert_eq!(state(&mut e)["fills"].as_array().unwrap().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sports_catalog_and_trade_curve_survive_retries() {
|
||||
let mut e = Exchange::open(":memory:").unwrap();
|
||||
let mut catalog = Value::Null;
|
||||
for line in include_str!("../../../docs/examples/football.jsonl").lines() {
|
||||
catalog = e.execute(serde_json::from_str(line).unwrap()).unwrap();
|
||||
}
|
||||
assert_eq!(catalog["markets"].as_array().unwrap().len(), 6);
|
||||
setup(&mut e);
|
||||
e.execute(order("ask", "alice", "sell", 50, 2)).unwrap();
|
||||
e.execute(order("bid", "bob", "buy", 50, 2)).unwrap();
|
||||
let open = json!({"op":"open","id":"opening","market":"e"});
|
||||
e.execute(open.clone()).unwrap();
|
||||
e.execute(open).unwrap();
|
||||
let query =
|
||||
json!({"op":"history","market":"e","outcome":"YES","from_ms":0,"to_ms":i64::MAX,"limit":1});
|
||||
let page = e.execute(query.clone()).unwrap();
|
||||
let p = &page["points"][0];
|
||||
assert_eq!(p["price_micros"], 500000);
|
||||
assert_eq!(p["quantity"], 2);
|
||||
let mut next = query;
|
||||
next["after"] = json!([p["at_ms"], p["fill"]]);
|
||||
assert_eq!(e.execute(next).unwrap()["points"], json!([]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user