Expose wallet-side public trades with signed keyset pagination
This commit is contained in:
@@ -3415,3 +3415,74 @@ fn directory_pages_filter_parents_without_truncating_siblings() {
|
||||
let many = vec![("id".to_owned(), "1".to_owned()); 101];
|
||||
assert!(db.gamma_list(Markets, &many).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trade_feed_replays_both_wallet_legs_and_keeps_the_cursor_after_restart() {
|
||||
fn feed(db: &Exchange, query: Value) -> Value {
|
||||
db.public_trade_feed(serde_json::from_value(query).unwrap())
|
||||
.unwrap()
|
||||
}
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("public-fills.db");
|
||||
let mut db = Exchange::open(&path).unwrap();
|
||||
for sample in [
|
||||
include_str!("../../../docs/examples/football.jsonl"),
|
||||
include_str!("../../../docs/examples/volume.jsonl"),
|
||||
] {
|
||||
for line in sample.lines() {
|
||||
db.execute(serde_json::from_str(line).unwrap()).unwrap();
|
||||
}
|
||||
}
|
||||
let event = db
|
||||
.gamma_event(exchange::DirectoryKey::Slug("cup-a-b"))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let event_id = event["id"].as_str().unwrap();
|
||||
let first = feed(&db, json!({"eventId":event_id,"user":"bob","limit":1}));
|
||||
assert_eq!(first["data"][0]["price"], json!(0.3));
|
||||
assert_eq!(first["data"][0]["size"], 2);
|
||||
assert_eq!(first["data"][0]["side"], "BUY");
|
||||
assert_eq!(first["data"][0]["event_slug"], "cup-a-b");
|
||||
assert_eq!(first["pagination"]["has_more"], true);
|
||||
let cursor = first["pagination"]["next_cursor"].as_str().unwrap();
|
||||
drop(db);
|
||||
let db = Exchange::open(&path).unwrap();
|
||||
let next = feed(
|
||||
&db,
|
||||
json!({"user":"bob","event_id":event_id,"cursor":cursor,"limit":999}),
|
||||
);
|
||||
assert_eq!(
|
||||
next["pagination"],
|
||||
json!({"offset":1,"limit":1,"has_more":false,"next_cursor":null})
|
||||
);
|
||||
let leg = &next["data"][0];
|
||||
assert_eq!(leg["token_id"], "eb:NO:full-2-1");
|
||||
assert_eq!(leg["price"], json!(0.4));
|
||||
assert_eq!(leg["size"], 3);
|
||||
assert_eq!(leg["outcome"], "其他比分");
|
||||
assert_eq!(leg["outcome_index"], 1);
|
||||
let changed = feed(
|
||||
&db,
|
||||
json!({"cursor":cursor,"user":"alice","side":"SELL","takerOnly":false}),
|
||||
);
|
||||
assert_eq!(changed["data"][0]["proxy_wallet"], "alice");
|
||||
assert_eq!(changed["data"][0]["token_id"], "eb:YES:half-1-0");
|
||||
let timestamp = first["data"][0]["timestamp"].as_i64().unwrap();
|
||||
let sale = feed(
|
||||
&db,
|
||||
json!({"condition":"half-1-0","user":"alice","side":"SELL","taker_only":false,"start":timestamp,"end":timestamp,"filterType":"CASH","filterAmount":0.6}),
|
||||
);
|
||||
assert_eq!(sale["data"].as_array().unwrap().len(), 1);
|
||||
assert!(feed(&db,json!({"user":"alice","end":timestamp-1,"start":timestamp-1,"side":"SELL","taker_only":false}))["data"].as_array().unwrap().is_empty());
|
||||
assert!(feed(&db, json!({"eventId":"99999"}))["data"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert!(db
|
||||
.public_trade_feed(serde_json::from_value(json!({"cursor":format!("{}A",cursor)})).unwrap())
|
||||
.is_err());
|
||||
let other = Exchange::open(":memory:").unwrap();
|
||||
assert!(other
|
||||
.public_trade_feed(serde_json::from_value(json!({"cursor":cursor})).unwrap())
|
||||
.is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user