Serve last execution prices and directions for individual and batch token queries
This commit is contained in:
@@ -2910,13 +2910,37 @@ fn market_stream_preserves_trades_and_empty_book_tick_across_restart() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("stream.db");
|
||||
let mut writer = Exchange::open(&path).unwrap();
|
||||
let yes = "eb:YES:demo".to_owned();
|
||||
let no = "eb:NO:demo".to_owned();
|
||||
let tokens = [no.clone(), yes.clone(), no.clone()];
|
||||
for line in include_str!("../../../docs/examples/market-stream-trades.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
let result = writer.execute(cmd.clone()).unwrap();
|
||||
if cmd["id"] == "maker-ask" {
|
||||
let prices = writer.last_trade_prices(&tokens).unwrap();
|
||||
assert_eq!(prices[1], json!({"token_id":yes,"price":"0.5","side":""}));
|
||||
} else if cmd["id"] == "buy" || cmd["id"] == "no" {
|
||||
let prices = writer.last_trade_prices(&tokens).unwrap();
|
||||
assert_eq!(
|
||||
prices[1],
|
||||
json!({"token_id":yes,"price":"0.4","side":"BUY"})
|
||||
);
|
||||
assert_eq!(prices[0], json!({"token_id":no,"price":"0.5","side":""}));
|
||||
}
|
||||
assert_eq!(writer.execute(cmd).unwrap(), result);
|
||||
}
|
||||
drop(writer);
|
||||
let mut reader = Exchange::open(&path).unwrap();
|
||||
let prices = reader.last_trade_prices(&tokens).unwrap();
|
||||
assert_eq!(
|
||||
prices[0],
|
||||
json!({"token_id":no,"price":"0.65","side":"SELL"})
|
||||
);
|
||||
assert_eq!(
|
||||
prices[1],
|
||||
json!({"token_id":yes,"price":"0.35","side":"BUY"})
|
||||
);
|
||||
assert_eq!(prices[0], prices[2]);
|
||||
let page = reader.market_stream_page("demo", Some(0)).unwrap();
|
||||
let kinds: Vec<_> = page
|
||||
.frames
|
||||
|
||||
Reference in New Issue
Block a user