Calculate priced gross open interest from outstanding outcome positions
This commit is contained in:
@@ -1827,3 +1827,37 @@ fn public_trades_reconcile_event_volume_and_resume_between_legs() {
|
||||
json!([])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn priced_interest_follows_outstanding_tokens_through_transfer_merge_and_redemption() {
|
||||
let mut exchange = Exchange::open(":memory:").unwrap();
|
||||
let mut snapshots = Vec::new();
|
||||
for line in include_str!("../../../docs/examples/open-interest.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
let response = exchange.execute(cmd.clone()).unwrap();
|
||||
if cmd["op"] == "open_interest" {
|
||||
assert_eq!(response["data"].as_array().unwrap().len(), 1);
|
||||
snapshots.push(response["data"][0].clone());
|
||||
}
|
||||
}
|
||||
assert_eq!(snapshots.len(), 6);
|
||||
assert_eq!(snapshots[0]["condition_id"], "cup");
|
||||
assert_eq!(snapshots[0]["value_micros"], 0);
|
||||
assert_eq!(snapshots[1]["gross_shares"], 20);
|
||||
assert_eq!(snapshots[1]["unpriced_shares"], 10);
|
||||
assert_eq!(snapshots[1]["priced_value_micros"], 6000000);
|
||||
assert!(snapshots[1]["value"].is_null());
|
||||
assert_eq!(snapshots[2]["value"].as_f64(), Some(10.0));
|
||||
assert_eq!(snapshots[2]["gross_shares"], 20);
|
||||
assert_eq!(snapshots[3]["condition_id"], "GLOBAL");
|
||||
assert_eq!(snapshots[3]["value_micros"], 7000000);
|
||||
assert_eq!(snapshots[3]["gross_shares"], 14);
|
||||
assert_eq!(snapshots[4]["value_micros"], 2000000);
|
||||
assert_eq!(snapshots[5]["value_micros"], 0);
|
||||
assert_eq!(
|
||||
exchange
|
||||
.execute(json!({"op":"open_interest","market":"missing"}))
|
||||
.unwrap()["data"],
|
||||
json!([])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user