Serve single and batch CLOB order books over HTTP
This commit is contained in:
@@ -2916,3 +2916,52 @@ fn market_stream_preserves_trades_and_empty_book_tick_across_restart() {
|
||||
page.cursor
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn batch_book_reads_keep_complementary_depth_on_one_revision() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("batch.db");
|
||||
let mut writer = Exchange::open(&path).unwrap();
|
||||
let mut reader = Exchange::open(&path).unwrap();
|
||||
for cmd in [
|
||||
json!({"op":"list","id":"list","market":"demo","rules":"Local binary outcome","tick_size":"0.01"}),
|
||||
json!({"op":"fund","id":"fund","account":"maker","cents":3000}),
|
||||
json!({"op":"open","id":"open","market":"demo"}),
|
||||
] {
|
||||
writer.execute(cmd).unwrap();
|
||||
}
|
||||
let tokens = ["eb:YES:demo", "eb:NO:demo", "eb:YES:demo"].map(String::from);
|
||||
let start = std::sync::Barrier::new(2);
|
||||
std::thread::scope(|scope| {
|
||||
scope.spawn(|| {
|
||||
start.wait();
|
||||
for index in 0..24 {
|
||||
let order = writer
|
||||
.execute(json!({"op":"order","id":format!("bid-{index}"),
|
||||
"account":"maker","asset_id":"eb:YES:demo","side":"buy","price":30,"qty":1}))
|
||||
.unwrap();
|
||||
writer
|
||||
.execute(json!({"op":"cancel","id":format!("cancel-{index}"),
|
||||
"account":"maker","order":order["order"]}))
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
start.wait();
|
||||
for _ in 0..48 {
|
||||
let books = reader.public_books(&tokens).unwrap();
|
||||
assert_eq!(books.len(), 3);
|
||||
assert_eq!(books[0], books[2]);
|
||||
assert_eq!(books[0]["timestamp"], books[1]["timestamp"]);
|
||||
let bids = books[0]["bids"].as_array().unwrap();
|
||||
let asks = books[1]["asks"].as_array().unwrap();
|
||||
assert_eq!(bids.len(), asks.len());
|
||||
if !bids.is_empty() {
|
||||
assert_eq!(bids, &[json!({"price":"0.3","size":"1"})]);
|
||||
assert_eq!(asks, &[json!({"price":"0.7","size":"1"})]);
|
||||
}
|
||||
}
|
||||
});
|
||||
let books = reader.public_books(&tokens).unwrap();
|
||||
assert_eq!(books[0]["bids"], json!([]));
|
||||
assert_eq!(books[1]["asks"], json!([]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user