Expose single and batch execution-side prices from one book snapshot
This commit is contained in:
@@ -2065,3 +2065,55 @@ fn minimum_size_checks_submitted_orders_and_preserves_partial_fills() {
|
||||
.unwrap()["min_order_size"]
|
||||
.is_null());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_and_batch_execution_prices_follow_opposing_liquidity() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("execution-prices.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
let mut batch = Value::Null;
|
||||
let mut single = Vec::new();
|
||||
for line in include_str!("../../../docs/examples/execution-prices.jsonl").lines() {
|
||||
let request: Value = serde_json::from_str(line).unwrap();
|
||||
let response = e.execute(request.clone()).unwrap();
|
||||
match request["op"].as_str().unwrap() {
|
||||
"price" => single.push(response["price"].clone()),
|
||||
"prices" => {
|
||||
for (asset, buy, sell) in [
|
||||
("eb:YES:cup:final", 0.11, 0.09),
|
||||
("eb:NO:cup:final", 0.91, 0.89),
|
||||
] {
|
||||
assert_eq!(response[asset]["BUY"].as_f64(), Some(buy));
|
||||
assert_eq!(response[asset]["SELL"].as_f64(), Some(sell));
|
||||
}
|
||||
batch = request;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
assert_eq!(single, vec![Value::Null, json!("0.11")]);
|
||||
let mut reader = Exchange::open(&path).unwrap();
|
||||
assert_eq!(
|
||||
reader.execute(batch.clone()).unwrap(),
|
||||
e.execute(batch.clone()).unwrap()
|
||||
);
|
||||
e.execute(json!({"op":"cancel_all","id":"cancel","account":"alice"}))
|
||||
.unwrap();
|
||||
let empty = reader.execute(batch.clone()).unwrap();
|
||||
assert_eq!(empty["eb:NO:cup:final"], json!({"BUY":null,"SELL":null}));
|
||||
let item = batch["requests"][0].clone();
|
||||
let limit = json!({"op":"prices","requests":vec![item.clone();500]});
|
||||
assert_eq!(
|
||||
reader.execute(limit).unwrap(),
|
||||
json!({"eb:YES:cup:final":{"BUY":null}})
|
||||
);
|
||||
for invalid in [
|
||||
json!({"op":"prices","requests":[]}),
|
||||
json!({"op":"prices","requests":vec![item.clone();501]}),
|
||||
json!({"op":"prices","requests":[item,{"token_id":"eb:YES:unknown","side":"BUY"}]}),
|
||||
json!({"op":"price","token_id":"eb:other:cup:final","side":"SELL"}),
|
||||
json!({"op":"price","token_id":"eb:YES:cup:final","side":"other"}),
|
||||
] {
|
||||
assert!(reader.execute(invalid).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user