Apply per-market taker fees to cash budgets, fills and account activity
This commit is contained in:
@@ -1861,3 +1861,49 @@ fn priced_interest_follows_outstanding_tokens_through_transfer_merge_and_redempt
|
||||
json!([])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fees_follow_taker_cash_budget_and_net_sale_proceeds() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("fees.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
for line in include_str!("../../../docs/examples/fees.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
if cmd["op"] == "market_buy" {
|
||||
e.execute(json!({"op":"fund","id":"poor","account":"poor","cents":5000}))
|
||||
.unwrap();
|
||||
let before = state(&mut e);
|
||||
assert!(e.execute(json!({"op":"order","id":"unfunded-fee","market":"cup","outcome":"YES","side":"buy","price":50,"qty":100,"account":"poor"})).is_err());
|
||||
assert_eq!(state(&mut e), before);
|
||||
}
|
||||
let reply = e.execute(cmd.clone()).unwrap();
|
||||
match cmd["op"].as_str().unwrap() {
|
||||
"estimate" if cmd["amount_cents"] == 5000 => assert_eq!(reply["filled_shares"], 97),
|
||||
"estimate" => assert_eq!(reply["fee_micros"], 1250000),
|
||||
"market_buy" => {
|
||||
assert_eq!(reply["total_spent_micros"], 51250000);
|
||||
assert_eq!(reply["fee_micros"], 1250000);
|
||||
drop(e);
|
||||
e = Exchange::open(&path).unwrap();
|
||||
assert_eq!(e.execute(cmd).unwrap(), reply);
|
||||
}
|
||||
"market_sell" => {
|
||||
assert_eq!(reply["fee_micros"], 10500);
|
||||
assert_eq!(reply["net_proceeds_micros"], 289500);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let s = state(&mut e);
|
||||
assert_eq!(s["accounts"][1]["cash"], 903);
|
||||
assert_eq!(s["cash_remainders"][0]["micros"], 9500);
|
||||
assert_eq!(s["execution_fees"].as_array().unwrap().len(), 2);
|
||||
let leg = e
|
||||
.execute(json!({"op":"trades","account":"alice","market":"cup"}))
|
||||
.unwrap();
|
||||
assert!(leg["trades"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|r| r["fee_micros"] == 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user