Mark outcome positions and report account holdings value
This commit is contained in:
@@ -1674,3 +1674,40 @@ fn catalog_and_ranked_volume_count_executions_once_across_conditions() {
|
||||
assert_eq!(listing["volume"], condition["volume"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valuation_counts_reserved_shares_and_distinguishes_unpriced_from_zero() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("valuation.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
let mut snapshots = Vec::new();
|
||||
for line in include_str!("../../../docs/examples/valuation.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
let response = e.execute(cmd.clone()).unwrap();
|
||||
match cmd["op"].as_str().unwrap() {
|
||||
"portfolio_value" => snapshots.push(response),
|
||||
"positions" => {
|
||||
let yes = response["positions"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|p| p["outcome"] == "YES")
|
||||
.unwrap();
|
||||
assert_eq!(yes["reserved_size"], 8);
|
||||
assert_eq!(yes["current_price_micros"], 565000);
|
||||
assert_eq!(yes["price_source"], "midpoint");
|
||||
assert_eq!(yes["current_value_micros"], 4520000);
|
||||
drop(e);
|
||||
e = Exchange::open(&path).unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
assert_eq!(snapshots.len(), 4);
|
||||
assert!(snapshots[0]["value_micros"].is_null());
|
||||
assert_eq!(snapshots[0]["unpriced_positions"], 1);
|
||||
assert_eq!(snapshots[0]["priced_value_micros"], 4800000);
|
||||
assert_eq!(snapshots[1]["value_micros"], 8870000);
|
||||
assert_eq!(snapshots[2]["value_micros"], 8000000);
|
||||
assert_eq!(snapshots[3]["value_micros"], 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user