Settle sub-cent orders and migrate historical book prices
This commit is contained in:
@@ -2198,7 +2198,7 @@ fn configured_ticks_bind_order_amounts_execution_and_opening_price() {
|
||||
if request["op"] == "limit_amounts" {
|
||||
assert_eq!(result["size_micros"], 5120000);
|
||||
assert_eq!(result["collateral_micros"], 66560);
|
||||
assert_eq!(result["local_precision_supported"], false);
|
||||
assert_eq!(result["local_precision_supported"], true);
|
||||
let (maker, taker) = if request["side"] == "buy" {
|
||||
("66560", "5120000")
|
||||
} else {
|
||||
@@ -2546,3 +2546,89 @@ fn old_resting_order_is_scaled_once_and_keeps_fifo_after_partial_fill() {
|
||||
.unwrap();
|
||||
assert_eq!(r["cancelled"].to_string(), "0.99");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subcent_fills_reconcile_across_restart_budget_and_complement() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("fine.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
for line in include_str!("../../../docs/examples/fine-price-execution.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
if cmd["op"] == "price" {
|
||||
drop(e);
|
||||
e = Exchange::open(&path).unwrap();
|
||||
}
|
||||
if cmd["id"] == "buy" {
|
||||
for invalid in [
|
||||
json!({"price_micros":13500}),
|
||||
json!({"price":1,"price_micros":13000}),
|
||||
] {
|
||||
let mut broken = cmd.clone();
|
||||
broken
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.extend(invalid.as_object().unwrap().clone());
|
||||
assert!(e.execute(broken).is_err());
|
||||
}
|
||||
}
|
||||
let r = e.execute(cmd.clone()).unwrap();
|
||||
match cmd["op"].as_str().unwrap() {
|
||||
"price" => assert_eq!(r["price"], "0.013"),
|
||||
"balance" => assert_eq!(r["available_micros"], 1_933_440),
|
||||
"estimate" => {
|
||||
assert_eq!(r["total_spent_micros"], 9880);
|
||||
assert_eq!(r["worst_fill_price"].to_string(), "1.3");
|
||||
}
|
||||
"market_buy" => {
|
||||
assert_eq!(r["unspent_micros"], 120);
|
||||
assert_eq!(r["total_spent_micros"], 9880);
|
||||
}
|
||||
"cancel" => assert_eq!(r["cancelled"].to_string(), "0.12"),
|
||||
"history" => {
|
||||
assert_eq!(r["points"][0]["price_micros"], 987000);
|
||||
assert_eq!(r["points"][0]["quantity"].to_string(), "1.01");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let state = state(&mut e);
|
||||
assert_eq!(state["fills"][0]["price"].to_string(), "1.3");
|
||||
assert_eq!(state["paired_fills"][0]["yes_price"].to_string(), "1.3");
|
||||
assert_eq!(state["markets"][0]["collateral"], 801);
|
||||
let replay = e.execute(json!({"op":"volume","market":"e"})).unwrap();
|
||||
assert_eq!(
|
||||
replay["volume"]["all_time"]["taker_notional_cents"].to_string(),
|
||||
"8.957"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auction_uses_fine_grid_and_coarsening_releases_exact_bid_reserve() {
|
||||
let mut e = Exchange::open(":memory:").unwrap();
|
||||
e.execute(json!({"op":"list","id":"l","market":"e","rules":"r","tick_size":"0.001"}))
|
||||
.unwrap();
|
||||
for (who, cents) in [("maker", 200), ("buyer", 100)] {
|
||||
e.execute(json!({"op":"fund","id":who,"account":who,"cents":cents}))
|
||||
.unwrap();
|
||||
}
|
||||
e.execute(json!({"op":"split","id":"s","market":"e","account":"maker","qty":2}))
|
||||
.unwrap();
|
||||
for (id, account, side, p, qty) in [
|
||||
("a", "maker", "sell", 12000, 2),
|
||||
("b", "buyer", "buy", 12000, 3),
|
||||
("c", "buyer", "buy", 17000, 2),
|
||||
] {
|
||||
e.execute(json!({"op":"order","id":id,"market":"e","outcome":"YES","account":account,"side":side,"price_micros":p,"qty":qty})).unwrap();
|
||||
}
|
||||
e.execute(json!({"op":"open","id":"o","market":"e"}))
|
||||
.unwrap();
|
||||
assert_eq!(state(&mut e)["fills"][0]["price"].to_string(), "1.3");
|
||||
let balance = json!({"op":"balance","account":"buyer"});
|
||||
let before = e.execute(balance.clone()).unwrap();
|
||||
assert_eq!(before["reserved_micros"], 36000);
|
||||
assert_eq!(before["available_micros"], 938000);
|
||||
e.execute(json!({"op":"tick_size_change","id":"wider","asset_id":"eb:YES:e","old_tick_size":"0.001","new_tick_size":"0.01","timestamp":"1"})).unwrap();
|
||||
let after = e.execute(balance).unwrap();
|
||||
assert_eq!(after["available_micros"], 974000);
|
||||
assert_eq!(after["reserved_micros"], 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user